Search in sources :

Example 16 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class PersonGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<PersonIndexDto, PersonCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getPersonFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getPersonFacade().count(query.getFilter().orElse(null)));
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria)

Example 17 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantFacadeEjb method getIndexList.

@Override
public List<EventParticipantIndexDto> getIndexList(EventParticipantCriteria eventParticipantCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    if ((eventParticipantCriteria == null) || (eventParticipantCriteria.getEvent() == null && eventParticipantCriteria.getPerson() == null)) {
        // Retrieving an index list independent of an event is not possible
        return new ArrayList<>();
    }
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<EventParticipantIndexDto> cq = cb.createQuery(EventParticipantIndexDto.class);
    final Root<EventParticipant> eventParticipant = cq.from(EventParticipant.class);
    final EventParticipantQueryContext queryContext = new EventParticipantQueryContext(cb, cq, eventParticipant);
    EventParticipantJoins joins = queryContext.getJoins();
    Join<EventParticipant, Person> person = joins.getPerson();
    Join<EventParticipant, Case> resultingCase = joins.getResultingCase();
    Join<EventParticipant, Event> event = joins.getEvent();
    final Join<EventParticipant, Sample> samples = eventParticipant.join(EventParticipant.SAMPLES, JoinType.LEFT);
    samples.on(cb.and(cb.isFalse(samples.get(DeletableAdo.DELETED)), cb.equal(samples.get(Sample.ASSOCIATED_EVENT_PARTICIPANT), eventParticipant.get(AbstractDomainObject.ID))));
    Expression<Object> inJurisdictionSelector = JurisdictionHelper.booleanSelector(cb, service.inJurisdiction(queryContext));
    Expression<Object> inJurisdictionOrOwnedSelector = JurisdictionHelper.booleanSelector(cb, service.inJurisdictionOrOwned(queryContext));
    cq.multiselect(eventParticipant.get(EventParticipant.UUID), person.get(Person.UUID), resultingCase.get(Case.UUID), event.get(Event.UUID), person.get(Person.FIRST_NAME), person.get(Person.LAST_NAME), person.get(Person.SEX), person.get(Person.APPROXIMATE_AGE), person.get(Person.APPROXIMATE_AGE_TYPE), eventParticipant.get(EventParticipant.INVOLVEMENT_DESCRIPTION), // POSITIVE is the max value of available results
    cb.max(samples.get(Sample.PATHOGEN_TEST_RESULT)), // all samples have the same date, but have to be aggregated
    cb.max(samples.get(Sample.SAMPLE_DATE_TIME)), eventParticipant.get(EventParticipant.VACCINATION_STATUS), joins.getEventParticipantReportingUser().get(User.UUID), inJurisdictionSelector, inJurisdictionOrOwnedSelector);
    cq.groupBy(eventParticipant.get(EventParticipant.ID), eventParticipant.get(EventParticipant.UUID), person.get(Person.UUID), resultingCase.get(Case.UUID), event.get(Event.UUID), person.get(Person.FIRST_NAME), person.get(Person.LAST_NAME), person.get(Person.SEX), person.get(Person.APPROXIMATE_AGE), person.get(Person.APPROXIMATE_AGE_TYPE), eventParticipant.get(EventParticipant.INVOLVEMENT_DESCRIPTION), eventParticipant.get(EventParticipant.VACCINATION_STATUS), joins.getEventParticipantReportingUser().get(User.ID), joins.getEventParticipantReportingUser().get(User.UUID), inJurisdictionSelector, inJurisdictionOrOwnedSelector);
    Predicate filter = service.buildCriteriaFilter(eventParticipantCriteria, queryContext);
    if (eventParticipantCriteria.getPathogenTestResult() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(samples.get(Sample.PATHOGEN_TEST_RESULT), eventParticipantCriteria.getPathogenTestResult()));
    }
    if (filter != null) {
        cq.where(filter);
    }
    if (sortProperties != null && sortProperties.size() > 0) {
        List<Order> order = new ArrayList<>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case EventParticipantIndexDto.UUID:
                case EventParticipantIndexDto.INVOLVEMENT_DESCRIPTION:
                case EventParticipantIndexDto.VACCINATION_STATUS:
                    expression = eventParticipant.get(sortProperty.propertyName);
                    break;
                case EventParticipantIndexDto.PERSON_UUID:
                    expression = person.get(Person.UUID);
                    break;
                case EventParticipantIndexDto.APPROXIMATE_AGE:
                case EventParticipantIndexDto.SEX:
                case EventParticipantIndexDto.LAST_NAME:
                case EventParticipantIndexDto.FIRST_NAME:
                    expression = person.get(sortProperty.propertyName);
                    break;
                case EventParticipantIndexDto.CASE_UUID:
                    expression = resultingCase.get(Case.UUID);
                    break;
                default:
                    throw new IllegalArgumentException(sortProperty.propertyName);
            }
            order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
        }
        cq.orderBy(order);
    } else {
        cq.orderBy(cb.desc(person.get(Person.LAST_NAME)));
    }
    List<EventParticipantIndexDto> indexList = QueryHelper.getResultList(em, cq, first, max);
    if (!indexList.isEmpty()) {
        Map<String, Long> eventParticipantContactCount = getContactCountPerEventParticipant(indexList.stream().map(EventParticipantIndexDto::getUuid).collect(Collectors.toList()), eventParticipantCriteria);
        for (EventParticipantIndexDto eventParticipantIndexDto : indexList) {
            Optional.ofNullable(eventParticipantContactCount.get(eventParticipantIndexDto.getUuid())).ifPresent(eventParticipantIndexDto::setContactCount);
        }
    }
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    pseudonymizer.pseudonymizeDtoCollection(EventParticipantIndexDto.class, indexList, p -> p.getInJurisdictionOrOwned(), null);
    return indexList;
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) Sample(de.symeda.sormas.backend.sample.Sample) EventParticipantIndexDto(de.symeda.sormas.api.event.EventParticipantIndexDto) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Person(de.symeda.sormas.backend.person.Person)

Example 18 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class DocumentService method getRelatedToEntity.

public List<Document> getRelatedToEntity(DocumentRelatedEntityType type, String uuid, List<SortProperty> sortProperties) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Document> cq = cb.createQuery(getElementClass());
    Root<Document> from = cq.from(getElementClass());
    from.fetch(Document.UPLOADING_USER);
    Predicate filter = cb.and(cb.isFalse(from.get(Document.DELETED)), cb.equal(from.get(Document.RELATED_ENTITY_TYPE), type), cb.equal(from.get(Document.RELATED_ENTITY_UUID), uuid));
    cq.where(filter);
    if (sortProperties != null && sortProperties.size() > 0) {
        List<Order> order = new ArrayList<Order>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case DocumentDto.UUID:
                case DocumentDto.NAME:
                case DocumentDto.CONTENT_TYPE:
                case DocumentDto.SIZE:
                    expression = from.get(sortProperty.propertyName);
                    break;
                default:
                    throw new IllegalArgumentException(sortProperty.propertyName);
            }
            order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
        }
        cq.orderBy(order);
    } else {
        cq.orderBy(cb.desc(from.get(Document.CHANGE_DATE)));
    }
    cq.distinct(true);
    return em.createQuery(cq).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) SortProperty(de.symeda.sormas.api.utils.SortProperty) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 19 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class EventGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<EventIndexDto, EventCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getEventFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getEventFacade().count(query.getFilter().orElse(null)));
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria)

Example 20 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class EventActionsGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<EventActionIndexDto, EventCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getActionFacade().getEventActionList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getActionFacade().countEventActions(query.getFilter().orElse(null)));
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : EventActionIndexDto(de.symeda.sormas.api.event.EventActionIndexDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) EventCriteria(de.symeda.sormas.api.event.EventCriteria)

Aggregations

SortProperty (de.symeda.sormas.api.utils.SortProperty)73 ArrayList (java.util.ArrayList)42 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)37 Order (javax.persistence.criteria.Order)37 Predicate (javax.persistence.criteria.Predicate)34 Date (java.util.Date)14 District (de.symeda.sormas.backend.infrastructure.district.District)13 Region (de.symeda.sormas.backend.infrastructure.region.Region)10 Pseudonymizer (de.symeda.sormas.backend.util.Pseudonymizer)10 PersonDto (de.symeda.sormas.api.person.PersonDto)9 Location (de.symeda.sormas.backend.location.Location)8 AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)7 Person (de.symeda.sormas.backend.person.Person)7 User (de.symeda.sormas.backend.user.User)7 Collectors (java.util.stream.Collectors)6 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)5 UserDto (de.symeda.sormas.api.user.UserDto)5 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)5 Case (de.symeda.sormas.backend.caze.Case)5 Selection (javax.persistence.criteria.Selection)5