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));
}
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();
}
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();
}
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;
}
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;
}
Aggregations