Search in sources :

Example 1 with ContactListEntryDtoResultTransformer

use of de.symeda.sormas.backend.contact.transformers.ContactListEntryDtoResultTransformer in project SORMAS-Project by hzi-braunschweig.

the class ContactService method getEntriesList.

public List<ContactListEntryDto> getEntriesList(Long personId, Integer first, Integer max) {
    if (personId == null) {
        return Collections.emptyList();
    }
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    final Root<Contact> contact = cq.from(Contact.class);
    ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
    cq.multiselect(contact.get(Contact.UUID), contact.get(Contact.CONTACT_STATUS), contact.get(Contact.DISEASE), contact.get(Contact.CONTACT_CLASSIFICATION), contact.get(Contact.CONTACT_CATEGORY), JurisdictionHelper.booleanSelector(cb, inJurisdictionOrOwned(contactQueryContext)), contact.get(Contact.CHANGE_DATE));
    Predicate filter = cb.equal(contact.get(Contact.PERSON_ID), personId);
    filter = CriteriaBuilderHelper.and(cb, filter, cb.isFalse(contact.get(Contact.DELETED)));
    cq.where(filter);
    cq.orderBy(cb.desc(contact.get(Contact.CHANGE_DATE)));
    cq.distinct(true);
    return createQuery(cq, first, max).unwrap(org.hibernate.query.Query.class).setResultTransformer(new ContactListEntryDtoResultTransformer()).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Subquery(javax.persistence.criteria.Subquery) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) ContactListEntryDtoResultTransformer(de.symeda.sormas.backend.contact.transformers.ContactListEntryDtoResultTransformer) Predicate(javax.persistence.criteria.Predicate)

Aggregations

AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)1 ContactListEntryDtoResultTransformer (de.symeda.sormas.backend.contact.transformers.ContactListEntryDtoResultTransformer)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 Subquery (javax.persistence.criteria.Subquery)1