<%@ page extends="oneit.servlets.process.AJAXProcessJSP" %>

<%@ page import="oneit.servlets.jsp.*,oneit.servlets.orm.*,oneit.servlets.objstore.*,oneit.servlets.jsp.tabs.*,oneit.logging.*,oneit.sql.*,oneit.objstore.services.*" %>
<%@ page import="performa.orm.*,performa.orm.types.*,performa.utils.*, java.util.*, oneit.objstore.*, oneit.servlets.process.*, oneit.utils.*" %>
<%@ page import="oneit.utils.filter.Filter, oneit.objstore.rdbms.filters.EqualsFilter" %>

<%@ include file="../../../setuprequest.jsp" %>

<%! protected String getName (ServletConfig config) { return "save_job_match_answers_jsp"; } %>
<oneit:form method="POST">
<%
    ORMProcessState     process         =   (ORMProcessState)ProcessDecorator.getDefaultProcess(request);
    ObjectTransaction   objTran         =   ObjectTransaction.getTransaction();
    int                 questionNumber  =   Integer.valueOf(request.getParameter ("questionNumber")) - 1;
    int                 actualNumber    =   Integer.valueOf(request.getParameter ("actualNumber"));
    int                 answerNo        =   Integer.valueOf(request.getParameter ("answerNo"));
    boolean             complete        =   Boolean.valueOf(request.getParameter ("completeApplication"));
    JobApplication      jobApplication  =   (JobApplication) process.getAttribute("JobApplication");
    List<Question>      allQuestions    =   (List<Question>) process.getAttribute("AllQuestions");

    
    jobApplication  =   (JobApplication) jobApplication.getInTransaction (objTran);

    Debug.assertion (jobApplication.getObjectWriteability() == FieldWriteability.TRUE, "Must be able to edit");

    Question        question    =   (Question) allQuestions.get(questionNumber).getInTransaction (objTran);
    Filter<Answer>  filter      =   Answer.SearchByAll().andQuestion(new EqualsFilter<>(question));
    Answer          answer      =   jobApplication.pipelineJobApplication().toCandidate().toProfileAssessmentAnswers(filter).val();

    if(answer == null)
    {
        answer  =   Answer.createAnswer(objTran);

        jobApplication.getCandidate().addToProfileAssessmentAnswers(answer);
        answer.setQuestion(question);
    }


    answer.setAnswerNo(answer.getFinalAnswerValue(answerNo));
%>
</oneit:form>