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