use of fi.otavanopisto.pyramus.koski.exception.NoLatestStudentException in project pyramus by otavanopisto.
the class KoskiClient method updatePerson.
/**
* Updates Person to Koski.
*/
public void updatePerson(Person person) {
try {
if (!settings.isEnabled())
return;
if (person == null) {
logger.log(Level.WARNING, "updateStudent called with null person.");
return;
}
clearPersonLog(person);
// Does the person have any reported study programmes
if (!settings.hasReportedStudents(person)) {
return;
}
String personOid = personVariableDAO.findByPersonAndKey(person, KOSKI_HENKILO_OID);
if (StringUtils.isBlank(person.getSocialSecurityNumber()) && StringUtils.isBlank(personOid)) {
logger.warning(String.format("Can not update person (%d) without SSN or OID.", person.getId()));
koskiPersonLogDAO.create(person, KoskiPersonState.NO_UNIQUE_ID, new Date());
return;
}
Oppija oppija = koskiController.personToOppija(person);
if (oppija.getOpiskeluoikeudet().size() == 0) {
logger.info(String.format("Updating person %d was skipped due to no updateable study permits.", person.getId()));
return;
}
updatePersonToKoski(oppija, person, personOid);
} catch (NoLatestStudentException nlse) {
logger.severe(String.format("Could not resolve latest student for person %d.", person.getId()));
koskiPersonLogDAO.create(person, KoskiPersonState.UNKNOWN_FAILURE, new Date());
} catch (Exception ex) {
logger.log(Level.SEVERE, String.format("Unknown error while processing person %d", person != null ? person.getId() : null), ex);
koskiPersonLogDAO.create(person, KoskiPersonState.UNKNOWN_FAILURE, new Date(), ex.getMessage());
}
}
use of fi.otavanopisto.pyramus.koski.exception.NoLatestStudentException in project pyramus by otavanopisto.
the class KoskiController method personToOppija.
public Oppija personToOppija(Person person) throws NoLatestStudentException {
Student latestStudent = resolveLatestStudent(person);
if (latestStudent == null) {
throw new NoLatestStudentException();
}
String personOid = personVariableDAO.findByPersonAndKey(person, KoskiConsts.VariableNames.KOSKI_HENKILO_OID);
Henkilo henkilo;
if (StringUtils.isNotBlank(personOid)) {
henkilo = new HenkiloTiedotJaOID(personOid, person.getSocialSecurityNumber(), latestStudent.getFirstName(), latestStudent.getLastName(), getCallname(latestStudent));
} else {
henkilo = new HenkiloUusi(person.getSocialSecurityNumber(), latestStudent.getFirstName(), latestStudent.getLastName(), getCallname(latestStudent));
}
Oppija oppija = new Oppija();
oppija.setHenkilo(henkilo);
List<Student> reportedStudents = new ArrayList<>();
for (Student s : person.getStudents()) {
if (settings.isReportedStudent(s)) {
List<Opiskeluoikeus> opiskeluoikeudet = studentToOpiskeluoikeus(s);
for (Opiskeluoikeus o : opiskeluoikeudet) {
if (o != null) {
oppija.addOpiskeluoikeus(o);
reportedStudents.add(s);
}
}
}
}
return oppija;
}
Aggregations