use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method listUserPropertiesByUser.
@Override
public List<UserProperty> listUserPropertiesByUser(String userIdentifier) {
Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
if (studentId != null) {
Student student = pyramusClient.get("/students/students/" + studentId, Student.class);
Map<String, String> variables = student.getVariables();
List<UserProperty> userProperties = new ArrayList<>();
for (String key : variables.keySet()) {
String value = variables.get(key);
if (value != null) {
userProperties.add(new PyramusUserProperty(userIdentifier, key, value));
}
}
return userProperties;
}
logger.warning(String.format("PyramusUserSchoolDataBridge.listUserPropertiesByUser malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s", userIdentifier));
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException 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());
}
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.
the class LocalUserSchoolDataBridge method updateUser.
/**
* {@inheritDoc}
*/
@Override
public User updateUser(User user) {
if (StringUtils.isNotBlank(user.getFirstName())) {
throw new SchoolDataBridgeInternalException("firstName is required");
}
if (StringUtils.isNotBlank(user.getLastName())) {
throw new SchoolDataBridgeInternalException("lastName is required");
}
LocalUser localUser = localUserSchoolDataController.findUser(user.getIdentifier());
if (localUser != null) {
localUserSchoolDataController.updateUserFirstName(localUser, user.getFirstName());
localUserSchoolDataController.updateUserLastName(localUser, user.getLastName());
return toLocalUserImpl(localUser);
}
throw new SchoolDataBridgeInternalException("Unexpected error occured while creating LocalUser");
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.
the class LocalUserSchoolDataBridge method listUserImagesByUserIdentifier.
/**
* {@inheritDoc}
*/
@Override
public List<UserImage> listUserImagesByUserIdentifier(String userIdentifier) {
List<UserImage> result = new ArrayList<>();
List<LocalUserImage> images = localUserSchoolDataController.listUserImagesByUserIdentifier(userIdentifier);
for (LocalUserImage image : images) {
UserImage userImage = toLocalUserImageImpl(image);
if (userImage != null) {
result.add(userImage);
} else {
throw new SchoolDataBridgeInternalException("Unexpected error occured while listing LocalUserImages");
}
}
return result;
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException in project muikku by otavanopisto.
the class LocalUserSchoolDataBridge method removeUserImage.
/**
* {@inheritDoc}
*/
@Override
public void removeUserImage(String identifier) {
LocalUserImage localUserImage = localUserSchoolDataController.findUserImage(identifier);
if (localUserImage == null) {
throw new SchoolDataBridgeInternalException("UserImage can not be removed because it does not exist");
}
localUserSchoolDataController.removeUserImage(localUserImage);
}
Aggregations