use of de.symeda.sormas.backend.campaign.form.CampaignFormMeta in project SORMAS-Project by hzi-braunschweig.
the class CampaignFormDataService method createCriteriaFilter.
public Predicate createCriteriaFilter(CampaignFormDataCriteria criteria, CriteriaBuilder cb, Root<CampaignFormData> root) {
Join<CampaignFormData, Campaign> campaignJoin = root.join(CampaignFormData.CAMPAIGN, JoinType.LEFT);
Join<CampaignFormData, CampaignFormMeta> campaignFormJoin = 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);
Predicate filter = null;
if (criteria.getCampaign() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(campaignJoin.get(Campaign.UUID), criteria.getCampaign().getUuid()));
} else {
filter = CriteriaBuilderHelper.and(cb, filter, cb.or(cb.equal(campaignJoin.get(Campaign.ARCHIVED), false), cb.isNull(campaignJoin.get(Campaign.ARCHIVED))));
}
if (criteria.getCampaignFormMeta() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(campaignFormJoin.get(CampaignFormMeta.UUID), criteria.getCampaignFormMeta().getUuid()));
}
if (criteria.getRegion() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(regionJoin.get(Region.UUID), criteria.getRegion().getUuid()));
}
if (criteria.getDistrict() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(districtJoin.get(District.UUID), criteria.getDistrict().getUuid()));
}
if (criteria.getCommunity() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(communityJoin.get(Community.UUID), criteria.getCommunity().getUuid()));
}
if (criteria.getFormDate() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.greaterThanOrEqualTo(root.get(CampaignFormData.FORM_DATE), DateHelper.getStartOfDay(criteria.getFormDate())), cb.lessThanOrEqualTo(root.get(CampaignFormData.FORM_DATE), DateHelper.getEndOfDay(criteria.getFormDate())));
}
return filter;
}
use of de.symeda.sormas.backend.campaign.form.CampaignFormMeta 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