Search in sources :

Example 21 with CommunicatorMessageRecipient

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

the class CommunicatorMessageRecipientDAO method listByMessage.

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

Example 22 with CommunicatorMessageRecipient

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

the class CommunicatorMessageRecipientDAO method listByUserAndRead.

public List<CommunicatorMessageRecipient> listByUserAndRead(UserEntity user, boolean read, boolean trashed) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CommunicatorMessageRecipient> criteria = criteriaBuilder.createQuery(CommunicatorMessageRecipient.class);
    Root<CommunicatorMessageRecipient> root = criteria.from(CommunicatorMessageRecipient.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.recipient), user.getId()), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.readByReceiver), read), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.trashedByReceiver), trashed), criteriaBuilder.equal(root.get(CommunicatorMessageRecipient_.archivedByReceiver), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) EntityManager(javax.persistence.EntityManager)

Example 23 with CommunicatorMessageRecipient

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

the class CommunicatorMessageRecipientDAO method create.

public CommunicatorMessageRecipient create(CommunicatorMessage communicatorMessage, UserEntity recipient, CommunicatorMessageRecipientGroup recipientGroup) {
    CommunicatorMessageRecipient msg = new CommunicatorMessageRecipient();
    msg.setCommunicatorMessage(communicatorMessage);
    msg.setRecipient(recipient.getId());
    msg.setRecipientGroup(recipientGroup);
    msg.setReadByReceiver(false);
    msg.setArchivedByReceiver(false);
    msg.setTrashedByReceiver(false);
    getEntityManager().persist(msg);
    return msg;
}
Also used : CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient)

Example 24 with CommunicatorMessageRecipient

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

the class CommunicatorMessageRecipientDAO method listByMessageIncludeGroupRecipients.

public List<CommunicatorMessageRecipient> listByMessageIncludeGroupRecipients(CommunicatorMessage communicatorMessage) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CommunicatorMessageRecipient> criteria = criteriaBuilder.createQuery(CommunicatorMessageRecipient.class);
    Root<CommunicatorMessageRecipient> root = criteria.from(CommunicatorMessageRecipient.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.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)

Example 25 with CommunicatorMessageRecipient

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

the class CommunicatorMessageRecipientDAO method listByUserAndMessageId.

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

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