<commit_before>package org.innovateuk.ifs.assessment.dashboard.populator;

import org.innovateuk.ifs.assessment.common.service.AssessmentService;
import org.innovateuk.ifs.assessment.dashboard.viewmodel.AssessorCompetitionDashboardApplicationViewModel;
import org.innovateuk.ifs.assessment.dashboard.viewmodel.AssessorCompetitionDashboardViewModel;
import org.innovateuk.ifs.assessment.resource.AssessmentTotalScoreResource;
import org.innovateuk.ifs.assessment.resource.dashboard.ApplicationAssessmentResource;
import org.innovateuk.ifs.assessment.resource.dashboard.AssessorCompetitionDashboardResource;
import org.innovateuk.ifs.assessment.service.AssessorCompetitionDashboardRestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

import static org.innovateuk.ifs.assessment.resource.AssessmentState.SUBMITTED;

/**
 * Build the model for the Assessor Competition Dashboard view.
 */
@Component
public class AssessorCompetitionDashboardModelPopulator {

    @Autowired
    private AssessmentService assessmentService;

    @Autowired
    private AssessorCompetitionDashboardRestService assessorCompetitionDashboardRestService;

    public AssessorCompetitionDashboardViewModel populateModel(Long competitionId, Long userId) {

        AssessorCompetitionDashboardResource competitionDetails = assessorCompetitionDashboardRestService.getAssessorCompetitionDashboard(competitionId, userId).getSuccess();

        List<AssessorCompetitionDashboardApplicationViewModel> outstanding = getOutstandingAssessments(competitionDetails.getApplicationAssessments());
        List<AssessorCompetitionDashboardApplicationViewModel> submitted = getSubmittedAssessments(competitionDetails.getApplicationAssessments());

        boolean submitVisible = outstanding.stream()
                .anyMatch(AssessorCompetitionDashboardApplicationViewModel::isReadyToSubmit);

        return new AssessorCompetitionDashboardViewModel(
                competitionDetails.getCompetitionId(),
                competitionDetails.getCompetitionName(),
                competitionDetails.getInnovationLead(),
                competitionDetails.getAssessorAcceptDate(),
                competitionDetails.getAssessorDeadlineDate(),
                submitted,
                outstanding,
                submitVisible
        );
    }

    private List<AssessorCompetitionDashboardApplicationViewModel> getSubmittedAssessments(List<ApplicationAssessmentResource> assessmentResources) {
        return assessmentResources.stream()
                .filter(this::isAssessmentSubmitted)
                .map(this::createApplicationViewModel)
                .collect(Collectors.toList());
    }

    private List<AssessorCompetitionDashboardApplicationViewModel> getOutstandingAssessments(List<ApplicationAssessmentResource> assessmentResources) {
        return assessmentResources.stream()
                .filter(resource -> !isAssessmentSubmitted(resource))
                .map(this::createApplicationViewModel)
                .collect(Collectors.toList());
    }

    private boolean isAssessmentSubmitted(ApplicationAssessmentResource assessmentResource) {
        return SUBMITTED == assessmentResource.getState();
    }

    private boolean isAssessmentNotSubmitted(ApplicationAssessmentResource assessmentResource) {
        return !(SUBMITTED == assessmentResource.getState());
    }

    private AssessorCompetitionDashboardApplicationViewModel createApplicationViewModel(ApplicationAssessmentResource assessment) {

        return new AssessorCompetitionDashboardApplicationViewModel(
                assessment.getApplicationId(),
                assessment.getAssessmentId(),
                assessment.getCompetitionName(),
                assessment.getLeadOrganisation(),
                assessment.getState(),
                getOverallScore(assessment),
                assessment.isRecommended()<commit_msg>IFS-6500 - removal of unused method.<commit_after>package org.innovateuk.ifs.assessment.dashboard.populator;

import org.innovateuk.ifs.assessment.common.service.AssessmentService;
import org.innovateuk.ifs.assessment.dashboard.viewmodel.AssessorCompetitionDashboardApplicationViewModel;
import org.innovateuk.ifs.assessment.dashboard.viewmodel.AssessorCompetitionDashboardViewModel;
import org.innovateuk.ifs.assessment.resource.AssessmentTotalScoreResource;
import org.innovateuk.ifs.assessment.resource.dashboard.ApplicationAssessmentResource;
import org.innovateuk.ifs.assessment.resource.dashboard.AssessorCompetitionDashboardResource;
import org.innovateuk.ifs.assessment.service.AssessorCompetitionDashboardRestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

import static org.innovateuk.ifs.assessment.resource.AssessmentState.SUBMITTED;

/**
 * Build the model for the Assessor Competition Dashboard view.
 */
@Component
public class AssessorCompetitionDashboardModelPopulator {

    @Autowired
    private AssessmentService assessmentService;

    @Autowired
    private AssessorCompetitionDashboardRestService assessorCompetitionDashboardRestService;

    public AssessorCompetitionDashboardViewModel populateModel(Long competitionId, Long userId) {

        AssessorCompetitionDashboardResource competitionDetails = assessorCompetitionDashboardRestService.getAssessorCompetitionDashboard(competitionId, userId).getSuccess();

        List<AssessorCompetitionDashboardApplicationViewModel> outstanding = getOutstandingAssessments(competitionDetails.getApplicationAssessments());
        List<AssessorCompetitionDashboardApplicationViewModel> submitted = getSubmittedAssessments(competitionDetails.getApplicationAssessments());

        boolean submitVisible = outstanding.stream()
                .anyMatch(AssessorCompetitionDashboardApplicationViewModel::isReadyToSubmit);

        return new AssessorCompetitionDashboardViewModel(
                competitionDetails.getCompetitionId(),
                competitionDetails.getCompetitionName(),
                competitionDetails.getInnovationLead(),
                competitionDetails.getAssessorAcceptDate(),
                competitionDetails.getAssessorDeadlineDate(),
                submitted,
                outstanding,
                submitVisible
        );
    }

    private List<AssessorCompetitionDashboardApplicationViewModel> getSubmittedAssessments(List<ApplicationAssessmentResource> assessmentResources) {
        return assessmentResources.stream()
                .filter(this::isAssessmentSubmitted)
                .map(this::createApplicationViewModel)
                .collect(Collectors.toList());
    }

    private List<AssessorCompetitionDashboardApplicationViewModel> getOutstandingAssessments(List<ApplicationAssessmentResource> assessmentResources) {
        return assessmentResources.stream()
                .filter(resource -> !isAssessmentSubmitted(resource))
                .map(this::createApplicationViewModel)
                .collect(Collectors.toList());
    }

    private boolean isAssessmentSubmitted(ApplicationAssessmentResource assessmentResource) {
        return SUBMITTED == assessmentResource.getState();
    }

    private AssessorCompetitionDashboardApplicationViewModel createApplicationViewModel(ApplicationAssessmentResource assessment) {

        return new AssessorCompetitionDashboardApplicationViewModel(
                assessment.getApplicationId(),
                assessment.getAssessmentId(),
                assessment.getCompetitionName(),
                assessment.getLeadOrganisation(),
                assessment.getState(),
                getOverallScore(assessment),
                assessment.isRecommended()
{'fraction_non_alphanumeric': 0.06750094804702313, 'fraction_numerical': 0.0005056250790039186, 'mean_word_length': 4.243207422133864, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '6039959', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1904, 'n_words': 248}