package org.innovateuk.ifs.assessment.feedback.populator;

import org.innovateuk.ifs.form.resource.QuestionResource;
import org.innovateuk.ifs.application.service.QuestionService;
import org.innovateuk.ifs.application.service.SectionService;
import org.innovateuk.ifs.assessment.feedback.viewmodel.AssessmentFeedbackNavigationViewModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

import static org.innovateuk.ifs.form.resource.SectionType.GENERAL;

/**
 * Build the model for Assessment Feedback navigation view.
 */
@Component
public class AssessmentFeedbackNavigationModelPopulator extends AssessmentModelPopulator<AssessmentFeedbackNavigationViewModel> {

    @Autowired
    private QuestionService questionService;

    @Autowired
    private SectionService sectionService;

    @Override
    public AssessmentFeedbackNavigationViewModel populate(final long assessmentId, final QuestionResource question) {
        return new AssessmentFeedbackNavigationViewModel(assessmentId, getPreviousQuestion(question.getId()), getNextQuestion(question.getId()));
    }

    private Optional<QuestionResource> getPreviousQuestion(final long questionId) {
        return questionService.getPreviousQuestion(questionId);
    }

    private Optional<QuestionResource> getNextQuestion(final long questionId) {
        return questionService.getNextQuestion(questionId).filter(this::isAssessmentQuestion);
    }

    private boolean isAssessmentQuestion(QuestionResource question) {
        return sectionService.getById(question.getSection()).getType() == GENERAL;
    }
}

@@ -56,66 +56,8 @@
 r;%0A%0A
-import org.innovateuk.ifs.form.resource.QuestionResource;%0A
 impo
@@ -107,32 +107,32 @@
 uestionService;%0A
+
 import org.innov
@@ -272,16 +272,74 @@
 wModel;%0A
+import org.innovateuk.ifs.form.resource.QuestionResource;%0A
 import o
@@ -471,16 +471,117 @@
 ional;%0A%0A
+import static org.innovateuk.ifs.competition.resource.CompetitionSetupQuestionType.APPLICATION_TEAM;%0A
 import s
@@ -1402,16 +1402,51 @@
 stionId)
+.filter(this::isAssessmentQuestion)
 ;%0A    %7D%0A
@@ -1690,32 +1690,32 @@
 rce question) %7B%0A
-
         return s
@@ -1779,16 +1779,89 @@
  GENERAL
+%0A                && (question.getQuestionSetupType() != APPLICATION_TEAM)
 ;%0A    %7D%0A

Fix assessor navigation issue