Search in sources :

Example 1 with CommunicatorMessage

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

the class Evaluation2RESTService method sendAssessmentNotification.

private void sendAssessmentNotification(WorkspaceEntity workspaceEntity, WorkspaceAssessment workspaceAssessment, UserEntity evaluator, UserEntity student, Workspace workspace, String grade) {
    String workspaceUrl = String.format("%s/workspace/%s/materials", baseUrl, workspaceEntity.getUrlName());
    Locale locale = userEntityController.getLocale(student);
    CommunicatorMessageCategory category = communicatorController.persistCategory("assessments");
    CommunicatorMessage communicatorMessage = communicatorController.createMessage(communicatorController.createMessageId(), evaluator, Arrays.asList(student), null, null, null, category, localeController.getText(locale, "plugin.workspace.assessment.notificationTitle", new Object[] { workspace.getName(), grade }), localeController.getText(locale, "plugin.workspace.assessment.notificationContent", new Object[] { workspaceUrl, workspace.getName(), grade, workspaceAssessment.getVerbalAssessment() }), Collections.<Tag>emptySet());
    communicatorMessageSentEvent.fire(new CommunicatorMessageSent(communicatorMessage.getId(), student.getId(), baseUrl));
}
Also used : Locale(java.util.Locale) CommunicatorMessageCategory(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) CommunicatorMessageSent(fi.otavanopisto.muikku.plugins.communicator.events.CommunicatorMessageSent)

Example 2 with CommunicatorMessage

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

the class CommunicatorMessageDAO method listMessagesInThread.

public List<CommunicatorMessage> listMessagesInThread(UserEntity user, CommunicatorMessageId communicatorMessageId, boolean trashed, boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CommunicatorMessage> criteria;
    Root<CommunicatorMessage> CommunicatorMessage;
    criteria = criteriaBuilder.createQuery(CommunicatorMessage.class);
    CommunicatorMessage = criteria.from(CommunicatorMessage.class);
    Root<CommunicatorMessageRecipient> recipient = criteria.from(CommunicatorMessageRecipient.class);
    Join<CommunicatorMessageRecipient, CommunicatorMessage> recipientMessage = criteriaBuilder.treat(recipient.join(CommunicatorMessageRecipient_.communicatorMessage), CommunicatorMessage.class);
    criteria.select(CommunicatorMessage);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(CommunicatorMessage.get(CommunicatorMessage_.id), recipientMessage.get(CommunicatorMessage_.id)), criteriaBuilder.equal(recipientMessage.get(CommunicatorMessage_.communicatorMessageId), communicatorMessageId), criteriaBuilder.equal(recipient.get(CommunicatorMessageRecipient_.recipient), user.getId()), criteriaBuilder.equal(recipient.get(CommunicatorMessageRecipient_.trashedByReceiver), trashed), criteriaBuilder.equal(recipient.get(CommunicatorMessageRecipient_.archivedByReceiver), archived)));
    return entityManager.createQuery(criteria).getResultList();
}
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)

Example 3 with CommunicatorMessage

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

the class CommunicatorMessageDAO method listMessagesInSentThread.

public List<CommunicatorMessage> listMessagesInSentThread(UserEntity sender, CommunicatorMessageId communicatorMessageId, boolean trashed, boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CommunicatorMessage> criteria = criteriaBuilder.createQuery(CommunicatorMessage.class);
    Root<CommunicatorMessage> root = criteria.from(CommunicatorMessage.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CommunicatorMessage_.communicatorMessageId), communicatorMessageId), criteriaBuilder.equal(root.get(CommunicatorMessage_.sender), sender.getId()), criteriaBuilder.equal(root.get(CommunicatorMessage_.trashedBySender), trashed), criteriaBuilder.equal(root.get(CommunicatorMessage_.archivedBySender), archived)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)

Example 4 with CommunicatorMessage

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

the class CommunicatorMessageDAO method listUserThreadBasicInfos.

private List<CommunicatorThreadBasicInfo> listUserThreadBasicInfos(UserEntity userEntity, CommunicatorFolderType type, CommunicatorLabel label) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CommunicatorThreadBasicInfo> criteria = criteriaBuilder.createQuery(CommunicatorThreadBasicInfo.class);
    switch(type) {
        case UNREAD:
            {
                Root<CommunicatorMessageRecipient> root = criteria.from(CommunicatorMessageRecipient.class);
                Join<CommunicatorMessageRecipient, CommunicatorMessage> messageJoin = root.join(CommunicatorMessageRecipient_.communicatorMessage);
                criteria.multiselect(messageJoin.get(CommunicatorMessage_.communicatorMessageId), criteriaBuilder.greatest(messageJoin.get(CommunicatorMessage_.created)));
                criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.recipient), userEntity.getId()), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.readByReceiver), Boolean.FALSE), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.trashedByReceiver), Boolean.FALSE), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.archivedByReceiver), Boolean.FALSE)));
                criteria.groupBy(messageJoin.get(CommunicatorMessage_.communicatorMessageId));
            }
            break;
        case LABEL:
            {
                Root<CommunicatorMessageRecipient> root = criteria.from(CommunicatorMessageRecipient.class);
                Join<CommunicatorMessageRecipient, CommunicatorMessage> messageJoin = root.join(CommunicatorMessageRecipient_.communicatorMessage);
                Join<CommunicatorMessage, CommunicatorMessageId> threadJoin = messageJoin.join(CommunicatorMessage_.communicatorMessageId);
                criteria.multiselect(messageJoin.get(CommunicatorMessage_.communicatorMessageId), criteriaBuilder.greatest(messageJoin.get(CommunicatorMessage_.created)));
                Root<CommunicatorMessageIdLabel> labelRoot = criteria.from(CommunicatorMessageIdLabel.class);
                criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.recipient), userEntity.getId()), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.trashedByReceiver), Boolean.FALSE), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.archivedByReceiver), Boolean.FALSE), threadJoin.in(labelRoot.get(CommunicatorMessageIdLabel_.communicatorMessageId)), criteriaBuilder.equal(labelRoot.get(CommunicatorMessageIdLabel_.label), label)));
                criteria.groupBy(messageJoin.get(CommunicatorMessage_.communicatorMessageId));
            }
            break;
        case SENT:
            {
                Root<CommunicatorMessage> root = criteria.from(CommunicatorMessage.class);
                criteria.multiselect(root.get(CommunicatorMessage_.communicatorMessageId), criteriaBuilder.greatest(root.get(CommunicatorMessage_.created)));
                criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CommunicatorMessage_.sender), userEntity.getId()), criteriaBuilder.equal(root.get(CommunicatorMessage_.archivedBySender), Boolean.FALSE), criteriaBuilder.equal(root.get(CommunicatorMessage_.trashedBySender), Boolean.FALSE)));
                criteria.groupBy(root.get(CommunicatorMessage_.communicatorMessageId));
            }
            break;
        case INBOX:
        case TRASH:
            Root<CommunicatorMessageRecipient> root = criteria.from(CommunicatorMessageRecipient.class);
            Join<CommunicatorMessageRecipient, CommunicatorMessage> messageJoin = root.join(CommunicatorMessageRecipient_.communicatorMessage);
            criteria.multiselect(messageJoin.get(CommunicatorMessage_.communicatorMessageId), criteriaBuilder.greatest(messageJoin.get(CommunicatorMessage_.created)));
            criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.recipient), userEntity.getId()), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.trashedByReceiver), type == CommunicatorFolderType.TRASH), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.archivedByReceiver), Boolean.FALSE)));
            criteria.groupBy(messageJoin.get(CommunicatorMessage_.communicatorMessageId));
            break;
    }
    List<CommunicatorThreadBasicInfo> threads = entityManager.createQuery(criteria).getResultList();
    Collections.sort(threads, new Comparator<CommunicatorThreadBasicInfo>() {

        @Override
        public int compare(CommunicatorThreadBasicInfo o1, CommunicatorThreadBasicInfo o2) {
            return o2.getLatestThread().compareTo(o1.getLatestThread());
        }
    });
    return threads;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) Root(javax.persistence.criteria.Root) Join(javax.persistence.criteria.Join) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) EntityManager(javax.persistence.EntityManager)

Example 5 with CommunicatorMessage

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

the class CommunicatorMessageDAO method create.

public CommunicatorMessage create(CommunicatorMessageId communicatorMessageId, Long sender, CommunicatorMessageCategory category, String caption, String content, Date created, Set<Tag> tags) {
    CommunicatorMessage msg = new CommunicatorMessage();
    int s = tags != null ? tags.size() : 0;
    Set<Long> tagIds = new HashSet<Long>(s);
    if (tags != null) {
        for (Tag t : tags) tagIds.add(t.getId());
    }
    msg.setCommunicatorMessageId(communicatorMessageId);
    msg.setSender(sender);
    msg.setCategory(category);
    msg.setCaption(caption);
    msg.setContent(content);
    msg.setCreated(created);
    msg.setTags(tagIds);
    msg.setArchivedBySender(false);
    msg.setTrashedBySender(false);
    getEntityManager().persist(msg);
    return msg;
}
Also used : CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) Tag(fi.otavanopisto.muikku.model.base.Tag) HashSet(java.util.HashSet)

Aggregations

CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)28 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)14 CommunicatorMessageRecipient (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient)13 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)12 Path (javax.ws.rs.Path)12 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)10 CommunicatorMessageIdLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel)10 GET (javax.ws.rs.GET)10 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)6 UserBasicInfo (fi.otavanopisto.muikku.rest.model.UserBasicInfo)5 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)4 Tag (fi.otavanopisto.muikku.model.base.Tag)3 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)3 CommunicatorMessageCategory (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory)3 CommunicatorMessageRecipientUserGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup)3 CommunicatorMessageRecipientWorkspaceGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup)3 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)2