Search in sources :

Example 11 with CommunicatorMessageRecipient

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

the class CommunicatorRESTModels method restFullMessage.

public CommunicatorMessageRESTModel restFullMessage(CommunicatorMessage message) {
    String categoryName = message.getCategory() != null ? message.getCategory().getName() : null;
    UserBasicInfo senderBasicInfo = getSenderBasicInfo(message);
    List<CommunicatorMessageRecipient> messageRecipients = communicatorController.listCommunicatorMessageRecipients(message);
    List<CommunicatorMessageRecipientUserGroup> userGroupRecipients = communicatorController.listCommunicatorMessageUserGroupRecipients(message);
    List<CommunicatorMessageRecipientWorkspaceGroup> workspaceGroupRecipients = communicatorController.listCommunicatorMessageWorkspaceGroupRecipients(message);
    Long recipientCount = (long) messageRecipients.size();
    List<CommunicatorMessageRecipientRESTModel> restRecipients = restRecipient(messageRecipients);
    List<fi.otavanopisto.muikku.rest.model.UserGroup> restUserGroupRecipients = restUserGroupRecipients(userGroupRecipients);
    List<CommunicatorMessageRecipientWorkspaceGroupRESTModel> restWorkspaceRecipients = restWorkspaceGroupRecipients(workspaceGroupRecipients);
    return new CommunicatorMessageRESTModel(message.getId(), message.getCommunicatorMessageId().getId(), message.getSender(), senderBasicInfo, categoryName, message.getCaption(), message.getContent(), message.getCreated(), tagIdsToStr(message.getTags()), restRecipients, restUserGroupRecipients, restWorkspaceRecipients, recipientCount);
}
Also used : CommunicatorMessageRecipientUserGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup) UserGroup(fi.otavanopisto.muikku.schooldata.entity.UserGroup) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) UserBasicInfo(fi.otavanopisto.muikku.rest.model.UserBasicInfo) CommunicatorMessageRecipientUserGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup) CommunicatorMessageRecipientWorkspaceGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup)

Example 12 with CommunicatorMessageRecipient

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

the class CommunicatorRESTService method markInboxAsUnRead.

@POST
@Path("/items/{COMMUNICATORMESSAGEID}/markasunread")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response markInboxAsUnRead(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId, @QueryParam("messageIds") List<Long> messageIds) {
    UserEntity user = sessionController.getLoggedUserEntity();
    CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
    List<CommunicatorMessageRecipient> list = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, messageId, false);
    for (CommunicatorMessageRecipient r : list) {
        if ((messageIds != null) && (r.getCommunicatorMessage() != null)) {
            if (!messageIds.isEmpty() && !messageIds.contains(r.getCommunicatorMessage().getId()))
                continue;
        }
        communicatorController.updateRead(r, false);
    }
    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 13 with CommunicatorMessageRecipient

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

the class CommunicatorRESTService method listCommunicatorMessageRecipients.

@GET
@Path("/communicatormessages/{COMMUNICATORMESSAGEID}/recipients/{RECIPIENTID}/info")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listCommunicatorMessageRecipients(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId, @PathParam("RECIPIENTID") Long recipientId) throws AuthorizationException {
    CommunicatorMessageRecipient recipient = communicatorController.findCommunicatorMessageRecipient(recipientId);
    CommunicatorMessage communicatorMessage = communicatorController.findCommunicatorMessageById(communicatorMessageId);
    if (!hasCommunicatorMessageAccess(communicatorMessage)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    schoolDataBridgeSessionController.startSystemSession();
    try {
        UserEntity userEntity = userEntityController.findUserEntityById(recipient.getRecipient());
        fi.otavanopisto.muikku.schooldata.entity.User user = userController.findUserByUserEntityDefaults(userEntity);
        // TODO: userController.hasPicture(userEntity);
        Boolean hasPicture = false;
        fi.otavanopisto.muikku.rest.model.UserBasicInfo result = new fi.otavanopisto.muikku.rest.model.UserBasicInfo(userEntity.getId(), user.getFirstName(), user.getLastName(), user.getNickName(), user.getStudyProgrammeName(), hasPicture, user.hasEvaluationFees(), user.getCurriculumIdentifier());
        return Response.ok(result).build();
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
}
Also used : CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) UserBasicInfo(fi.otavanopisto.muikku.rest.model.UserBasicInfo) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) UserBasicInfo(fi.otavanopisto.muikku.rest.model.UserBasicInfo) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 14 with CommunicatorMessageRecipient

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient 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 15 with CommunicatorMessageRecipient

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient 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();
}
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)

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