class ExecutionFilesProcessorService {

    public Optional<Execution> getExecution(PlannedIndexation plannedIndexation) {
        if (plannedIndexation == null) {
            return Optional.empty();
        }

        File rawExecutionFile = plannedIndexation.getExecutionFolder();
        if (rawExecutionFile == null) {
            return Optional.empty();
        }

        CycleDefinition cycleDefinition = plannedIndexation.getCycleDefinition();
        if (cycleDefinition == null) {
            return Optional.empty();
        }

        Long projectId = cycleDefinition.getProjectId();
        String buildInformationFilePath = settingService.get(projectId, Settings.EXECUTION_INDEXER_FILE_BUILD_INFORMATION_PATH);
        Optional<Build> build = getBuildFromFile(rawExecutionFile, buildInformationFilePath);
        if (!build.isPresent()) {
            log.info("The build information file ({}) in [{}] couldn't be processed", buildInformationFilePath, rawExecutionFile.getAbsolutePath());
            return Optional.empty();
        }

        Optional<Execution> execution = getExecutionFromBuildAndCycleDefinition(build.get(), cycleDefinition);

        String buildUrl = build.get().getUrl();
        Optional<ExecutionCompletionRequest> completionRequest = (StringUtils.isEmpty(buildUrl) ? Optional.empty() : executionCompletionRequestRepository.findById(buildUrl));
        completionRequest.ifPresent(executionCompletionRequestRepository::delete);

        if (!execution.isPresent()) {
            return Optional.empty();
        }

        String cycleDefinitionFilePath = settingService.get(projectId, Settings.EXECUTION_INDEXER_FILE_CYCLE_DEFINITION_PATH);
        Optional<CycleDef> cycleDef = fileProcessorService.getMappedObjectFromFile(rawExecutionFile, cycleDefinitionFilePath, CycleDef.class);
        if (!cycleDef.isPresent()) {
            if (JobStatus.DONE.equals(execution.get().getStatus()) || completionRequest.isPresent()) {
                log.info("Cycle-run's cycle-definition JSON not found in done job (cycle deeply broken): indexing it as failed");
                execution.get().setBlockingValidation(false);
                return execution;
            }
            log.info("Cycle-run's cycle-definition JSON not found (too soon?): not indexing it yet");
            return Optional.empty();
        }
        execution.get().setBlockingValidation(cycleDef.get().isBlockingValidation());
        String qualityThresholds = getQualityThresholdsFromCycleDefinition(cycleDef.get());
        execution.get().setQualityThresholds(qualityThresholds);

        Pair<List<CountryDeployment>, List<Run>> countryDeploymentsAndRuns = getCountryDeploymentsAndRunsPair(rawExecutionFile, cycleDef.get(), projectId, execution.get().getStatus(), buildInformationFilePath);

        Set<CountryDeployment> countryDeployments = new TreeSet<>(countryDeploymentsAndRuns.getFirst());
        execution.get().addCountryDeployments(countryDeployments);

        Set<Run> runs = new TreeSet<>(countryDeploymentsAndRuns.getSecond());
        execution.get().addRuns(runs);

        qualityService.computeQuality(execution.get());

        Boolean executionIsIncomplete = !executionIsComplete(execution.get(), cycleDef.get());
        if (executionIsIncomplete) {
            execution.get().setQualityStatus(QualityStatus.INCOMPLETE);
        }

        return execution;
    }

}