Search in sources :

Example 1 with GeoFeature

use of org.hisp.dhis.webapi.webdomain.GeoFeature in project dhis2-core by dhis2.

the class GeoFeatureController method getGeoFeaturesJsonP.

@RequestMapping(method = RequestMethod.GET, produces = { "application/javascript" })
public void getGeoFeaturesJsonP(@RequestParam String ou, @RequestParam(required = false) DisplayProperty displayProperty, @RequestParam(required = false) Date relativePeriodDate, @RequestParam(required = false) String userOrgUnit, @RequestParam(defaultValue = "callback") String callback, @RequestParam(defaultValue = "false", value = "includeGroupSets") boolean rpIncludeGroupSets, @RequestParam Map<String, String> parameters, DhisApiVersion apiVersion, HttpServletRequest request, HttpServletResponse response) throws IOException {
    WebOptions options = new WebOptions(parameters);
    boolean includeGroupSets = "detailed".equals(options.getViewClass()) || rpIncludeGroupSets;
    List<GeoFeature> features = getGeoFeatures(ou, displayProperty, relativePeriodDate, userOrgUnit, request, response, includeGroupSets, apiVersion);
    if (features == null) {
        return;
    }
    ContextUtils.setCacheControl(response, GEOFEATURE_CACHE);
    response.setContentType("application/javascript");
    renderService.toJsonP(response.getOutputStream(), features, callback);
}
Also used : WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) GeoFeature(org.hisp.dhis.webapi.webdomain.GeoFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with GeoFeature

use of org.hisp.dhis.webapi.webdomain.GeoFeature 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)

Example 3 with GeoFeature

use of org.hisp.dhis.webapi.webdomain.GeoFeature in project dhis2-core by dhis2.

the class GeoFeatureController method getGeoFeaturesJson.

// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.GET, produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_HTML })
public void getGeoFeaturesJson(@RequestParam String ou, @RequestParam(required = false) DisplayProperty displayProperty, @RequestParam(required = false) Date relativePeriodDate, @RequestParam(required = false) String userOrgUnit, @RequestParam(defaultValue = "false", value = "includeGroupSets") boolean rpIncludeGroupSets, @RequestParam Map<String, String> parameters, DhisApiVersion apiVersion, HttpServletRequest request, HttpServletResponse response) throws IOException {
    WebOptions options = new WebOptions(parameters);
    boolean includeGroupSets = "detailed".equals(options.getViewClass()) || rpIncludeGroupSets;
    List<GeoFeature> features = getGeoFeatures(ou, displayProperty, relativePeriodDate, userOrgUnit, request, response, includeGroupSets, apiVersion);
    if (features == null) {
        return;
    }
    ContextUtils.setCacheControl(response, GEOFEATURE_CACHE);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    renderService.toJson(response.getOutputStream(), features);
}
Also used : WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) GeoFeature(org.hisp.dhis.webapi.webdomain.GeoFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

GeoFeature (org.hisp.dhis.webapi.webdomain.GeoFeature)3 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 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