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