Search in sources :

Example 1 with CommunicatorMessageRecipientWorkspaceGroup

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

the class CommunicatorMessageRecipientWorkspaceGroupDAO method listByMessage.

public List<CommunicatorMessageRecipientWorkspaceGroup> listByMessage(CommunicatorMessage communicatorMessage) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CommunicatorMessageRecipientWorkspaceGroup> criteria = criteriaBuilder.createQuery(CommunicatorMessageRecipientWorkspaceGroup.class);
    Root<CommunicatorMessageRecipientWorkspaceGroup> root = criteria.from(CommunicatorMessageRecipientWorkspaceGroup.class);
    Root<CommunicatorMessageRecipient> root2 = criteria.from(CommunicatorMessageRecipient.class);
    criteria.select(root).distinct(true);
    criteria.where(criteriaBuilder.and(root2.get(CommunicatorMessageRecipient_.recipientGroup).in(root), criteriaBuilder.equal(root2.get(CommunicatorMessageRecipient_.communicatorMessage), communicatorMessage)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) EntityManager(javax.persistence.EntityManager) CommunicatorMessageRecipientWorkspaceGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup)

Example 2 with CommunicatorMessageRecipientWorkspaceGroup

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

the class CommunicatorController method createMessage.

public CommunicatorMessage createMessage(CommunicatorMessageId communicatorMessageId, UserEntity sender, List<UserEntity> userRecipients, List<UserGroupEntity> userGroupRecipients, List<WorkspaceEntity> workspaceStudentRecipients, List<WorkspaceEntity> workspaceTeacherRecipients, CommunicatorMessageCategory category, String caption, String content, Set<Tag> tags) {
    CommunicatorMessage message = communicatorMessageDAO.create(communicatorMessageId, sender.getId(), category, caption, clean(content), new Date(), tags);
    // Clean duplicates from recipient list
    cleanDuplicateRecipients(userRecipients);
    Set<Long> recipientIds = new HashSet<Long>();
    for (UserEntity recipient : userRecipients) {
        // #3758: Only send messages to active users
        if (!isActiveUser(recipient)) {
            continue;
        }
        if (!recipientIds.contains(recipient.getId())) {
            recipientIds.add(recipient.getId());
            communicatorMessageRecipientDAO.create(message, recipient, null);
        }
    }
    if (!CollectionUtils.isEmpty(userGroupRecipients)) {
        for (UserGroupEntity userGroup : userGroupRecipients) {
            List<UserGroupUserEntity> groupUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroup);
            if (!CollectionUtils.isEmpty(groupUsers)) {
                CommunicatorMessageRecipientUserGroup groupRecipient = createUserGroupRecipient(userGroup);
                for (UserGroupUserEntity groupUser : groupUsers) {
                    UserSchoolDataIdentifier userSchoolDataIdentifier = groupUser.getUserSchoolDataIdentifier();
                    UserEntity recipient = userSchoolDataIdentifier.getUserEntity();
                    // #3758: Only send messages to active users
                    if (!isActiveUser(recipient)) {
                        continue;
                    }
                    if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
                        if (!recipientIds.contains(recipient.getId())) {
                            recipientIds.add(recipient.getId());
                            communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
                        }
                    }
                }
            }
        }
    }
    if (!CollectionUtils.isEmpty(workspaceStudentRecipients)) {
        for (WorkspaceEntity workspaceEntity : workspaceStudentRecipients) {
            List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
            if (!CollectionUtils.isEmpty(workspaceUsers)) {
                CommunicatorMessageRecipientWorkspaceGroup groupRecipient = createWorkspaceGroupRecipient(workspaceEntity, WorkspaceRoleArchetype.STUDENT);
                for (WorkspaceUserEntity workspaceUserEntity : workspaceUsers) {
                    UserEntity recipient = workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity();
                    // #3758: Only send messages to active users
                    if (!isActiveUser(recipient)) {
                        continue;
                    }
                    if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
                        if (!recipientIds.contains(recipient.getId())) {
                            recipientIds.add(recipient.getId());
                            communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
                        }
                    }
                }
            }
        }
    }
    if (!CollectionUtils.isEmpty(workspaceTeacherRecipients)) {
        for (WorkspaceEntity workspaceEntity : workspaceTeacherRecipients) {
            List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
            if (!CollectionUtils.isEmpty(workspaceUsers)) {
                CommunicatorMessageRecipientWorkspaceGroup groupRecipient = createWorkspaceGroupRecipient(workspaceEntity, WorkspaceRoleArchetype.TEACHER);
                for (WorkspaceUserEntity wosu : workspaceUsers) {
                    UserEntity recipient = wosu.getUserSchoolDataIdentifier().getUserEntity();
                    // #3758: Workspace teachers are considered active, no need to check
                    if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
                        if (!recipientIds.contains(recipient.getId())) {
                            recipientIds.add(recipient.getId());
                            communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
                        }
                    }
                }
            }
        }
    }
    return message;
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) Date(java.util.Date) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) CommunicatorMessageRecipientUserGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) CommunicatorMessageRecipientWorkspaceGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup) HashSet(java.util.HashSet)

Example 3 with CommunicatorMessageRecipientWorkspaceGroup

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

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup 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)

Example 5 with CommunicatorMessageRecipientWorkspaceGroup

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup 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)

Aggregations

CommunicatorMessageRecipientWorkspaceGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup)6 CommunicatorMessageRecipient (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient)4 CommunicatorMessageRecipientUserGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup)4 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)3 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)3 UserBasicInfo (fi.otavanopisto.muikku.rest.model.UserBasicInfo)3 Date (java.util.Date)3 CommunicatorMessageIdLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel)2 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)1 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 UserGroup (fi.otavanopisto.muikku.schooldata.entity.UserGroup)1 HashSet (java.util.HashSet)1 EntityManager (javax.persistence.EntityManager)1