use of fi.otavanopisto.pyramus.rest.model.Address in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method listUserAddresses.
@Override
public List<UserAddress> listUserAddresses(SchoolDataIdentifier userIdentifier) {
if (!StringUtils.equals(userIdentifier.getDataSource(), getSchoolDataSource())) {
throw new SchoolDataBridgeInternalException(String.format("Could not list email addresses for user from school data source %s", userIdentifier.getDataSource()));
}
Address[] addresses = null;
Long pyramusStudentId = identifierMapper.getPyramusStudentId(userIdentifier.getIdentifier());
if (pyramusStudentId != null) {
addresses = pyramusClient.get(String.format("/students/students/%d/addresses", pyramusStudentId), Address[].class);
} else {
Long pyramusStaffId = identifierMapper.getPyramusStaffId(userIdentifier.getIdentifier());
if (pyramusStaffId != null) {
addresses = pyramusClient.get(String.format("/staff/members/%d/addresses", pyramusStaffId), Address[].class);
}
}
if (addresses == null) {
return Collections.emptyList();
}
List<UserAddress> result = new ArrayList<>(addresses.length);
for (Address address : addresses) {
ContactType contactType = address.getContactTypeId() != null ? pyramusClient.get(String.format("/common/contactTypes/%d", address.getContactTypeId()), ContactType.class) : null;
result.add(entityFactory.createEntity(userIdentifier, address, contactType));
}
return result;
}
use of fi.otavanopisto.pyramus.rest.model.Address in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method updateUserAddress.
@Override
public void updateUserAddress(SchoolDataIdentifier studentIdentifier, SchoolDataIdentifier identifier, String street, String postalCode, String city, String country) {
Long addressId = identifierMapper.getPyramusAddressId(identifier.getIdentifier());
Long studentId = identifierMapper.getPyramusStudentId(studentIdentifier.getIdentifier());
if (addressId == null) {
throw new SchoolDataBridgeInternalException(String.format("Malformed identifier %s", identifier));
}
if (studentId == null) {
throw new SchoolDataBridgeInternalException(String.format("Malformed identifier %s", studentIdentifier));
}
try {
Address address = pyramusClient.get(String.format("/students/students/%d/addresses/%d", studentId, addressId), Address.class);
if (address == null) {
throw new SchoolDataBridgeInternalException(String.format("Address %d of student %d not found", addressId, studentId));
}
address.setStreetAddress(street);
address.setPostalCode(postalCode);
address.setCity(city);
address.setCountry(country);
pyramusClient.put(String.format("/students/students/%d/addresses/%s", studentId, addressId), address);
} catch (PyramusRestClientUnauthorizedException purr) {
throw new SchoolDataBridgeUnauthorizedException(purr.getMessage());
}
}
Aggregations