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