use of fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment 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.domainmodel.matriculation.MatriculationExamEnrollment 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.domainmodel.matriculation.MatriculationExamEnrollment 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.domainmodel.matriculation.MatriculationExamEnrollment in project pyramus by otavanopisto.
the class MatriculationExamEnrollmentDAO method findLatestByExamAndStudent.
public MatriculationExamEnrollment findLatestByExamAndStudent(MatriculationExam exam, Student student) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<MatriculationExamEnrollment> criteria = criteriaBuilder.createQuery(MatriculationExamEnrollment.class);
Root<MatriculationExamEnrollment> root = criteria.from(MatriculationExamEnrollment.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(MatriculationExamEnrollment_.exam), exam), criteriaBuilder.equal(root.get(MatriculationExamEnrollment_.student), student)));
criteria.orderBy(criteriaBuilder.desc(root.get(MatriculationExamEnrollment_.enrollmentDate)));
List<MatriculationExamEnrollment> resultList = entityManager.createQuery(criteria).getResultList();
if (resultList.size() == 0) {
return null;
} else {
return resultList.get(0);
}
}
use of fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment in project pyramus by otavanopisto.
the class MatriculationExamEnrollmentDAO method listDistinctByAttendanceTerms.
public List<MatriculationExamEnrollment> listDistinctByAttendanceTerms(MatriculationExam exam, MatriculationExamEnrollmentState enrollmentState, Integer year, MatriculationExamTerm term, MatriculationExamAttendanceStatus attendanceStatus) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<MatriculationExamEnrollment> criteria = criteriaBuilder.createQuery(MatriculationExamEnrollment.class);
Root<MatriculationExamAttendance> root = criteria.from(MatriculationExamAttendance.class);
Join<MatriculationExamAttendance, MatriculationExamEnrollment> enrollment = root.join(MatriculationExamAttendance_.enrollment);
criteria.select(root.get(MatriculationExamAttendance_.enrollment)).distinct(true);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(enrollment.get(MatriculationExamEnrollment_.exam), exam), criteriaBuilder.equal(enrollment.get(MatriculationExamEnrollment_.state), enrollmentState), criteriaBuilder.equal(root.get(MatriculationExamAttendance_.year), year), criteriaBuilder.equal(root.get(MatriculationExamAttendance_.term), term), criteriaBuilder.equal(root.get(MatriculationExamAttendance_.status), attendanceStatus)));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations