Search in sources :

Example 1 with NoLatestStudentException

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());
    }
}
Also used : NoLatestStudentException(fi.otavanopisto.pyramus.koski.exception.NoLatestStudentException) Oppija(fi.otavanopisto.pyramus.koski.model.Oppija) Date(java.util.Date) ConnectException(java.net.ConnectException) NoLatestStudentException(fi.otavanopisto.pyramus.koski.exception.NoLatestStudentException) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with NoLatestStudentException

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;
}
Also used : HenkiloTiedotJaOID(fi.otavanopisto.pyramus.koski.model.HenkiloTiedotJaOID) NoLatestStudentException(fi.otavanopisto.pyramus.koski.exception.NoLatestStudentException) HenkiloUusi(fi.otavanopisto.pyramus.koski.model.HenkiloUusi) Henkilo(fi.otavanopisto.pyramus.koski.model.Henkilo) ArrayList(java.util.ArrayList) Opiskeluoikeus(fi.otavanopisto.pyramus.koski.model.Opiskeluoikeus) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Oppija(fi.otavanopisto.pyramus.koski.model.Oppija)

Aggregations

NoLatestStudentException (fi.otavanopisto.pyramus.koski.exception.NoLatestStudentException)2 Oppija (fi.otavanopisto.pyramus.koski.model.Oppija)2 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)1 Henkilo (fi.otavanopisto.pyramus.koski.model.Henkilo)1 HenkiloTiedotJaOID (fi.otavanopisto.pyramus.koski.model.HenkiloTiedotJaOID)1 HenkiloUusi (fi.otavanopisto.pyramus.koski.model.HenkiloUusi)1 Opiskeluoikeus (fi.otavanopisto.pyramus.koski.model.Opiskeluoikeus)1 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ProcessingException (javax.ws.rs.ProcessingException)1