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