<commit_before>package org.innovateuk.ifs.testdata.services;

import org.innovateuk.ifs.assessment.resource.AssessmentState;
import org.innovateuk.ifs.competition.resource.CompetitionResource;
import org.innovateuk.ifs.competition.resource.CompetitionStatus;
import org.innovateuk.ifs.form.resource.FormInputResource;
import org.innovateuk.ifs.form.resource.FormInputScope;
import org.innovateuk.ifs.form.resource.FormInputType;
import org.innovateuk.ifs.form.resource.QuestionResource;
import org.innovateuk.ifs.invite.constant.InviteStatus;
import org.innovateuk.ifs.testdata.builders.*;
import org.innovateuk.ifs.testdata.builders.data.ApplicationData;
import org.innovateuk.ifs.testdata.builders.data.CompetitionData;
import org.innovateuk.ifs.user.domain.User;
import org.innovateuk.ifs.user.repository.UserRepository;
import org.innovateuk.ifs.user.resource.RoleProfileState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.time.ZonedDateTime;
import java.util.*;

import static java.util.Arrays.asList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.innovateuk.ifs.assessment.resource.AssessmentState.READY_TO_SUBMIT;
import static org.innovateuk.ifs.assessment.resource.AssessmentState.SUBMITTED;
import static org.innovateuk.ifs.testdata.builders.AssessmentDataBuilder.newAssessmentData;
import static org.innovateuk.ifs.testdata.builders.AssessorDataBuilder.newAssessorData;
import static org.innovateuk.ifs.testdata.builders.AssessorInviteDataBuilder.newAssessorInviteData;
import static org.innovateuk.ifs.testdata.builders.AssessorResponseDataBuilder.newAssessorResponseData;
import static org.innovateuk.ifs.testdata.services.CsvUtils.*;
import static org.innovateuk.ifs.util.CollectionFunctions.*;

/**
 * A service that {@link org.innovateuk.ifs.testdata.BaseGenerateTestData} uses to generate Assessment data.  While
 * {@link org.innovateuk.ifs.testdata.BaseGenerateTestData} is responsible for gathering CSV information and
 * orchestarting the building of it, this service is responsible for taking the CSV data passed to it and using
 * the appropriate builders to generate and update entities.
 */
@Component
@Lazy
public class AssessmentDataBuilderService extends BaseDataBuilderService {
    List<String> defaultAssessors = asList("<EMAIL>", "<EMAIL>");

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private GenericApplicationContext applicationContext;

    private AssessmentDataBuilder assessmentBuilder;
    private AssessorDataBuilder assessorUserBuilder;
    private AssessorResponseDataBuilder assessorResponseBuilder;
    private AssessorInviteDataBuilder assessorInviteUserBuilder;

    @PostConstruct
    public void readCsvs() {
        ServiceLocator serviceLocator = new ServiceLocator(applicationContext, COMP_ADMIN_EMAIL, PROJECT_FINANCE_EMAIL);

        assessmentBuilder = newAssessmentData(serviceLocator);
        assessorUserBuilder = newAssessorData(serviceLocator);
        assessorResponseBuilder = newAssessorResponseData(serviceLocator);
        assessorInviteUserBuilder = newAssessorInviteData(serviceLocator);
    }

    public void createAssessments(List<ApplicationData> applications, List<AssessmentLine> assessmentLines, List<AssessorResponseLine> assessorResponseLines, List<CompetitionLine> competitionLines) {

        List<CompetitionLine> competitionsPastAssessment = simpleFilter(competitionLines, l -> l.competitionStatus.isLaterThan(CompetitionStatus.IN_ASSESSMENT));
        List<String> competitionsPastAssessmentNames = simpleMap(competitionsPastAssessment, l -> l.name);

        applications.forEach(application -> {

            List<AssessmentLine> assessmentLinesForApplication = simpleFilter(assessmentLines, l ->
                    Objects.equals(l.applicationName, application.getApplication().getName()));

            assessmentLinesForApplication.forEach(assessmentLine -> {
                createAssessment(assessmentLine);

                createAssessorResponses(assessmentLine.applicationName, assessmentLine.assessorEmail, assessmentLine.state,
                        assessorResponseLines, application.getCompetition());

                submitAssessment(assessmentLine);

                assignToPanel(assessmentLine, application.getCompetition());

                assignToInterview(assessmentLine, application.getCompetition());
            });<commit_msg>removed changes no longer needed<commit_after>package org.innovateuk.ifs.testdata.services;

import org.innovateuk.ifs.assessment.resource.AssessmentState;
import org.innovateuk.ifs.competition.resource.CompetitionResource;
import org.innovateuk.ifs.competition.resource.CompetitionStatus;
import org.innovateuk.ifs.form.resource.FormInputResource;
import org.innovateuk.ifs.form.resource.FormInputScope;
import org.innovateuk.ifs.form.resource.FormInputType;
import org.innovateuk.ifs.form.resource.QuestionResource;
import org.innovateuk.ifs.invite.constant.InviteStatus;
import org.innovateuk.ifs.testdata.builders.*;
import org.innovateuk.ifs.testdata.builders.data.ApplicationData;
import org.innovateuk.ifs.testdata.builders.data.CompetitionData;
import org.innovateuk.ifs.user.domain.User;
import org.innovateuk.ifs.user.repository.UserRepository;
import org.innovateuk.ifs.user.resource.RoleProfileState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.time.ZonedDateTime;
import java.util.*;

import static java.util.Arrays.asList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.innovateuk.ifs.assessment.resource.AssessmentState.READY_TO_SUBMIT;
import static org.innovateuk.ifs.assessment.resource.AssessmentState.SUBMITTED;
import static org.innovateuk.ifs.testdata.builders.AssessmentDataBuilder.newAssessmentData;
import static org.innovateuk.ifs.testdata.builders.AssessorDataBuilder.newAssessorData;
import static org.innovateuk.ifs.testdata.builders.AssessorInviteDataBuilder.newAssessorInviteData;
import static org.innovateuk.ifs.testdata.builders.AssessorResponseDataBuilder.newAssessorResponseData;
import static org.innovateuk.ifs.testdata.services.CsvUtils.*;
import static org.innovateuk.ifs.util.CollectionFunctions.*;

/**
 * A service that {@link org.innovateuk.ifs.testdata.BaseGenerateTestData} uses to generate Assessment data.  While
 * {@link org.innovateuk.ifs.testdata.BaseGenerateTestData} is responsible for gathering CSV information and
 * orchestarting the building of it, this service is responsible for taking the CSV data passed to it and using
 * the appropriate builders to generate and update entities.
 */
@Component
@Lazy
public class AssessmentDataBuilderService extends BaseDataBuilderService {
    List<String> defaultAssessors = asList("<EMAIL>", "<EMAIL>");

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private GenericApplicationContext applicationContext;

    private AssessmentDataBuilder assessmentBuilder;
    private AssessorDataBuilder assessorUserBuilder;
    private AssessorResponseDataBuilder assessorResponseBuilder;
    private AssessorInviteDataBuilder assessorInviteUserBuilder;

    @PostConstruct
    public void readCsvs() {
        ServiceLocator serviceLocator = new ServiceLocator(applicationContext, COMP_ADMIN_EMAIL, PROJECT_FINANCE_EMAIL);

        assessmentBuilder = newAssessmentData(serviceLocator);
        assessorUserBuilder = newAssessorData(serviceLocator);
        assessorResponseBuilder = newAssessorResponseData(serviceLocator);
        assessorInviteUserBuilder = newAssessorInviteData(serviceLocator);
    }

    public void createAssessments(List<ApplicationData> applications, List<AssessmentLine> assessmentLines, List<AssessorResponseLine> assessorResponseLines, List<CompetitionLine> competitionLines) {

        List<CompetitionLine> competitionsPastAssessment = simpleFilter(competitionLines, l -> l.competitionStatus.isLaterThan(CompetitionStatus.IN_ASSESSMENT));
        List<String> competitionsPastAssessmentNames = simpleMap(competitionsPastAssessment, l -> l.name);

        applications.forEach(application -> {

            List<AssessmentLine> assessmentLinesForApplication = simpleFilter(assessmentLines, l ->
                    Objects.equals(l.applicationName, application.getApplication().getName()));

            assessmentLinesForApplication.forEach(assessmentLine -> {

                createAssessment(assessmentLine);

                createAssessorResponses(assessmentLine.applicationName, assessmentLine.assessorEmail, assessmentLine.state,
                        assessorResponseLines, application.getCompetition());

                submitAssessment(assessmentLine);

                assignToPanel(assessmentLine, application.getCompetition());

                assignToInterview(assessmentLine, application.getCompetition());
            });
{'fraction_non_alphanumeric': 0.08052394245222246, 'fraction_numerical': 0.00021473051320592657, 'mean_word_length': 5.433011049723757, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '989384', 'n_tokens_mistral': 2588, 'n_tokens_neox': 2521, 'n_words': 422}