Search in sources :

Example 6 with CommunicatorMessageIdLabel

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.

the class CommunicatorLabelRESTService method listMessageIdLabels.

@GET
@Path("/messages/{COMMUNICATORMESSAGEID}/labels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listMessageIdLabels(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) throws AuthorizationException {
    CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
    // Lists only labels of logged user so we can consider this safe
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(userEntity, messageId);
    return Response.ok(restModels.restLabel(labels)).build();
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 7 with CommunicatorMessageIdLabel

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.

the class CommunicatorRESTService method listUserUnreadCommunicatorMessagesByMessageId.

@GET
@Path("/unread/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserUnreadCommunicatorMessagesByMessageId(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
    UserEntity user = sessionController.getLoggedUserEntity();
    CommunicatorMessageId threadId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
    List<CommunicatorMessage> receivedItems = communicatorController.listMessagesByMessageId(user, threadId, false);
    List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, threadId);
    List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
    CommunicatorMessageId olderThread = communicatorController.findOlderThreadId(user, threadId, CommunicatorFolderType.UNREAD, null);
    CommunicatorMessageId newerThread = communicatorController.findNewerThreadId(user, threadId, CommunicatorFolderType.UNREAD, null);
    return Response.ok(restModels.restThreadViewModel(receivedItems, olderThread, newerThread, restLabels)).build();
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 8 with CommunicatorMessageIdLabel

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.

the class CommunicatorRESTService method listUserSentCommunicatorMessagesByMessageId.

@GET
@Path("/sentitems/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserSentCommunicatorMessagesByMessageId(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
    UserEntity user = sessionController.getLoggedUserEntity();
    CommunicatorMessageId threadId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
    List<CommunicatorMessage> receivedItems = communicatorController.listMessagesByMessageId(user, threadId, false);
    CommunicatorMessageId olderThread = communicatorController.findOlderThreadId(user, threadId, CommunicatorFolderType.SENT, null);
    CommunicatorMessageId newerThread = communicatorController.findNewerThreadId(user, threadId, CommunicatorFolderType.SENT, null);
    List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, threadId);
    List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
    return Response.ok(restModels.restThreadViewModel(receivedItems, olderThread, newerThread, restLabels)).build();
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 9 with CommunicatorMessageIdLabel

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.

the class CommunicatorRESTService method listUserInboxMessages.

@GET
@Path("/items")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserInboxMessages(@QueryParam("labelId") Long labelId, @QueryParam("onlyUnread") @DefaultValue("false") Boolean onlyUnread, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
    UserEntity user = sessionController.getLoggedUserEntity();
    CommunicatorLabel label;
    if (labelId != null) {
        label = communicatorController.findUserLabelById(labelId);
        if (label == null)
            return Response.status(Status.NOT_FOUND).build();
    } else
        label = null;
    List<CommunicatorMessage> receivedItems;
    if (label != null)
        receivedItems = communicatorController.listReceivedItems(user, label, onlyUnread, firstResult, maxResults);
    else
        receivedItems = communicatorController.listReceivedItems(user, onlyUnread, firstResult, maxResults);
    List<CommunicatorThreadRESTModel> result = new ArrayList<CommunicatorThreadRESTModel>();
    for (CommunicatorMessage receivedItem : receivedItems) {
        String categoryName = receivedItem.getCategory() != null ? receivedItem.getCategory().getName() : null;
        boolean hasUnreadMsgs = false;
        Date latestMessageDate = receivedItem.getCreated();
        List<CommunicatorMessageRecipient> recipients = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, receivedItem.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(receivedItem);
        Long messageCountInThread = communicatorController.countMessagesByUserAndMessageId(user, receivedItem.getCommunicatorMessageId(), false);
        List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, receivedItem.getCommunicatorMessageId());
        List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
        result.add(new CommunicatorThreadRESTModel(receivedItem.getId(), receivedItem.getCommunicatorMessageId().getId(), receivedItem.getSender(), senderBasicInfo, categoryName, receivedItem.getCaption(), receivedItem.getCreated(), tagIdsToStr(receivedItem.getTags()), hasUnreadMsgs, latestMessageDate, messageCountInThread, restLabels));
    }
    return Response.ok(result).build();
}
Also used : CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) ArrayList(java.util.ArrayList) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Date(java.util.Date) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) UserBasicInfo(fi.otavanopisto.muikku.rest.model.UserBasicInfo) CommunicatorLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorLabel) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 10 with CommunicatorMessageIdLabel

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel in project muikku by otavanopisto.

the class CommunicatorRESTService method listUserCommunicatorMessagesByMessageId.

@GET
@Path("/messages/{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, false);
    List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, threadId);
    List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
    CommunicatorMessageId olderThread = communicatorController.findOlderThreadId(user, threadId, CommunicatorFolderType.INBOX, null);
    CommunicatorMessageId newerThread = communicatorController.findNewerThreadId(user, threadId, CommunicatorFolderType.INBOX, null);
    return Response.ok(restModels.restThreadViewModel(receivedItems, olderThread, newerThread, restLabels)).build();
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

CommunicatorMessageIdLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel)18 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)11 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)11 Path (javax.ws.rs.Path)11 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)10 GET (javax.ws.rs.GET)10 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)8 CommunicatorMessageRecipient (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient)5 EntityManager (javax.persistence.EntityManager)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 UserBasicInfo (fi.otavanopisto.muikku.rest.model.UserBasicInfo)3 CommunicatorLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorLabel)2 CommunicatorMessageRecipientUserGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup)2 CommunicatorMessageRecipientWorkspaceGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup)2 CommunicatorUserLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel)1 Join (javax.persistence.criteria.Join)1 Predicate (javax.persistence.criteria.Predicate)1 Root (javax.persistence.criteria.Root)1