Search in sources :

Example 1 with MatriculationExamSubjectSettingsDAO

use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO 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 2 with MatriculationExamSubjectSettingsDAO

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

the class MatriculationExamSettingsViewController method doPost.

private void doPost(PageRequestContext pageRequestContext) {
    MatriculationExamDAO dao = DAOFactory.getInstance().getMatriculationExamDAO();
    MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    Date starts = DateUtils.startOfDay(pageRequestContext.getDate("starts"));
    Date ends = DateUtils.endOfDay(pageRequestContext.getDate("ends"));
    boolean enrollmentActive = Boolean.TRUE.equals(pageRequestContext.getBoolean("enrollmentActive"));
    Long signupGradeId = pageRequestContext.getLong("signupGradeId");
    Grade signupGrade = signupGradeId != null ? gradeDAO.findById(signupGradeId) : null;
    Integer examYear = pageRequestContext.getInteger("examYear");
    MatriculationExamTerm examTerm = StringUtils.isNotBlank(pageRequestContext.getString("examTerm")) ? MatriculationExamTerm.valueOf(pageRequestContext.getString("examTerm")) : null;
    MatriculationExam exam;
    if ("new".equals(pageRequestContext.getString("examId"))) {
        // Create new
        exam = dao.create(starts, ends, signupGrade, examYear, examTerm, enrollmentActive);
    } else {
        Long examId = pageRequestContext.getLong("examId");
        exam = dao.findById(examId);
        exam = dao.update(exam, starts, ends, signupGrade, examYear, examTerm, enrollmentActive);
    }
    Long subjectTableRowCount = pageRequestContext.getLong("subjectSettingsTable.rowCount");
    for (int i = 0; i < subjectTableRowCount; i++) {
        String colPrefix = "subjectSettingsTable." + i;
        MatriculationExamSubject subject = MatriculationExamSubject.valueOf(pageRequestContext.getString(colPrefix + ".subjectCode"));
        Long projectId = pageRequestContext.getLong(colPrefix + ".projectId");
        Project project = projectId != null ? projectDAO.findById(projectId) : null;
        Date examDate = pageRequestContext.getDate(colPrefix + ".examDate");
        MatriculationExamSubjectSettings subjectSettings = matriculationExamSubjectSettingsDAO.findBy(exam, subject);
        if (subjectSettings == null) {
            matriculationExamSubjectSettingsDAO.create(exam, subject, project, examDate);
        } else {
            matriculationExamSubjectSettingsDAO.update(subjectSettings, project, examDate);
        }
    }
    pageRequestContext.setRedirectURL(String.format("%s/matriculation/settings.page?examId=%d", pageRequestContext.getRequest().getContextPath(), exam.getId()));
}
Also used : MatriculationExamDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) Date(java.util.Date) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) MatriculationExamTerm(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 3 with MatriculationExamSubjectSettingsDAO

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

the class MatriculationExamSettingsViewController method doGet.

private void doGet(PageRequestContext pageRequestContext) {
    MatriculationExamDAO dao = DAOFactory.getInstance().getMatriculationExamDAO();
    MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    List<GradingScale> gradingScales = gradingScaleDAO.listUnarchived();
    pageRequestContext.getRequest().setAttribute("gradingScales", gradingScales);
    MatriculationExam exam;
    if ("new".equals(pageRequestContext.getString("examId"))) {
        pageRequestContext.getRequest().setAttribute("examId", pageRequestContext.getString("examId"));
        exam = null;
    } else {
        Long examId = pageRequestContext.getLong("examId");
        exam = dao.findById(examId);
        pageRequestContext.getRequest().setAttribute("examId", examId);
    }
    pageRequestContext.getRequest().setAttribute("exam", exam);
    JSONArray subjectsJSON = new JSONArray();
    List<MatriculationExamSubject> matriculationExamSubjects = Arrays.asList(MatriculationExamSubject.values());
    matriculationExamSubjects.sort(Comparator.comparing(MatriculationExamSubject::toString));
    for (MatriculationExamSubject subject : matriculationExamSubjects) {
        MatriculationExamSubjectSettings subset = exam != null ? matriculationExamSubjectSettingsDAO.findBy(exam, subject) : null;
        JSONObject subjectJSON = new JSONObject();
        subjectJSON.put("subjectCode", subject);
        subjectJSON.put("projectId", (subset != null && subset.getProject() != null) ? subset.getProject().getId() : null);
        subjectJSON.put("examDate", (subset != null && subset.getExamDate() != null) ? subset.getExamDate().getTime() : null);
        subjectsJSON.add(subjectJSON);
    }
    setJsDataVariable(pageRequestContext, "subjectData", subjectsJSON.toString());
    List<Project> projects = projectDAO.listUnarchived();
    projects.sort(Comparator.comparing(Project::getName));
    JSONArray projectsJSON = new JSONArray();
    for (Project project : projects) {
        JSONObject projectJSON = new JSONObject();
        projectJSON.put("id", project.getId());
        projectJSON.put("name", project.getName());
        projectsJSON.add(projectJSON);
    }
    setJsDataVariable(pageRequestContext, "projectData", projectsJSON.toString());
    pageRequestContext.setIncludeJSP("/templates/matriculation/management-enrollment-settings.jsp");
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) JSONArray(net.sf.json.JSONArray) MatriculationExamDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) JSONObject(net.sf.json.JSONObject) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Aggregations

MatriculationExamSubjectSettingsDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO)3 MatriculationExam (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam)3 MatriculationExamSubject (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject)3 MatriculationExamSubjectSettings (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings)3 Project (fi.otavanopisto.pyramus.domainmodel.projects.Project)3 MatriculationExamDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO)2 ProjectDAO (fi.otavanopisto.pyramus.dao.projects.ProjectDAO)2 MatriculationExamTerm (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Severity (fi.internetix.smvc.Severity)1 PageRequestContext (fi.internetix.smvc.controllers.PageRequestContext)1 DAOFactory (fi.otavanopisto.pyramus.dao.DAOFactory)1 GradeDAO (fi.otavanopisto.pyramus.dao.grading.GradeDAO)1 GradingScaleDAO (fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO)1 ProjectAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO)1 MatriculationExamAttendanceDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO)1 MatriculationExamEnrollmentDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO)1 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)1 StudentProjectModuleDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO)1