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);
}
}
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()));
}
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");
}
Aggregations