Search in sources :

Example 1 with MatriculationExamEnrollment

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MatriculationExamDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) MatriculationExamEnrollmentState(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollmentState) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MatriculationExamEnrollment

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;
}
Also used : Objects(java.util.Objects) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment)

Example 3 with MatriculationExamEnrollment

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);
    }
}
Also used : MatriculationExamDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) MatriculationExamEnrollmentDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) IOException(java.io.IOException) YTLAineKoodi(fi.otavanopisto.pyramus.ytl.YTLAineKoodi) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) YTLSiirtotiedosto(fi.otavanopisto.pyramus.ytl.YTLSiirtotiedosto)

Example 4 with MatriculationExamEnrollment

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);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment)

Example 5 with MatriculationExamEnrollment

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) MatriculationExamEnrollment(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance)

Aggregations

MatriculationExamEnrollment (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamEnrollment)15 MatriculationExamEnrollmentDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamEnrollmentDAO)6 MatriculationExam (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam)6 EntityManager (javax.persistence.EntityManager)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 ArrayList (java.util.ArrayList)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 MatriculationExamAttendance (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance)3 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)3 Date (java.util.Date)3 MatriculationExamAttendanceDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO)2 MatriculationExamDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO)2 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)2 MatriculationExamAttendanceFunding (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendanceFunding)2 MatriculationExamTerm (fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamTerm)2 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)2 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)2 List (java.util.List)2 Path (javax.ws.rs.Path)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1