@Override
  public void triggerForProject(String projectUuid) {
    try (DbSession dbSession = dbClient.openSession(false)) {

      // remove already existing indexing task, if any
      removeExistingIndexationTasksForProject(dbSession, projectUuid);

      dbClient.branchDao().updateAllNeedIssueSyncForProject(dbSession, projectUuid);
      List<BranchDto> branchInNeedOfIssueSync = dbClient.branchDao().selectBranchNeedingIssueSyncForProject(dbSession, projectUuid);
      LOG.info("{} branch(es) found in need of issue sync for project.", branchInNeedOfIssueSync.size());

      List<CeTaskSubmit> tasks = new ArrayList<>();
      for (BranchDto branch : branchInNeedOfIssueSync) {
        tasks.add(buildTaskSubmit(branch));
      }

      ceQueue.massSubmit(tasks);
      dbSession.commit();
    }
  }
@Test
  public void remove_existing_indexation_for_project_task() {
    String reportTaskUuid = persistReportTasks();

    ProjectDto projectDto = dbTester.components().insertPrivateProject().getProjectDto();
    String branchUuid = "branch_uuid";
    dbTester.components().insertProjectBranch(projectDto, b -> b.setBranchType(BRANCH).setUuid(branchUuid));

    CeQueueDto mainBranchTask = new CeQueueDto().setUuid("uuid_2").setTaskType(BRANCH_ISSUE_SYNC)
      .setEntityUuid(projectDto.getUuid()).setComponentUuid(projectDto.getUuid());
    dbClient.ceQueueDao().insert(dbTester.getSession(), mainBranchTask);

    CeQueueDto branchTask = new CeQueueDto().setUuid("uuid_3").setTaskType(BRANCH_ISSUE_SYNC)
      .setEntityUuid(projectDto.getUuid()).setComponentUuid(branchUuid);
    dbClient.ceQueueDao().insert(dbTester.getSession(), branchTask);

    ProjectDto anotherProjectDto = dbTester.components().insertPrivateProject().getProjectDto();
    CeQueueDto taskOnAnotherProject = new CeQueueDto().setUuid("uuid_4").setTaskType(BRANCH_ISSUE_SYNC)
      .setEntityUuid(anotherProjectDto.getUuid()).setComponentUuid("another-branchUuid");
    CeActivityDto canceledTaskOnAnotherProject = new CeActivityDto(taskOnAnotherProject).setStatus(Status.CANCELED);
    dbClient.ceActivityDao().insert(dbTester.getSession(), canceledTaskOnAnotherProject);

    dbTester.commit();

    underTest.triggerForProject(projectDto.getUuid());

    assertThat(dbClient.ceQueueDao().selectAllInAscOrder(dbTester.getSession())).extracting("uuid")
      .containsExactly(reportTaskUuid);
    assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), REPORT)).hasSize(1);
    assertThat(dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbTester.getSession(), new HashSet<>(List.of("uuid_2")))).isEmpty();

    // verify that the canceled tasks on anotherProject is still here, and was not removed by the project reindexing
    assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), BRANCH_ISSUE_SYNC))
      .hasSize(1)
      .extracting(CeActivityDto::getEntityUuid)
      .containsExactly(anotherProjectDto.getUuid());

    assertThat(logTester.logs(Level.INFO))
      .contains(
        "2 pending indexing task found to be deleted...",
        "2 completed indexing task found to be deleted...",
        "Indexing task deletion complete.",
        "Deleting tasks characteristics...",
        "Tasks characteristics deletion complete.",
        "Tasks characteristics deletion complete.",
        "2 branch(es) found in need of issue sync for project.");
  }