Search in sources :

Example 1 with KoskiStudentId

use of fi.otavanopisto.pyramus.koski.KoskiStudentId in project pyramus by otavanopisto.

the class ListKoskiPersonVariablesJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    try {
        PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
        StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
        PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
        UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
        Long personId = requestContext.getLong("personId");
        if (personId == null) {
            logger.log(Level.WARNING, "Unable to load log entries due to missing personId.");
            requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        Person person = personDAO.findById(personId);
        String personOid = personVariableDAO.findByPersonAndKey(person, KoskiConsts.VariableNames.KOSKI_HENKILO_OID);
        KoskiSettings koskiSettings = CDI.current().select(KoskiSettings.class).get();
        KoskiController koskiController = CDI.current().select(KoskiController.class).get();
        List<Map<String, Object>> studentVariables = new ArrayList<>();
        List<Student> students = studentDAO.listByPerson(person);
        students.sort((a, b) -> Comparator.nullsFirst(Date::compareTo).reversed().compare(a.getStudyStartDate(), b.getStudyStartDate()));
        for (Student student : students) {
            KoskiStudyProgrammeHandler handlerType = koskiSettings.getStudyProgrammeHandlerType(student.getStudyProgramme().getId());
            KoskiStudentHandler handler = handlerType != null ? koskiController.getStudentHandler(handlerType) : null;
            if (handler != null) {
                String studentIdentifier = KoskiConsts.getStudentIdentifier(handlerType, student.getId());
                Set<KoskiStudentId> oids = handler.listOids(student);
                KoskiStudentId koskiId = oids.stream().filter(oid -> StringUtils.equals(oid.getStudentIdentifier(), studentIdentifier)).findFirst().orElse(null);
                Map<String, Object> studentInfo = new HashMap<>();
                studentInfo.put("studentId", student.getId());
                studentInfo.put("studyProgrammeName", student.getStudyProgramme().getName());
                studentInfo.put("oid", koskiId != null ? koskiId.getOid() : null);
                studentInfo.put("linkedOid", userVariableDAO.findByUserAndKey(student, KoskiConsts.VariableNames.KOSKI_LINKED_STUDYPERMISSION_ID));
                studentInfo.put("studyStartDate", student.getStudyStartDate().getTime());
                studentVariables.add(studentInfo);
            }
        }
        requestContext.addResponseParameter("personOID", personOid);
        requestContext.addResponseParameter("studentVariables", studentVariables);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error loading person variables", e);
    }
}
Also used : KoskiStudyProgrammeHandler(fi.otavanopisto.pyramus.koski.KoskiStudyProgrammeHandler) KoskiController(fi.otavanopisto.pyramus.koski.KoskiController) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) KoskiStudentId(fi.otavanopisto.pyramus.koski.KoskiStudentId) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) KoskiStudentHandler(fi.otavanopisto.pyramus.koski.KoskiStudentHandler) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) KoskiSettings(fi.otavanopisto.pyramus.koski.KoskiSettings) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with KoskiStudentId

use of fi.otavanopisto.pyramus.koski.KoskiStudentId in project pyramus by otavanopisto.

the class ListKoskiPersonStudiesJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    try {
        PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
        StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
        PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
        Long personId = requestContext.getLong("personId");
        if (personId == null) {
            logger.log(Level.WARNING, "Unable to load log entries due to missing personId.");
            requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        Person person = personDAO.findById(personId);
        String personOid = personVariableDAO.findByPersonAndKey(person, KoskiConsts.VariableNames.KOSKI_HENKILO_OID);
        if (StringUtils.isBlank(personOid)) {
            return;
        }
        KoskiClient koskiClient = CDI.current().select(KoskiClient.class).get();
        KoskiSettings koskiSettings = CDI.current().select(KoskiSettings.class).get();
        KoskiController koskiController = CDI.current().select(KoskiController.class).get();
        // Find student info from Koski
        OppijaReturnVal koskiStudent = koskiClient.findPersonByOid(personOid);
        List<Map<String, Object>> studyPermitIds = new ArrayList<>();
        if (koskiStudent != null) {
            Map<String, Student> oidMap = new HashMap<>();
            List<Student> students = studentDAO.listByPerson(person);
            for (Student student : students) {
                if (student.getStudyProgramme() != null) {
                    KoskiStudyProgrammeHandler handlerType = koskiSettings.getStudyProgrammeHandlerType(student.getStudyProgramme().getId());
                    KoskiStudentHandler handler = handlerType != null ? koskiController.getStudentHandler(handlerType) : null;
                    if (handler != null) {
                        Set<KoskiStudentId> ids = handler.listOids(student);
                        ids.forEach(id -> oidMap.put(id.getOid(), student));
                    }
                }
            }
            for (OpiskeluoikeusReturnVal studyPermit : koskiStudent.getOpiskeluoikeudet()) {
                String oid = studyPermit.getOid();
                if (oid != null) {
                    Student student = oidMap.get(oid);
                    Map<String, Object> studyPermitInfo = new HashMap<>();
                    studyPermitInfo.put("oid", oid);
                    studyPermitInfo.put("linkedStudyProgrammeName", student != null ? student.getStudyProgramme().getName() : null);
                    studyPermitInfo.put("linkedStudyProgrammeStartDate", student != null ? student.getStudyStartDate().getTime() : null);
                    studyPermitInfo.put("linkedStudentId", student != null ? student.getId() : null);
                    studyPermitIds.add(studyPermitInfo);
                }
            }
        }
        requestContext.addResponseParameter("studyPermitIDs", studyPermitIds);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error loading log entries", e);
    }
}
Also used : KoskiStudyProgrammeHandler(fi.otavanopisto.pyramus.koski.KoskiStudyProgrammeHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OppijaReturnVal(fi.otavanopisto.pyramus.koski.model.result.OppijaReturnVal) KoskiStudentId(fi.otavanopisto.pyramus.koski.KoskiStudentId) KoskiStudentHandler(fi.otavanopisto.pyramus.koski.KoskiStudentHandler) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) KoskiSettings(fi.otavanopisto.pyramus.koski.KoskiSettings) OpiskeluoikeusReturnVal(fi.otavanopisto.pyramus.koski.model.result.OpiskeluoikeusReturnVal) KoskiClient(fi.otavanopisto.pyramus.koski.KoskiClient) KoskiController(fi.otavanopisto.pyramus.koski.KoskiController) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)2 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)2 PersonVariableDAO (fi.otavanopisto.pyramus.dao.users.PersonVariableDAO)2 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)2 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)2 KoskiController (fi.otavanopisto.pyramus.koski.KoskiController)2 KoskiSettings (fi.otavanopisto.pyramus.koski.KoskiSettings)2 KoskiStudentHandler (fi.otavanopisto.pyramus.koski.KoskiStudentHandler)2 KoskiStudentId (fi.otavanopisto.pyramus.koski.KoskiStudentId)2 KoskiStudyProgrammeHandler (fi.otavanopisto.pyramus.koski.KoskiStudyProgrammeHandler)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UserVariableDAO (fi.otavanopisto.pyramus.dao.users.UserVariableDAO)1 KoskiClient (fi.otavanopisto.pyramus.koski.KoskiClient)1 OpiskeluoikeusReturnVal (fi.otavanopisto.pyramus.koski.model.result.OpiskeluoikeusReturnVal)1 OppijaReturnVal (fi.otavanopisto.pyramus.koski.model.result.OppijaReturnVal)1