Search in sources :

Example 1 with MatriculationExamAttendanceDAO

use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO in project pyramus by otavanopisto.

the class YTLReportBinaryRequestController method enrollmentToKokelas.

private AbstractKokelas enrollmentToKokelas(MatriculationExamEnrollment enrollment, List<YTLAineKoodi> mapping) {
    MatriculationExamAttendanceDAO matriculationExamAttendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
    Student student = enrollment.getStudent();
    if (student == null || student.getPerson() == null) {
        return null;
    }
    List<MatriculationExamAttendance> attendances = matriculationExamAttendanceDAO.listByEnrollmentAndStatus(enrollment, MatriculationExamAttendanceStatus.ENROLLED);
    Person person = student.getPerson();
    String hetu = enrollment.getSsn();
    if (hetu == null) {
        hetu = person.getSocialSecurityNumber();
        if (hetu == null && person.getBirthday() != null) {
            DateFormat format = new SimpleDateFormat("dd.MM.yyyy");
            hetu = format.format(person.getBirthday());
        }
    }
    List<String> etunimet = Arrays.asList(StringUtils.split(student.getFirstName(), " "));
    String oppijanumero = personVariableDAO.findByPersonAndKey(person, KOSKI_HENKILO_OID);
    oppijanumero = StringUtils.isNotBlank(oppijanumero) ? oppijanumero : null;
    int kokelasnumero = enrollment.getCandidateNumber();
    Koulutustyyppi koulutustyyppi = schoolTypeToKoulutustyyppi(enrollment.getEnrollAs());
    Tutkintotyyppi tutkintotyyppi = degreeTypeToTutkintoTyyppi(enrollment.getDegreeType());
    boolean uudelleenaloittaja = enrollment.isRestartExam();
    AbstractKokelas kokelas;
    switch(enrollment.getDegreeStructure()) {
        case PRE2022:
            kokelas = vanhaKokelas(student, attendances, mapping);
            break;
        case POST2022:
            kokelas = uusiKokelas(student, attendances, mapping);
            break;
        default:
            throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Invalid degree structure.");
    }
    kokelas.getEtunimet().addAll(etunimet);
    kokelas.setSukunimi(student.getLastName());
    kokelas.setHetu(hetu);
    kokelas.setKokelasnumero(kokelasnumero);
    kokelas.setOppijanumero(oppijanumero);
    kokelas.setKoulutustyyppi(koulutustyyppi);
    kokelas.setTutkintotyyppi(tutkintotyyppi);
    kokelas.setUudelleenaloittaja(uudelleenaloittaja);
    return kokelas;
}
Also used : SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) AbstractKokelas(fi.otavanopisto.pyramus.ytl.AbstractKokelas) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Tutkintotyyppi(fi.otavanopisto.pyramus.ytl.Tutkintotyyppi) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) SimpleDateFormat(java.text.SimpleDateFormat) Koulutustyyppi(fi.otavanopisto.pyramus.ytl.Koulutustyyppi)

Example 2 with MatriculationExamAttendanceDAO

use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO in project pyramus by otavanopisto.

the class EditEnrollmentViewController method createOrUpdateStudentProject.

private void createOrUpdateStudentProject(MatriculationExamAttendance examAttendance, Student student, MatriculationExamSubject subject, boolean mandatory, StaffMember loggedUser) {
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
    MatriculationExamAttendanceDAO matriculationExamAttendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    MatriculationExamSubjectSettings subjectSettings = matriculationExamSubjectSettingsDAO.findBy(examAttendance.getEnrollment().getExam(), subject);
    if (subjectSettings == null || subjectSettings.getProject() == null) {
        // We cannot really do anything if the settings aren't in place
        return;
    }
    CourseOptionality projectOptionality = mandatory ? CourseOptionality.MANDATORY : CourseOptionality.OPTIONAL;
    Project project = subjectSettings.getProject();
    StudentProject studentProject;
    if (examAttendance != null && examAttendance.getProjectAssessment() != null && BooleanUtils.isFalse(examAttendance.getProjectAssessment().getArchived()) && examAttendance.getProjectAssessment().getStudentProject() != null && BooleanUtils.isFalse(examAttendance.getProjectAssessment().getStudentProject().getArchived())) {
        // Use the studentproject from the projectassessment if it exists
        studentProject = examAttendance.getProjectAssessment().getStudentProject();
    } else {
        // Resolve studentProject from the project in the settings
        List<StudentProject> studentProjects = studentProjectDAO.listBy(student, project, TSB.IGNORE);
        // Find first non-archived project
        studentProject = studentProjects.stream().filter(studentProject1 -> BooleanUtils.isFalse(studentProject1.getArchived())).findFirst().orElse(null);
        if (studentProject == null) {
            // No unarchived student project was found so try to use any other
            studentProject = studentProjects.isEmpty() ? null : studentProjects.get(0);
            if (studentProject != null && BooleanUtils.isTrue(studentProject.getArchived())) {
                studentProjectDAO.unarchive(studentProject);
            }
        }
    }
    if (studentProject == null) {
        // No matching student project was found so create a new one
        studentProject = studentProjectDAO.create(student, project.getName(), project.getDescription(), project.getOptionalStudiesLength().getUnits(), project.getOptionalStudiesLength().getUnit(), projectOptionality, loggedUser, project);
        Set<Tag> tags = new HashSet<>();
        for (Tag tag : project.getTags()) {
            tags.add(tag);
        }
        studentProjectDAO.updateTags(studentProject, tags);
        List<ProjectModule> projectModules = project.getProjectModules();
        for (ProjectModule projectModule : projectModules) {
            studentProjectModuleDAO.create(studentProject, projectModule.getModule(), null, CourseOptionality.getOptionality(projectModule.getOptionality().getValue()));
        }
    } else {
        studentProject = studentProjectDAO.updateOptionality(studentProject, projectOptionality);
    }
    MatriculationExam matriculationExam = examAttendance.getEnrollment().getExam();
    if (matriculationExam != null && matriculationExam.getSignupGrade() != null && subjectSettings.getExamDate() != null && examAttendance.getProjectAssessment() == null) {
        // Add the exam date
        ProjectAssessment projectAssessment = projectAssessmentDAO.create(studentProject, loggedUser, matriculationExam.getSignupGrade(), subjectSettings.getExamDate(), "");
        // Link the project assessment to this exam atten dance
        matriculationExamAttendanceDAO.updateProjectAssessment(examAttendance, projectAssessment);
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Arrays(java.util.Arrays) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) MatriculationExamAttendanceFunding(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceFunding) SchoolType(fi.otavanopisto.pyramus.domainmodel.matriculation.SchoolType) DegreeType(fi.otavanopisto.pyramus.domainmodel.matriculation.DegreeType) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) StringUtils(org.apache.commons.lang3.StringUtils) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamGrade(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamGrade) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BooleanUtils(org.apache.commons.lang.BooleanUtils) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) MatriculationExamAttendanceStatus(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceStatus) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) MatriculationExamEnrollmentState(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentState) Severity(fi.internetix.smvc.Severity) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) UserRole(fi.otavanopisto.pyramus.framework.UserRole) MatriculationExamEnrollmentDegreeStructure(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentDegreeStructure) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TSB(fi.otavanopisto.pyramus.domainmodel.TSB) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) MatriculationExamTerm(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm) PageRequestContext(fi.internetix.smvc.controllers.PageRequestContext) PyramusViewController(fi.otavanopisto.pyramus.framework.PyramusViewController) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance) List(java.util.List) DAOFactory(fi.otavanopisto.pyramus.dao.DAOFactory) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) HashSet(java.util.HashSet)

Example 3 with MatriculationExamAttendanceDAO

use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO in project pyramus by otavanopisto.

the class ArchiveMatriculationAttendanceJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    MatriculationExamAttendanceDAO examAttendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    Long examAttendanceId = requestContext.getLong("examAttendanceId");
    MatriculationExamAttendance examAttendance = examAttendanceDAO.findById(examAttendanceId);
    if (examAttendance.getProjectAssessment() != null) {
        projectAssessmentDAO.archive(examAttendance.getProjectAssessment());
    }
    examAttendanceDAO.delete(examAttendance);
}
Also used : MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance)

Example 4 with MatriculationExamAttendanceDAO

use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO in project pyramus by otavanopisto.

the class EditEnrollmentViewController method doGet.

private void doGet(PageRequestContext pageRequestContext) {
    pageRequestContext.setIncludeJSP("/templates/matriculation/management-edit-enrollment.jsp");
    Long id = pageRequestContext.getLong("enrollment");
    if (id == null) {
        pageRequestContext.addMessage(Severity.ERROR, "Enrollment not found");
        return;
    }
    MatriculationExamEnrollmentDAO enrollmentDAO = DAOFactory.getInstance().getMatriculationExamEnrollmentDAO();
    MatriculationExamAttendanceDAO attendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    MatriculationExamEnrollment enrollment = enrollmentDAO.findById(id);
    if (enrollment == null) {
        pageRequestContext.addMessage(Severity.ERROR, "Enrollment not found");
        return;
    }
    pageRequestContext.getRequest().setAttribute("enrollment", enrollment);
    pageRequestContext.getRequest().setAttribute("name", enrollment.getName());
    pageRequestContext.getRequest().setAttribute("ssn", enrollment.getSsn());
    pageRequestContext.getRequest().setAttribute("email", enrollment.getEmail());
    pageRequestContext.getRequest().setAttribute("phone", enrollment.getPhone());
    pageRequestContext.getRequest().setAttribute("address", enrollment.getAddress());
    pageRequestContext.getRequest().setAttribute("postalCode", enrollment.getPostalCode());
    pageRequestContext.getRequest().setAttribute("postalOffice", enrollment.getCity());
    pageRequestContext.getRequest().setAttribute("nationalStudentNumber", enrollment.getNationalStudentNumber());
    pageRequestContext.getRequest().setAttribute("guidanceCounselor", enrollment.getGuider());
    pageRequestContext.getRequest().setAttribute("enrollAs", enrollment.getEnrollAs().name());
    pageRequestContext.getRequest().setAttribute("numMandatoryCourses", enrollment.getNumMandatoryCourses());
    pageRequestContext.getRequest().setAttribute("restartExam", enrollment.isRestartExam());
    pageRequestContext.getRequest().setAttribute("location", enrollment.getLocation());
    pageRequestContext.getRequest().setAttribute("message", enrollment.getMessage());
    pageRequestContext.getRequest().setAttribute("canPublishName", enrollment.isCanPublishName());
    pageRequestContext.getRequest().setAttribute("state", enrollment.getState().name());
    pageRequestContext.getRequest().setAttribute("degreeStructure", enrollment.getDegreeStructure().name());
    pageRequestContext.getRequest().setAttribute("enrollmentDate", enrollment.getEnrollmentDate());
    List<MatriculationExamAttendance> attendances = attendanceDAO.listByEnrollment(enrollment);
    List<List<Object>> enrolledAttendances = new ArrayList<>();
    List<List<Object>> finishedAttendances = new ArrayList<>();
    List<List<Object>> plannedAttendances = new ArrayList<>();
    for (MatriculationExamAttendance attendance : attendances) {
        switch(attendance.getStatus()) {
            case ENROLLED:
                enrolledAttendances.add(Arrays.asList(attendance.getId(), attendance.getTerm().name() + attendance.getYear(), attendance.getSubject().name(), mandatoryToString(attendance.isMandatory()), attendance.isRetry() ? "REPEAT" : "FIRST_TIME", attendance.getFunding() != null ? attendance.getFunding().toString() : "", (attendance.getProjectAssessment() != null && attendance.getProjectAssessment().getDate() != null) ? attendance.getProjectAssessment().getDate().getTime() : null, ""));
                break;
            case FINISHED:
                finishedAttendances.add(Arrays.asList(attendance.getId(), attendance.getTerm().name() + attendance.getYear(), attendance.getSubject().name(), mandatoryToString(attendance.isMandatory()), attendance.getFunding() != null ? attendance.getFunding().toString() : "", attendance.getGrade().name(), ""));
                break;
            case PLANNED:
                plannedAttendances.add(Arrays.asList(attendance.getId(), attendance.getTerm().name() + attendance.getYear(), attendance.getSubject().name(), mandatoryToString(attendance.isMandatory()), ""));
                break;
            default:
                break;
        }
        ObjectMapper om = new ObjectMapper();
        try {
            setJsDataVariable(pageRequestContext, "enrolledAttendances", om.writeValueAsString(enrolledAttendances));
            setJsDataVariable(pageRequestContext, "finishedAttendances", om.writeValueAsString(finishedAttendances));
            setJsDataVariable(pageRequestContext, "plannedAttendances", om.writeValueAsString(plannedAttendances));
        } catch (JsonProcessingException ex) {
            throw new RuntimeException(ex);
        }
    }
}
Also used : MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) ArrayList(java.util.ArrayList) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) ArrayList(java.util.ArrayList) List(java.util.List) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance)

Example 5 with MatriculationExamAttendanceDAO

use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO in project pyramus by otavanopisto.

the class EditEnrollmentViewController method doPost.

private void doPost(PageRequestContext pageRequestContext) {
    pageRequestContext.setIncludeJSP("/templates/matriculation/management-edit-enrollment.jsp");
    Long id = pageRequestContext.getLong("enrollment");
    if (id == null) {
        pageRequestContext.addMessage(Severity.ERROR, "Enrollment not found");
        return;
    }
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    MatriculationExamEnrollmentDAO enrollmentDAO = DAOFactory.getInstance().getMatriculationExamEnrollmentDAO();
    MatriculationExamAttendanceDAO attendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    MatriculationExamEnrollment enrollment = enrollmentDAO.findById(id);
    if (enrollment == null) {
        pageRequestContext.addMessage(Severity.ERROR, "Enrollment not found");
        return;
    }
    StaffMember loggedUser = staffMemberDAO.findById(pageRequestContext.getLoggedUserId());
    MatriculationExamEnrollmentState enrollmentState = MatriculationExamEnrollmentState.valueOf(pageRequestContext.getString("state"));
    enrollment = enrollmentDAO.update(enrollment, ObjectUtils.firstNonNull(pageRequestContext.getString("name"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("ssn"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("email"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("phone"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("address"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("postalCode"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("postalOffice"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("guidanceCounselor"), ""), SchoolType.valueOf(pageRequestContext.getString("enrollAs")), DegreeType.valueOf(pageRequestContext.getString("degreeType")), ObjectUtils.firstNonNull(pageRequestContext.getInteger("numMandatoryCourses"), 0), pageRequestContext.getBoolean("restartExam"), ObjectUtils.firstNonNull(pageRequestContext.getString("location"), ""), ObjectUtils.firstNonNull(pageRequestContext.getString("message"), ""), pageRequestContext.getBoolean("canPublishName"), enrollment.getStudent(), enrollmentState, MatriculationExamEnrollmentDegreeStructure.valueOf(pageRequestContext.getString("degreeStructure")), pageRequestContext.getBoolean("approvedByGuider"));
    Integer enrolledAttendances = pageRequestContext.getInteger("enrolledAttendances.rowCount");
    if (enrolledAttendances == null) {
        enrolledAttendances = 0;
    }
    for (int i = 0; i < enrolledAttendances; i++) {
        Long attendanceId = pageRequestContext.getLong("enrolledAttendances." + i + ".attendanceId");
        attendanceId = attendanceId != null ? attendanceId : -1;
        MatriculationExamSubject subject = MatriculationExamSubject.valueOf(pageRequestContext.getString("enrolledAttendances." + i + ".subject"));
        Boolean mandatory = parseMandatory(pageRequestContext.getString("enrolledAttendances." + i + ".mandatority"));
        boolean repeat = "REPEAT".equals(pageRequestContext.getString("enrolledAttendances." + i + ".repeat"));
        MatriculationExamAttendanceFunding funding = parseFunding(pageRequestContext.getString("enrolledAttendances." + i + ".funding"));
        MatriculationExamAttendance examAttendance;
        if (NEW_ROW_ID.equals(attendanceId)) {
            // NOTE: new ENROLLED attendances are tied to the year and term defined in the exam properties
            MatriculationExam matriculationExam = enrollment.getExam();
            Integer year = matriculationExam.getExamYear();
            MatriculationExamTerm term = matriculationExam.getExamTerm();
            examAttendance = attendanceDAO.create(enrollment, subject, mandatory, repeat, year, term, MatriculationExamAttendanceStatus.ENROLLED, funding, null);
        } else {
            examAttendance = attendanceDAO.findById(attendanceId);
            examAttendance = attendanceDAO.update(examAttendance, enrollment, subject, mandatory, repeat, examAttendance.getYear(), examAttendance.getTerm(), examAttendance.getStatus(), funding, examAttendance.getGrade());
        }
        if (enrollmentState == MatriculationExamEnrollmentState.APPROVED) {
            createOrUpdateStudentProject(examAttendance, enrollment.getStudent(), subject, mandatory, loggedUser);
        }
    }
    Integer finishedAttendances = pageRequestContext.getInteger("finishedAttendances.rowCount");
    if (finishedAttendances == null) {
        finishedAttendances = 0;
    }
    for (int i = 0; i < finishedAttendances; i++) {
        Long attendanceId = pageRequestContext.getLong("finishedAttendances." + i + ".attendanceId");
        attendanceId = attendanceId != null ? attendanceId : -1;
        String termString = pageRequestContext.getString("finishedAttendances." + i + ".term");
        MatriculationExamTerm term = MatriculationExamTerm.valueOf(termString.substring(0, 6));
        int year = Integer.parseInt(termString.substring(6));
        MatriculationExamSubject subject = MatriculationExamSubject.valueOf(pageRequestContext.getString("finishedAttendances." + i + ".subject"));
        Boolean mandatory = parseMandatory(pageRequestContext.getString("finishedAttendances." + i + ".mandatority"));
        MatriculationExamGrade grade = MatriculationExamGrade.valueOf(pageRequestContext.getString("finishedAttendances." + i + ".grade"));
        MatriculationExamAttendanceFunding funding = parseFunding(pageRequestContext.getString("finishedAttendances." + i + ".funding"));
        if (NEW_ROW_ID.equals(attendanceId)) {
            attendanceDAO.create(enrollment, subject, mandatory, null, year, term, MatriculationExamAttendanceStatus.FINISHED, funding, grade);
        } else {
            MatriculationExamAttendance examAttendance = attendanceDAO.findById(attendanceId);
            attendanceDAO.update(examAttendance, enrollment, subject, mandatory, null, year, term, MatriculationExamAttendanceStatus.FINISHED, funding, grade);
        }
    }
    Integer plannedAttendances = pageRequestContext.getInteger("plannedAttendances.rowCount");
    if (plannedAttendances == null) {
        plannedAttendances = 0;
    }
    for (int i = 0; i < plannedAttendances; i++) {
        Long attendanceId = pageRequestContext.getLong("plannedAttendances." + i + ".attendanceId");
        attendanceId = attendanceId != null ? attendanceId : -1;
        String termString = pageRequestContext.getString("plannedAttendances." + i + ".term");
        MatriculationExamTerm term = MatriculationExamTerm.valueOf(termString.substring(0, 6));
        int year = Integer.parseInt(termString.substring(6));
        MatriculationExamSubject subject = MatriculationExamSubject.valueOf(pageRequestContext.getString("plannedAttendances." + i + ".subject"));
        Boolean mandatory = parseMandatory(pageRequestContext.getString("plannedAttendances." + i + ".mandatority"));
        MatriculationExamAttendanceFunding funding = parseFunding(pageRequestContext.getString("plannedAttendances." + i + ".funding"));
        if (NEW_ROW_ID.equals(attendanceId)) {
            attendanceDAO.create(enrollment, subject, mandatory, null, year, term, MatriculationExamAttendanceStatus.PLANNED, funding, null);
        } else {
            MatriculationExamAttendance examAttendance = attendanceDAO.findById(attendanceId);
            attendanceDAO.update(examAttendance, enrollment, subject, mandatory, null, year, term, MatriculationExamAttendanceStatus.PLANNED, funding, null);
        }
    }
    pageRequestContext.setRedirectURL(pageRequestContext.getRequest().getRequestURI() + "?enrollment=" + id);
}
Also used : MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance) MatriculationExamAttendanceFunding(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceFunding) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) MatriculationExamTerm(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) MatriculationExamEnrollmentState(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentState) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) MatriculationExamGrade(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamGrade)

Aggregations

MatriculationExamAttendanceDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO)5 MatriculationExamAttendance (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance)5 MatriculationExamEnrollmentDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO)3 MatriculationExamEnrollment (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProjectAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO)2 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)2 MatriculationExam (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam)2 MatriculationExamAttendanceFunding (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceFunding)2 MatriculationExamEnrollmentState (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentState)2 MatriculationExamGrade (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamGrade)2 MatriculationExamSubject (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject)2 MatriculationExamTerm (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm)2 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)2 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)2 Severity (fi.internetix.smvc.Severity)1 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)1 PageRequestContext (fi.internetix.smvc.controllers.PageRequestContext)1 DAOFactory (fi.otavanopisto.pyramus.dao.DAOFactory)1