Search in sources :

Example 1 with PhoneNumber

use of fi.otavanopisto.pyramus.rest.model.PhoneNumber in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method listUserPhoneNumbers.

@Override
public List<UserPhoneNumber> listUserPhoneNumbers(SchoolDataIdentifier userIdentifier) {
    if (!StringUtils.equals(userIdentifier.getDataSource(), getSchoolDataSource())) {
        throw new SchoolDataBridgeInternalException(String.format("Could not list phone numbers for user from school data source %s", userIdentifier.getDataSource()));
    }
    PhoneNumber[] phoneNumbers = null;
    Long pyramusStudentId = identifierMapper.getPyramusStudentId(userIdentifier.getIdentifier());
    if (pyramusStudentId != null) {
        phoneNumbers = pyramusClient.get(String.format("/students/students/%d/phoneNumbers", pyramusStudentId), PhoneNumber[].class);
        if (phoneNumbers == null) {
            return Collections.emptyList();
        }
    } else {
        Long pyramusStaffId = identifierMapper.getPyramusStaffId(userIdentifier.getIdentifier());
        if (pyramusStaffId != null) {
            phoneNumbers = pyramusClient.get(String.format("/staff/members/%d/phoneNumbers", pyramusStaffId), PhoneNumber[].class);
            if (phoneNumbers == null) {
                return Collections.emptyList();
            }
        }
    }
    List<UserPhoneNumber> result = new ArrayList<>();
    for (PhoneNumber phoneNumber : phoneNumbers) {
        ContactType contactType = phoneNumber.getContactTypeId() != null ? pyramusClient.get(String.format("/common/contactTypes/%d", phoneNumber.getContactTypeId()), ContactType.class) : null;
        result.add(entityFactory.createEntity(userIdentifier, phoneNumber, contactType));
    }
    return result;
}
Also used : ContactType(fi.otavanopisto.pyramus.rest.model.ContactType) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) UserPhoneNumber(fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber) PhoneNumber(fi.otavanopisto.pyramus.rest.model.PhoneNumber) UserPhoneNumber(fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber)

Aggregations

SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)1 UserPhoneNumber (fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber)1 ContactType (fi.otavanopisto.pyramus.rest.model.ContactType)1 PhoneNumber (fi.otavanopisto.pyramus.rest.model.PhoneNumber)1 ArrayList (java.util.ArrayList)1