use of de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto in project SORMAS-Project by hzi-braunschweig.
the class CampaignDataGrid method setDataProvider.
public void setDataProvider() {
DataProvider<CampaignFormDataIndexDto, CampaignFormDataCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getCampaignFormDataFacade().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.getCampaignFormDataFacade().count(query.getFilter().orElse(null)));
setDataProvider(dataProvider);
setSelectionMode(SelectionMode.NONE);
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto in project SORMAS-Project by hzi-braunschweig.
the class CampaignFormDataFacadeEjb method getIndexList.
@Override
public List<CampaignFormDataIndexDto> getIndexList(CampaignFormDataCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<CampaignFormDataIndexDto> cq = cb.createQuery(CampaignFormDataIndexDto.class);
Root<CampaignFormData> root = cq.from(CampaignFormData.class);
Join<CampaignFormData, Campaign> campaignJoin = root.join(CampaignFormData.CAMPAIGN, JoinType.LEFT);
Join<CampaignFormData, CampaignFormMeta> campaignFormMetaJoin = root.join(CampaignFormData.CAMPAIGN_FORM_META, JoinType.LEFT);
Join<CampaignFormData, Region> regionJoin = root.join(CampaignFormData.REGION, JoinType.LEFT);
Join<CampaignFormData, District> districtJoin = root.join(CampaignFormData.DISTRICT, JoinType.LEFT);
Join<CampaignFormData, Community> communityJoin = root.join(CampaignFormData.COMMUNITY, JoinType.LEFT);
cq.multiselect(root.get(CampaignFormData.UUID), campaignJoin.get(Campaign.NAME), campaignFormMetaJoin.get(CampaignFormMeta.FORM_NAME), criteria.getCampaignFormMeta() != null ? root.get(CampaignFormData.FORM_VALUES) : cb.nullLiteral(String.class), regionJoin.get(Region.NAME), districtJoin.get(District.NAME), communityJoin.get(Community.NAME), root.get(CampaignFormData.FORM_DATE));
Predicate filter = CriteriaBuilderHelper.and(cb, campaignFormDataService.createCriteriaFilter(criteria, cb, root), campaignFormDataService.createUserFilter(cb, cq, root));
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 CampaignFormDataIndexDto.UUID:
case CampaignFormDataIndexDto.FORM_DATE:
expression = root.get(sortProperty.propertyName);
break;
case CampaignFormDataIndexDto.CAMPAIGN:
expression = campaignJoin.get(Campaign.NAME);
break;
case CampaignFormDataIndexDto.FORM:
expression = campaignFormMetaJoin.get(CampaignFormMeta.FORM_NAME);
break;
case CampaignFormDataIndexDto.REGION:
expression = regionJoin.get(Region.NAME);
break;
case CampaignFormDataIndexDto.DISTRICT:
expression = districtJoin.get(District.NAME);
break;
case CampaignFormDataIndexDto.COMMUNITY:
expression = communityJoin.get(Community.NAME);
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(root.get(CampaignFormData.CHANGE_DATE)));
}
return QueryHelper.getResultList(em, cq, first, max);
}
Aggregations