Search in sources :

Example 1 with Address

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;
}
Also used : ContactType(fi.otavanopisto.pyramus.rest.model.ContactType) UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress) Address(fi.otavanopisto.pyramus.rest.model.Address) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress)

Example 2 with Address

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());
    }
}
Also used : UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress) Address(fi.otavanopisto.pyramus.rest.model.Address) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) PyramusRestClientUnauthorizedException(fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)

Aggregations

SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)2 UserAddress (fi.otavanopisto.muikku.schooldata.entity.UserAddress)2 Address (fi.otavanopisto.pyramus.rest.model.Address)2 PyramusRestClientUnauthorizedException (fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)1 SchoolDataBridgeUnauthorizedException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException)1 ContactType (fi.otavanopisto.pyramus.rest.model.ContactType)1 ArrayList (java.util.ArrayList)1