use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO in project pyramus by otavanopisto.
the class SearchEnrollmentsJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
MatriculationExamDAO examDAO = DAOFactory.getInstance().getMatriculationExamDAO();
MatriculationExamEnrollmentDAO dao = DAOFactory.getInstance().getMatriculationExamEnrollmentDAO();
Integer resultsPerPage = NumberUtils.createInteger(requestContext.getRequest().getParameter("maxResults"));
if (resultsPerPage == null) {
resultsPerPage = 10;
}
Integer page = NumberUtils.createInteger(requestContext.getRequest().getParameter("page"));
if (page == null) {
page = 0;
}
Long examId = requestContext.getLong("examId");
MatriculationExam exam = examId != null ? examDAO.findById(examId) : null;
Boolean below20courses = requestContext.getBoolean("below20courses");
String stateStr = requestContext.getString("state");
MatriculationExamEnrollmentState state = StringUtils.isNotBlank(stateStr) ? MatriculationExamEnrollmentState.valueOf(stateStr) : null;
List<MatriculationExamEnrollment> enrollments = dao.listBy(exam, state, BooleanUtils.isTrue(below20courses), page * resultsPerPage, resultsPerPage);
List<Map<String, Object>> results = new ArrayList<>();
for (MatriculationExamEnrollment enrollment : enrollments) {
Map<String, Object> result = new HashMap<>();
result.put("id", enrollment.getId());
result.put("name", enrollment.getName());
result.put("email", enrollment.getEmail());
result.put("state", enrollment.getState());
result.put("numMandatoryCourses", enrollment.getNumMandatoryCourses());
result.put("guider", enrollment.getGuider());
result.put("approvedByGuider", enrollment.isApprovedByGuider());
results.add(result);
}
long count = dao.count();
requestContext.addResponseParameter("statusMessage", "");
requestContext.addResponseParameter("results", results);
requestContext.addResponseParameter("pages", Math.ceil((double) count / resultsPerPage));
requestContext.addResponseParameter("page", page);
}
use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO in project pyramus by otavanopisto.
the class YTLReportBinaryRequestController method processCandidateNumbers.
private List<MatriculationExamEnrollment> processCandidateNumbers(List<MatriculationExamEnrollment> enrollments) {
MatriculationExamEnrollmentDAO matriculationExamEnrollmentDAO = DAOFactory.getInstance().getMatriculationExamEnrollmentDAO();
// In theory, if the enrollment with the max number was removed,
// the max number might be reused for another entrant. Who knows
// if this proves to be an issue though in real life.
int nextFreeNumber = enrollments.stream().map(MatriculationExamEnrollment::getCandidateNumber).filter(Objects::nonNull).mapToInt(Integer::valueOf).max().orElse(0) + 1;
for (int i = 0; i < enrollments.size(); i++) {
MatriculationExamEnrollment enrollment = enrollments.get(i);
if (enrollment.getCandidateNumber() == null) {
enrollment = matriculationExamEnrollmentDAO.updateCandidateNumber(enrollment, nextFreeNumber);
enrollments.set(i, enrollment);
nextFreeNumber++;
}
}
return enrollments;
}
use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO in project pyramus by otavanopisto.
the class YTLReportBinaryRequestController method process.
public void process(BinaryRequestContext binaryRequestContext) {
List<YTLAineKoodi> m = readMapping();
MatriculationExamEnrollmentDAO matriculationExamEnrollmentDAO = DAOFactory.getInstance().getMatriculationExamEnrollmentDAO();
MatriculationExamDAO matriculationExamDAO = DAOFactory.getInstance().getMatriculationExamDAO();
Long examId = binaryRequestContext.getLong("examId");
MatriculationExam exam = matriculationExamDAO.findById(examId);
String tutkintokerta = String.valueOf(exam.getExamYear()) + (exam.getExamTerm() == MatriculationExamTerm.SPRING ? "K" : "S");
Integer koulunumero = binaryRequestContext.getInteger("schoolId");
YTLSiirtotiedosto ytl = new YTLSiirtotiedosto(tutkintokerta, koulunumero);
List<MatriculationExamEnrollment> enrollments = matriculationExamEnrollmentDAO.listDistinctByAttendanceTerms(exam, MatriculationExamEnrollmentState.APPROVED, exam.getExamYear(), exam.getExamTerm(), MatriculationExamAttendanceStatus.ENROLLED);
enrollments = processCandidateNumbers(enrollments);
enrollments.forEach(enrollment -> ytl.addKokelas(enrollmentToKokelas(enrollment, m)));
ObjectMapper objectMapper = new ObjectMapper();
try {
String value = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(ytl);
binaryRequestContext.setFileName("ytl_" + tutkintokerta + ".json");
binaryRequestContext.setResponseContent(value.getBytes("UTF-8"), "application/json;charset=UTF-8");
} catch (Exception e) {
throw new SmvcRuntimeException(e);
}
}
use of fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO 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.MatriculationExamEnrollmentDAO 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