Search in sources :

Example 1 with Campaign

use of de.symeda.sormas.backend.campaign.Campaign 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;
}
Also used : Campaign(de.symeda.sormas.backend.campaign.Campaign) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community) CampaignFormMeta(de.symeda.sormas.backend.campaign.form.CampaignFormMeta) Predicate(javax.persistence.criteria.Predicate)

Example 2 with Campaign

use of de.symeda.sormas.backend.campaign.Campaign 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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) CampaignFormDataIndexDto(de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto) CampaignFormMeta(de.symeda.sormas.backend.campaign.form.CampaignFormMeta) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) Campaign(de.symeda.sormas.backend.campaign.Campaign) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Example 3 with Campaign

use of de.symeda.sormas.backend.campaign.Campaign in project SORMAS-Project by hzi-braunschweig.

the class CampaignFormMetaService method getCampaignFormMetasAsReferencesByCampaign.

public List<CampaignFormMetaReferenceDto> getCampaignFormMetasAsReferencesByCampaign(String uuid) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CampaignFormMetaReferenceDto> cq = cb.createQuery(CampaignFormMetaReferenceDto.class);
    Root<Campaign> campaignRoot = cq.from(Campaign.class);
    Join<Campaign, CampaignFormMeta> campaignFormMetaJoin = campaignRoot.join(Campaign.CAMPAIGN_FORM_METAS);
    Predicate filter = cb.equal(campaignRoot.get(Campaign.UUID), uuid);
    cq = cq.where(filter);
    cq.multiselect(campaignFormMetaJoin.get(CampaignFormMeta.UUID), campaignFormMetaJoin.get(CampaignFormMeta.FORM_NAME));
    return em.createQuery(cq).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Campaign(de.symeda.sormas.backend.campaign.Campaign) CampaignFormMetaReferenceDto(de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto) Predicate(javax.persistence.criteria.Predicate)

Aggregations

Campaign (de.symeda.sormas.backend.campaign.Campaign)3 Predicate (javax.persistence.criteria.Predicate)3 CampaignFormMeta (de.symeda.sormas.backend.campaign.form.CampaignFormMeta)2 Community (de.symeda.sormas.backend.infrastructure.community.Community)2 District (de.symeda.sormas.backend.infrastructure.district.District)2 Region (de.symeda.sormas.backend.infrastructure.region.Region)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 CampaignFormDataIndexDto (de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto)1 CampaignFormMetaReferenceDto (de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto)1 SortProperty (de.symeda.sormas.api.utils.SortProperty)1 ArrayList (java.util.ArrayList)1 Order (javax.persistence.criteria.Order)1