class ExecutionIndexerService {

    @Transactional
    public void indexExecution(PlannedIndexation plannedIndexation) {
        if (plannedIndexation == null) {
            log.info("No execution indexation found");
            return;
        }

        File rawExecutionFolder = plannedIndexation.getExecutionFolder();
        if (rawExecutionFolder == null) {
            log.info("No execution folder found");
            return;
        }

        CycleDefinition cycleDefinition = plannedIndexation.getCycleDefinition();
        if (cycleDefinition == null) {
            log.info("No cycle definition found");
            return;
        }
        String branch = cycleDefinition.getBranch();
        String cycle = cycleDefinition.getName();
        final Long projectId = cycleDefinition.getProjectId();

        String link = rawExecutionFolder.getAbsolutePath() + File.separator;
        log.info("Began execution indexing {}/{} for link {}", branch, cycle, link);

        Optional<Execution> previousExecution = executionRepository.findByCycleDefinitionProjectIdAndJobLinkAndJobLinkNotNull(projectId, link);
        List<Long> existingErrorIds = getErrorIds(previousExecution);

        Optional<Execution> processedExecution = executionFilesProcessorService.getExecution(plannedIndexation);

        if (!processedExecution.isPresent()) {
            log.info("Could not extract any execution from the directory {}", link);
            log.info("Some of the files may be incorrect, please check again");
            return;
        }

        final Execution savedExecution = executionRepository.save(processedExecution.get());

        List<Long> newErrorIds = getErrorIds(Optional.of(savedExecution));
        newErrorIds.removeAll(existingErrorIds);
        if (!newErrorIds.isEmpty()) {
            final Set<Problem> updatedProblems = errorRepository.autoAssignProblemsToNewErrors(projectId, newErrorIds);
            problemDenormalizationService.updateFirstAndLastSeenDateTimes(updatedProblems);
        }

        if (JobStatus.DONE.equals(savedExecution.getStatus())) {
            transactionAppenderUtil.doAfterCommit(() -> safelySendQualityEmail(savedExecution));
        }

        String url = processedExecution.get().getJobUrl();
        log.info("Ended indexing execution {}/{} job URL {} and link {}", branch, cycle, url, link);
    }

}