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