use of fi.otavanopisto.muikku.schooldata.entity.UserEmail in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method listUserEmailsByUserIdentifier.
@Override
public List<UserEmail> listUserEmailsByUserIdentifier(String userIdentifier) {
Email[] emails = null;
Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
if (studentId != null) {
emails = pyramusClient.get(String.format("/students/students/%d/emails", studentId), Email[].class);
} else {
Long staffId = identifierMapper.getPyramusStaffId(userIdentifier);
if (staffId != null) {
emails = pyramusClient.get(String.format("/staff/members/%d/emails", staffId), Email[].class);
} else {
logger.severe(String.format("PyramusUserSchoolDataBridge.listUserEmailsByUserIdentifier malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
}
}
if (emails != null) {
List<UserEmail> result = new ArrayList<>(emails.length);
for (Email email : emails) {
ContactType contactType = email != null ? pyramusClient.get("/common/contactTypes/" + email.getContactTypeId(), ContactType.class) : null;
UserEmail userEmail = entityFactory.createEntity(new SchoolDataIdentifier(userIdentifier, getSchoolDataSource()), email, contactType);
if (userEmail != null) {
result.add(userEmail);
}
}
return result;
}
return Collections.emptyList();
}
use of fi.otavanopisto.muikku.schooldata.entity.UserEmail in project muikku by otavanopisto.
the class UserRESTService method listStudentEmails.
@GET
@Path("/students/{ID}/emails")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listStudentEmails(@PathParam("ID") String id) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
if (studentIdentifier == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
}
UserEntity studentEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
if (studentEntity == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Could not find user entity for identifier %s", id)).build();
}
if (!studentEntity.getId().equals(sessionController.getLoggedUserEntity().getId())) {
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.LIST_STUDENT_EMAILS)) {
return Response.status(Status.FORBIDDEN).build();
}
}
List<UserEmail> emails = userController.listUserEmails(studentIdentifier);
Collections.sort(emails, new Comparator<UserEmail>() {
@Override
public int compare(UserEmail o1, UserEmail o2) {
return o1.getDefaultAddress() ? -1 : o2.getDefaultAddress() ? 1 : 0;
}
});
return Response.ok(createRestModel(emails.toArray(new UserEmail[0]))).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.UserEmail in project muikku by otavanopisto.
the class LocalUserSchoolDataBridge method listUserEmailsByUserIdentifier.
/**
* {@inheritDoc}
*/
@Override
public List<UserEmail> listUserEmailsByUserIdentifier(String userIdentifier) {
if (!StringUtils.isNumeric(userIdentifier)) {
throw new SchoolDataBridgeInternalException("userIdentifier is invalid");
}
List<UserEmail> result = new ArrayList<>();
List<LocalUserEmail> emails = localUserSchoolDataController.listUserEmailsByUserIdentifier(userIdentifier);
for (LocalUserEmail email : emails) {
UserEmail emailImpl = toLocalUserEmailImpl(email);
if (emailImpl != null) {
result.add(emailImpl);
} else {
throw new SchoolDataBridgeInternalException("Unexpected error occured while listing LocalUserEmails");
}
}
return result;
}
Aggregations