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