Search in sources :

Example 1 with OrganisationUnitWithValidCoordinatesFilter

use of org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter in project dhis2-core by dhis2.

the class GeoFeatureController method getGeoFeatures.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
     * Returns list of geo features. Returns null if not modified based on the
     * request.
     *
     * @param ou                 the organisation unit parameter.
     * @param displayProperty    the display property.
     * @param relativePeriodDate the date to use as basis for relative periods.
     * @param userOrgUnit        the user organisation unit parameter.
     * @param request            the HTTP request.
     * @param response           the HTTP response.
     * @param includeGroupSets   whether to include organisation unit group sets.
     * @return a list of geo features or null.
     */
private List<GeoFeature> getGeoFeatures(String ou, DisplayProperty displayProperty, Date relativePeriodDate, String userOrgUnit, HttpServletRequest request, HttpServletResponse response, boolean includeGroupSets, DhisApiVersion apiVersion) {
    Set<String> set = new HashSet<>();
    set.add(ou);
    DataQueryParams params = dataQueryService.getFromUrl(set, null, AggregationType.SUM, null, null, null, null, false, false, false, false, false, false, false, false, false, false, displayProperty, null, null, false, null, relativePeriodDate, userOrgUnit, false, apiVersion);
    DimensionalObject dim = params.getDimension(DimensionalObject.ORGUNIT_DIM_ID);
    List<OrganisationUnit> organisationUnits = DimensionalObjectUtils.asTypedList(dim.getItems());
    FilterUtils.filter(organisationUnits, new OrganisationUnitWithValidCoordinatesFilter());
    boolean modified = !ContextUtils.clearIfNotModified(request, response, organisationUnits);
    if (!modified) {
        return null;
    }
    List<OrganisationUnitGroupSet> groupSets = includeGroupSets ? organisationUnitGroupService.getAllOrganisationUnitGroupSets() : null;
    List<GeoFeature> features = new ArrayList<>();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (OrganisationUnit unit : organisationUnits) {
        GeoFeature feature = new GeoFeature();
        Integer ty = unit.getFeatureType() != null ? FEATURE_TYPE_MAP.get(unit.getFeatureType()) : null;
        feature.setId(unit.getUid());
        feature.setCode(unit.getCode());
        feature.setHcd(unit.hasChildrenWithCoordinates());
        feature.setHcu(unit.hasCoordinatesUp());
        feature.setLe(unit.getLevel());
        feature.setPg(unit.getParentGraph(roots));
        feature.setPi(unit.getParent() != null ? unit.getParent().getUid() : null);
        feature.setPn(unit.getParent() != null ? unit.getParent().getDisplayName() : null);
        feature.setTy(ObjectUtils.firstNonNull(ty, 0));
        feature.setCo(unit.getCoordinates());
        feature.setNa(unit.getDisplayProperty(params.getDisplayProperty()));
        if (includeGroupSets) {
            for (OrganisationUnitGroupSet groupSet : groupSets) {
                OrganisationUnitGroup group = unit.getGroupInGroupSet(groupSet);
                if (group != null) {
                    feature.getDimensions().put(groupSet.getUid(), group.getUid());
                }
            }
        }
        features.add(feature);
    }
    Collections.sort(features, (o1, o2) -> Integer.valueOf(o1.getTy()).compareTo(Integer.valueOf(o2.getTy())));
    return features;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ArrayList(java.util.ArrayList) DimensionalObject(org.hisp.dhis.common.DimensionalObject) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnitWithValidCoordinatesFilter(org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) GeoFeature(org.hisp.dhis.webapi.webdomain.GeoFeature) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)1 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)1 OrganisationUnitWithValidCoordinatesFilter (org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter)1 GeoFeature (org.hisp.dhis.webapi.webdomain.GeoFeature)1