Search in sources :

Example 16 with CommunicatorMessageRecipient

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

the class CommunicatorRESTService method markInboxAsRead.

@POST
@Path("/items/{COMMUNICATORMESSAGEID}/markasread")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response markInboxAsRead(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
    UserEntity user = sessionController.getLoggedUserEntity();
    CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
    List<CommunicatorMessageRecipient> list = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, messageId, false);
    for (CommunicatorMessageRecipient r : list) {
        communicatorController.updateRead(r, true);
    }
    return Response.noContent().build();
}
Also used : CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) 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) POST(javax.ws.rs.POST)

Example 17 with CommunicatorMessageRecipient

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

the class CommunicatorRESTService method getReceivedItemsCount.

@GET
@Path("/receiveditemscount")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getReceivedItemsCount() {
    UserEntity user = sessionController.getLoggedUserEntity();
    List<CommunicatorMessageRecipient> receivedItems = communicatorController.listReceivedItemsByUserAndRead(user, false, false);
    // TODO could be more elegant, i presume
    long count = 0;
    Set<Long> ids = new HashSet<Long>();
    for (CommunicatorMessageRecipient r : receivedItems) {
        Long id = r.getCommunicatorMessage().getCommunicatorMessageId().getId();
        if (!ids.contains(id)) {
            ids.add(id);
            count++;
        }
    }
    return Response.ok(count).build();
}
Also used : CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 18 with CommunicatorMessageRecipient

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient 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();
}
Also used : CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) ArrayList(java.util.ArrayList) CommunicatorMessageRecipientUserGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageRecipientUserGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Date(java.util.Date) UserBasicInfo(fi.otavanopisto.muikku.rest.model.UserBasicInfo) CommunicatorMessageRecipientWorkspaceGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 19 with CommunicatorMessageRecipient

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

the class CommunicatorController method trashAllThreadMessages.

public void trashAllThreadMessages(UserEntity user, CommunicatorMessageId messageId) {
    List<CommunicatorMessageRecipient> received = communicatorMessageRecipientDAO.listByUserAndMessageId(user, messageId, false, false);
    for (CommunicatorMessageRecipient recipient : received) {
        communicatorMessageRecipientDAO.updateTrashedByReceiver(recipient, true);
    }
    List<CommunicatorMessage> sentMessages = communicatorMessageDAO.listMessagesInSentThread(user, messageId, false, false);
    for (CommunicatorMessage message : sentMessages) {
        communicatorMessageDAO.updateTrashedBySender(message, true);
    }
}
Also used : CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)

Example 20 with CommunicatorMessageRecipient

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

the class CommunicatorMessageDAO method countMessagesByUserAndMessageId.

/**
 * Returns the number of messages the user can see in a thread in either inbox/sent or in trash
 * depending on the value of trashed parameter.
 *
 * @param user
 * @param communicatorMessageId
 * @param trashed
 * @return
 */
public Long countMessagesByUserAndMessageId(UserEntity user, CommunicatorMessageId communicatorMessageId, boolean trashed) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
    Root<CommunicatorMessageRecipient> root = criteria.from(CommunicatorMessageRecipient.class);
    Join<CommunicatorMessageRecipient, CommunicatorMessage> msgJoin = root.join(CommunicatorMessageRecipient_.communicatorMessage);
    criteria.select(criteriaBuilder.countDistinct(msgJoin));
    criteria.where(criteriaBuilder.or(criteriaBuilder.and(criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.communicatorMessageId), communicatorMessageId), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.recipient), user.getId()), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.trashedByReceiver), trashed), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.archivedByReceiver), Boolean.FALSE)), criteriaBuilder.and(criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.communicatorMessageId), communicatorMessageId), criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.sender), user.getId()), criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.trashedBySender), trashed), criteriaBuilder.equal(msgJoin.get(CommunicatorMessage_.archivedBySender), Boolean.FALSE))));
    return entityManager.createQuery(criteria).getSingleResult();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) EntityManager(javax.persistence.EntityManager) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)

Aggregations

CommunicatorMessageRecipient (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient)26 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)13 EntityManager (javax.persistence.EntityManager)12 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)12 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)9 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)9 Path (javax.ws.rs.Path)9 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)6 CommunicatorMessageIdLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel)5 UserBasicInfo (fi.otavanopisto.muikku.rest.model.UserBasicInfo)5 Date (java.util.Date)5 GET (javax.ws.rs.GET)5 CommunicatorMessageRecipientUserGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup)4 CommunicatorMessageRecipientWorkspaceGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup)4 ArrayList (java.util.ArrayList)4 POST (javax.ws.rs.POST)4 CommunicatorLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorLabel)1 UserGroup (fi.otavanopisto.muikku.schooldata.entity.UserGroup)1 HashSet (java.util.HashSet)1 Join (javax.persistence.criteria.Join)1