class ExecutionHistoryService {

    void fillQualities(List<ExecutedScenarioWithErrorAndProblemJoin> allExecutedScenarioJoin,
                       RunWithQualitiesDTO run,
                       Map<Long, Long> functionalityTeamIds,
                       String defaultSeverityCode) {
        run.setQualitiesPerSeverity(new HashMap<>());
        run.setQualitiesPerTeamAndSeverity(new HashMap<>());

        final List<ExecutedScenarioWithErrorAndProblemJoin> allExecutedScenarioJoinOfRun = allExecutedScenarioJoin
                .stream()
                .filter(e -> run.getId().longValue() == e.getRunId())
                .collect(Collectors.toList());
        for (ExecutedScenarioWithErrorAndProblemJoin executedScenarioJoin : allExecutedScenarioJoinOfRun) {
            // Count the scenario for its severity and for global
            addScenario(executedScenarioJoin, run.getQualitiesPerSeverity(), defaultSeverityCode);

            // Do the same for the teams of the scenario
            final List<Long> functionalityIds = ScenarioExtractorUtil
                    .extractFunctionalityIds(executedScenarioJoin.getName());
            final Set<Long> teamIds = functionalityIds.stream()
                    .map(functionalityTeamIds::get)
                    .filter(Objects::nonNull) // Unknown functionality IDs have null team IDs
                    .collect(Collectors.toSet());
            if (teamIds.isEmpty()) {
                addScenarioForTeamAndSeverity(run, defaultSeverityCode, executedScenarioJoin, Team.NOT_ASSIGNED.getId());
            }
            for (Long teamId : teamIds) {
                addScenarioForTeamAndSeverity(run, defaultSeverityCode, executedScenarioJoin, teamId);
            }
        }
    }

}