← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13943: Web API, impl geoFeatures resource.

 

------------------------------------------------------------
revno: 13943
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-02-05 16:32:56 +0200
message:
  Web API, impl geoFeatures resource.
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/GeoFeatureController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/GeoFeature.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/GeoFeatureController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/GeoFeatureController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/GeoFeatureController.java	2014-02-05 14:32:56 +0000
@@ -0,0 +1,122 @@
+package org.hisp.dhis.api.controller.mapping;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static org.hisp.dhis.util.ContextUtils.clearIfNotModified;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.analytics.AggregationType;
+import org.hisp.dhis.analytics.AnalyticsService;
+import org.hisp.dhis.analytics.DataQueryParams;
+import org.hisp.dhis.api.webdomain.GeoFeature;
+import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.common.NameableObjectUtils;
+import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter;
+import org.hisp.dhis.system.util.FilterUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author Lars Helge Overland
+ */
+@Controller
+@RequestMapping(value = GeoFeatureController.RESOURCE_PATH)
+public class GeoFeatureController
+{
+    public static final String RESOURCE_PATH = "/geoFeatures";
+
+    private static final Map<String, Integer> FEATURE_TYPE_MAP = new HashMap<String, Integer>() { {
+        put( OrganisationUnit.FEATURETYPE_POINT, GeoFeature.TYPE_POINT );
+        put( OrganisationUnit.FEATURETYPE_MULTIPOLYGON, GeoFeature.TYPE_POLYGON );
+        put( OrganisationUnit.FEATURETYPE_POLYGON, GeoFeature.TYPE_POLYGON );
+        put( null, 0 );
+    } };
+    
+    @Autowired
+    private AnalyticsService analyticsService;
+    
+    @RequestMapping( method = RequestMethod.GET, produces = "application/json" )
+    public void getGeoFeatures( @RequestParam String ou, 
+        HttpServletRequest request, HttpServletResponse response ) throws IOException
+    {
+        Set<String> set = new HashSet<String>();
+        set.add( ou );
+        
+        DataQueryParams params = analyticsService.getFromUrl( set, null, AggregationType.SUM, null, false, false, false, false, false, false, null );
+        
+        DimensionalObject dim = params.getDimension( DimensionalObject.ORGUNIT_DIM_ID );
+        
+        List<OrganisationUnit> organisationUnits = NameableObjectUtils.asTypedList( dim.getItems() );
+
+        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidCoordinatesFilter() );
+
+        boolean modified = !clearIfNotModified( request, response, organisationUnits );
+
+        if ( !modified )
+        {
+            return;
+        }
+
+        List<GeoFeature> features = new ArrayList<GeoFeature>();
+        
+        for ( OrganisationUnit unit : organisationUnits )
+        {
+            GeoFeature feature = new GeoFeature();
+            feature.setId( unit.getUid() );
+            feature.setNa( unit.getDisplayName() );
+            feature.setHcd( unit.hasChildrenWithCoordinates() );
+            feature.setHcu( unit.hasCoordinatesUp() );
+            feature.setLe( unit.getLevel() );
+            feature.setPg( unit.getParentGraph() );
+            feature.setPi( unit.getParent() != null ? unit.getParent().getUid() : null );
+            feature.setPn( unit.getParent() != null ? unit.getParent().getDisplayName() : null );
+            feature.setTy( FEATURE_TYPE_MAP.get( unit.getFeatureType() ) );
+            feature.setCo( unit.getCoordinates() );
+            
+            features.add( feature );
+        }
+        
+        JacksonUtils.toJson( response.getOutputStream(), features );
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/GeoFeature.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/GeoFeature.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/GeoFeature.java	2014-02-05 14:32:56 +0000
@@ -0,0 +1,208 @@
+package org.hisp.dhis.api.webdomain;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GeoFeature
+{
+    public static final int TYPE_POINT = 1;
+    public static final int TYPE_POLYGON = 2;
+    
+    /**
+     * Identifier.
+     */
+    private String id;
+    
+    /**
+     * Name.
+     */
+    private String na;
+    
+    /**
+     * Has coordinates down.
+     */
+    private boolean hcd;
+    
+    /**
+     * Has coordinates up.
+     */
+    private boolean hcu;
+    
+    /**
+     * Level.
+     */
+    private int le;
+    
+    /**
+     * Parent graph.
+     */
+    private String pg;
+    
+    /**
+     * Parent identifier.
+     */
+    private String pi;
+    
+    /**
+     * Parent name.
+     */
+    private String pn;
+    
+    /**
+     * Feature type.
+     */
+    private int ty;
+    
+    /**
+     * Coordinates.
+     */
+    private String co;
+
+    public GeoFeature()
+    {
+    }
+
+    //--------------------------------------------------------------------------
+    // Getters and setters
+    //--------------------------------------------------------------------------
+
+    @JsonProperty
+    public String getId()
+    {
+        return id;
+    }
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    @JsonProperty
+    public String getNa()
+    {
+        return na;
+    }
+
+    public void setNa( String na )
+    {
+        this.na = na;
+    }
+
+    @JsonProperty
+    public boolean isHcd()
+    {
+        return hcd;
+    }
+
+    public void setHcd( boolean hcd )
+    {
+        this.hcd = hcd;
+    }
+
+    @JsonProperty
+    public boolean isHcu()
+    {
+        return hcu;
+    }
+
+    public void setHcu( boolean hcu )
+    {
+        this.hcu = hcu;
+    }
+
+    @JsonProperty
+    public int getLe()
+    {
+        return le;
+    }
+
+    public void setLe( int le )
+    {
+        this.le = le;
+    }
+
+    @JsonProperty
+    public String getPg()
+    {
+        return pg;
+    }
+
+    public void setPg( String pg )
+    {
+        this.pg = pg;
+    }
+
+    @JsonProperty
+    public String getPi()
+    {
+        return pi;
+    }
+
+    public void setPi( String pi )
+    {
+        this.pi = pi;
+    }
+
+    @JsonProperty
+    public String getPn()
+    {
+        return pn;
+    }
+
+    public void setPn( String pn )
+    {
+        this.pn = pn;
+    }
+
+    @JsonProperty
+    public int getTy()
+    {
+        return ty;
+    }
+
+    public void setTy( int ty )
+    {
+        this.ty = ty;
+    }
+
+    @JsonProperty
+    public String getCo()
+    {
+        return co;
+    }
+
+    public void setCo( String co )
+    {
+        this.co = co;
+    }
+}