Search in sources :

Example 1 with CampaignFormDataIndexDto

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);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) CampaignFormDataIndexDto(de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto) CampaignFormDataCriteria(de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria)

Example 2 with CampaignFormDataIndexDto

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

Aggregations

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