Search in sources :

Example 1 with PyramusRestClientUnauthorizedException

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException 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)

Example 2 with PyramusRestClientUnauthorizedException

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method updateUserCredentials.

@Override
public void updateUserCredentials(String userIdentifier, String oldPassword, String newUsername, String newPassword) {
    Long personId = getPersonId(userIdentifier);
    if (personId == null) {
        logger.warning(String.format("PyramusUserSchoolDataBridge.updateUserCredentials malformed user identifier %s", userIdentifier));
        throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
    }
    try {
        UserCredentials change = new UserCredentials(oldPassword, newUsername, newPassword);
        pyramusClient.put("/persons/persons/" + personId + "/credentials", change);
    } catch (PyramusRestClientUnauthorizedException purr) {
        throw new SchoolDataBridgeUnauthorizedException(purr.getMessage());
    }
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) SchoolDataBridgeUnauthorizedException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeUnauthorizedException) UserCredentials(fi.otavanopisto.pyramus.rest.model.UserCredentials) PyramusRestClientUnauthorizedException(fi.otavanopisto.muikku.plugins.schooldatapyramus.rest.PyramusRestClientUnauthorizedException)

Aggregations

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