use of fi.otavanopisto.muikku.rest.model.UserBasicInfo in project muikku by otavanopisto.
the class CommunicatorTrashRESTService method listUserTrashItems.
@GET
@Path("/trash")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserTrashItems(@QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
UserEntity user = sessionController.getLoggedUserEntity();
List<CommunicatorMessage> trashItems = communicatorController.listTrashItems(user, firstResult, maxResults);
List<CommunicatorThreadRESTModel> result = new ArrayList<CommunicatorThreadRESTModel>();
for (CommunicatorMessage receivedItem : trashItems) {
String categoryName = receivedItem.getCategory() != null ? receivedItem.getCategory().getName() : null;
boolean hasUnreadMsgs = false;
Date latestMessageDate = receivedItem.getCreated();
List<CommunicatorMessageRecipient> recipients = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, receivedItem.getCommunicatorMessageId(), true);
for (CommunicatorMessageRecipient recipient : recipients) {
hasUnreadMsgs = hasUnreadMsgs || Boolean.FALSE.equals(recipient.getReadByReceiver());
Date created = recipient.getCommunicatorMessage().getCreated();
latestMessageDate = latestMessageDate == null || latestMessageDate.before(created) ? created : latestMessageDate;
}
UserBasicInfo senderBasicInfo = restModels.getSenderBasicInfo(receivedItem);
Long messageCountInThread = communicatorController.countMessagesByUserAndMessageId(user, receivedItem.getCommunicatorMessageId(), true);
List<CommunicatorMessageRecipient> messageRecipients = communicatorController.listCommunicatorMessageRecipients(receivedItem);
List<CommunicatorMessageRecipientUserGroup> userGroupRecipients = communicatorController.listCommunicatorMessageUserGroupRecipients(receivedItem);
List<CommunicatorMessageRecipientWorkspaceGroup> workspaceGroupRecipients = communicatorController.listCommunicatorMessageWorkspaceGroupRecipients(receivedItem);
List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, receivedItem.getCommunicatorMessageId());
List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
List<CommunicatorMessageRecipientRESTModel> restRecipients = restModels.restRecipient(messageRecipients);
List<fi.otavanopisto.muikku.rest.model.UserGroup> restUserGroupRecipients = restModels.restUserGroupRecipients(userGroupRecipients);
List<CommunicatorMessageRecipientWorkspaceGroupRESTModel> restWorkspaceRecipients = restModels.restWorkspaceGroupRecipients(workspaceGroupRecipients);
Long recipientCount = (long) messageRecipients.size() + userGroupRecipients.size() + workspaceGroupRecipients.size();
result.add(new CommunicatorSentThreadRESTModel(receivedItem.getId(), receivedItem.getCommunicatorMessageId().getId(), receivedItem.getSender(), senderBasicInfo, categoryName, receivedItem.getCaption(), receivedItem.getCreated(), restModels.tagIdsToStr(receivedItem.getTags()), hasUnreadMsgs, latestMessageDate, messageCountInThread, restLabels, restRecipients, restUserGroupRecipients, restWorkspaceRecipients, recipientCount));
}
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.rest.model.UserBasicInfo in project muikku by otavanopisto.
the class UserRESTService method findUserBasicInfo.
@GET
@Path("/users/{ID}/basicinfo")
@RESTPermitUnimplemented
public Response findUserBasicInfo(@Context Request request, @PathParam("ID") String id) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).build();
}
UserEntity userEntity = null;
SchoolDataIdentifier userIdentifier = SchoolDataIdentifier.fromId(id);
if (userIdentifier == null) {
if (!StringUtils.isNumeric(id)) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid user id %s", id)).build();
}
userEntity = userEntityController.findUserEntityById(NumberUtils.createLong(id));
userIdentifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
} else {
userEntity = userEntityController.findUserEntityByUserIdentifier(userIdentifier);
}
if (userEntity == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(userEntity.getVersion())));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
schoolDataBridgeSessionController.startSystemSession();
try {
User user = userController.findUserByIdentifier(userIdentifier);
if (user == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
// TODO: User image
boolean hasImage = false;
return Response.ok(new UserBasicInfo(userEntity.getId(), user.getFirstName(), user.getLastName(), user.getNickName(), user.getStudyProgrammeName(), hasImage, user.hasEvaluationFees(), user.getCurriculumIdentifier())).cacheControl(cacheControl).tag(tag).build();
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
}
Aggregations