← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1893: Created action getGeoJson in mapping module

 

------------------------------------------------------------
revno: 1893
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Thu 2010-08-05 14:26:30 +0200
message:
  Created action getGeoJson in mapping module
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml


--
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
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2010-07-30 14:13:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2010-08-05 12:26:30 +0000
@@ -47,8 +47,9 @@
 public class OrganisationUnit
     extends Source implements DimensionOptionElement
 {
+    public static final String FEATURETYPE_NONE = "None";
+        
     private static final Pattern JSON_COORDINATE_PATTERN = Pattern.compile( "(\\[{3}.*?\\]{3})" );
-
     private static final Pattern COORDINATE_PATTERN = Pattern.compile("([\\-0-9.]+,[\\-0-9.]+)");
     
     private Set<OrganisationUnit> children = new HashSet<OrganisationUnit>();
@@ -211,6 +212,19 @@
         this.coordinates = StringUtils.trimToNull( builder.toString() );
     }
     
+    public String getChildrenFeatureType()
+    {
+        for ( OrganisationUnit child : children )
+        {
+            if ( child.getFeatureType() != null )
+            {
+                return child.getFeatureType();
+            }
+        }
+        
+        return FEATURETYPE_NONE;
+    }
+        
     // -------------------------------------------------------------------------
     // hashCode, equals and toString
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java	2010-07-05 14:49:02 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java	2010-08-05 12:26:30 +0000
@@ -107,8 +107,7 @@
 
             Collections.sort( units, organisationUnitComparator );
             
-            displayPropertyHandler.handle( units );
-            
+            displayPropertyHandler.handle( units );            
         }
         
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java	2010-07-10 16:30:22 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitsWithCoordinatesAction.java	2010-08-05 12:26:30 +0000
@@ -27,20 +27,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
+import java.util.Collection;
 
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.Predicate;
-import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
 import com.opensymphony.xwork2.Action;
 
-import java.util.Collections;
-
 /**
  * @author Jan Henrik Overland
  * @version $Id$
@@ -59,38 +52,24 @@
         this.organisationUnitService = organisationUnitService;
     }
 
-    private Comparator<OrganisationUnit> organisationUnitComparator;
-
-    public void setOrganisationUnitComparator( Comparator<OrganisationUnit> organisationUnitComparator )
-    {
-        this.organisationUnitComparator = organisationUnitComparator;
-    }
-
-    private DisplayPropertyHandler displayPropertyHandler;
-
-    public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler )
-    {
-        this.displayPropertyHandler = displayPropertyHandler;
-    }
-
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
 
-    private Integer id;
+    private Integer parentId;
 
-    public void setId( Integer id )
+    public void setParentId( Integer id )
     {
-        this.id = id;
-    }    
+        this.parentId = id;
+    }
     
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
 
-    private List<OrganisationUnit> object;
+    private Collection<OrganisationUnit> object;
 
-    public List<OrganisationUnit> getObject()
+    public Collection<OrganisationUnit> getObject()
     {
         return object;
     }
@@ -102,20 +81,10 @@
     public String execute()
         throws Exception
     {
-        object = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnit( id ).getChildren() );
-        
-        CollectionUtils.filter( object, new Predicate()
-            {
-                public boolean evaluate( Object object )
-                {
-                    return ((OrganisationUnit) object).hasCoordinates();
-                }
-            } );
-
-        Collections.sort( object, organisationUnitComparator );
-        
-        displayPropertyHandler.handle( object );
-        
-        return SUCCESS;
+        OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
+        
+        object = parent.getChildren();
+        
+        return parent.getChildrenFeatureType();
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2010-07-10 20:13:44 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2010-08-05 12:26:30 +0000
@@ -375,10 +375,10 @@
 			</result>
 		</action>
 
-		<!-- Shapefile -->
+		<!-- Shapefile - Remove ? -->
 
 		<action name="getPointShapefile"
-			class="org.hisp.dhis.mapping.action.GetOrganisationUnitsWithCoordinatesAction">
+			class="org.hisp.dhis.mapping.action.GetOrganisationUnitsWithPolygonsAction">
 			<result name="success" type="velocity-json">
 				/dhis-web-mapping/pointShapefile.vm</result>
 		</action>
@@ -391,7 +391,14 @@
 
 		<!-- GeoJson -->
 
-		<action name="getGeoJson" class="org.hisp.dhis.mapping.action.GetGeoJsonAction">
+		<action name="getGeoJson"
+			class="org.hisp.dhis.mapping.action.GetOrganisationUnitsWithCoordinatesAction">
+			<result name="Point" type="velocity-json">/dhis-web-mapping/pointShapefile.vm</result>
+			<result name="Polygon" type="velocity-json">/dhis-web-mapping/polygonShapefile.vm</result>
+			<result name="MultiPolygon" type="velocity-json">/dhis-web-mapping/polygonShapefile.vm</result>
+		</action>
+
+		<action name="getGeoJsonFile" class="org.hisp.dhis.mapping.action.GetGeoJsonAction">
 			<result name="success" type="stream">
 				<param name="contentType">application/json</param>
 				<param name="inputName">inputStream</param>