use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.
the class CommunicatorRESTService method listUserSentCommunicatorItems.
@GET
@Path("/sentitems")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserSentCommunicatorItems(@QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
UserEntity user = sessionController.getLoggedUserEntity();
List<CommunicatorMessage> sentItems = communicatorController.listSentItems(user, firstResult, maxResults);
List<CommunicatorThreadRESTModel> result = new ArrayList<CommunicatorThreadRESTModel>();
for (CommunicatorMessage sentItem : sentItems) {
String categoryName = sentItem.getCategory() != null ? sentItem.getCategory().getName() : null;
boolean hasUnreadMsgs = false;
Date latestMessageDate = sentItem.getCreated();
List<CommunicatorMessageRecipient> recipients = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, sentItem.getCommunicatorMessageId(), false);
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(sentItem);
Long messageCountInThread = communicatorController.countMessagesByUserAndMessageId(user, sentItem.getCommunicatorMessageId(), false);
List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, sentItem.getCommunicatorMessageId());
List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
List<CommunicatorMessageRecipient> messageRecipients = communicatorController.listCommunicatorMessageRecipients(sentItem);
List<CommunicatorMessageRecipientUserGroup> userGroupRecipients = communicatorController.listCommunicatorMessageUserGroupRecipients(sentItem);
List<CommunicatorMessageRecipientWorkspaceGroup> workspaceGroupRecipients = communicatorController.listCommunicatorMessageWorkspaceGroupRecipients(sentItem);
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(sentItem.getId(), sentItem.getCommunicatorMessageId().getId(), sentItem.getSender(), senderBasicInfo, categoryName, sentItem.getCaption(), sentItem.getCreated(), tagIdsToStr(sentItem.getTags()), hasUnreadMsgs, latestMessageDate, messageCountInThread, restLabels, restRecipients, restUserGroupRecipients, restWorkspaceRecipients, recipientCount));
}
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel 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.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.
the class CommunicatorTrashRESTService method listUserCommunicatorMessagesByMessageId.
@GET
@Path("/trash/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserCommunicatorMessagesByMessageId(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
UserEntity user = sessionController.getLoggedUserEntity();
CommunicatorMessageId threadId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
List<CommunicatorMessage> receivedItems = communicatorController.listMessagesByMessageId(user, threadId, true);
List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, threadId);
List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
CommunicatorMessageId olderThread = communicatorController.findOlderThreadId(user, threadId, CommunicatorFolderType.TRASH, null);
CommunicatorMessageId newerThread = communicatorController.findNewerThreadId(user, threadId, CommunicatorFolderType.TRASH, null);
return Response.ok(restModels.restThreadViewModel(receivedItems, olderThread, newerThread, restLabels)).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.
the class CommunicatorLabelRESTService method createMessageIdLabel.
@POST
@Path("/messages/{COMMUNICATORMESSAGEID}/labels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createMessageIdLabel(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId, CommunicatorMessageIdLabelRESTModel newLabel) throws AuthorizationException {
CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
UserEntity userEntity = sessionController.getLoggedUserEntity();
CommunicatorLabel label = communicatorController.findUserLabelById(newLabel.getLabelId());
if ((label != null) && canAccessLabel(userEntity, label)) {
CommunicatorMessageIdLabel userLabel = communicatorController.findMessageIdLabel(userEntity, messageId, label);
if (userLabel == null) {
userLabel = communicatorController.createMessageIdLabel(userEntity, messageId, label);
return Response.ok(restModels.restLabel(userLabel)).build();
} else {
return Response.status(Status.BAD_REQUEST).build();
}
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.
the class CommunicatorLabelRESTService method listUserUnreadCommunicatorMessagesByMessageId.
@GET
@Path("/userLabels/{USERLABELID}/messages/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserUnreadCommunicatorMessagesByMessageId(@PathParam("USERLABELID") Long userLabelId, @PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
UserEntity userEntity = sessionController.getLoggedUserEntity();
CommunicatorUserLabel userLabel = communicatorController.findUserLabelById(userLabelId);
if ((userLabel != null) && canAccessLabel(userEntity, userLabel)) {
CommunicatorMessageId threadId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
List<CommunicatorMessage> receivedItems = communicatorController.listMessagesByMessageId(userEntity, threadId, false);
List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(userEntity, threadId);
List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
CommunicatorMessageId olderThread = communicatorController.findOlderThreadId(userEntity, threadId, CommunicatorFolderType.LABEL, userLabel);
CommunicatorMessageId newerThread = communicatorController.findNewerThreadId(userEntity, threadId, CommunicatorFolderType.LABEL, userLabel);
return Response.ok(restModels.restThreadViewModel(receivedItems, olderThread, newerThread, restLabels)).build();
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
Aggregations