← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5168: (GIS) All orgunit group sets now supported in facility layer.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 5168 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-11-15 19:25:52 +0000
message:
  (GIS) All orgunit group sets now supported in facility layer.
added:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonFacilities.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/index.html
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/javascript/index.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js


--
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	2011-11-10 20:57:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-11-15 19:22:58 +0000
@@ -118,6 +118,8 @@
     private transient boolean currentParent;
 
     private transient String type;
+    
+    private transient String[] groupNames;
 
     /**
      * Set of the dynamic attributes values that belong to this
@@ -753,4 +755,14 @@
     {
         this.attributeValues = attributeValues;
     }
+
+    public String[] getGroupNames()
+    {
+        return groupNames;
+    }
+
+    public void setGroupNames( String[] groupNames )
+    {
+        this.groupNames = groupNames;
+    }
 }

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java	2011-11-15 19:22:58 +0000
@@ -0,0 +1,147 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2010, 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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter;
+import org.hisp.dhis.system.filter.OrganisationUnitWithValidPointCoordinateFilter;
+import org.hisp.dhis.system.util.FilterUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetGeoJsonFacilitiesAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer parentId;
+
+    public void setParentId( Integer id )
+    {
+        this.parentId = id;
+    }
+
+    private Integer level;
+
+    public void setLevel( Integer level )
+    {
+        this.level = level;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private Collection<OrganisationUnit> object;
+
+    public Collection<OrganisationUnit> getObject()
+    {
+        return object;
+    }
+    
+    private Collection<OrganisationUnitGroupSet> groupSets;
+
+    public Collection<OrganisationUnitGroupSet> getGroupSets()
+    {
+        return groupSets;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
+
+        level = level == null ? organisationUnitService.getLevelOfOrganisationUnit( parent ) : level;
+
+        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level,
+            parent );
+        
+        FilterUtils.filter( organisationUnits, new OrganisationUnitWithCoordinatesFilter() );
+
+        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidPointCoordinateFilter() );
+        
+        groupSets = organisationUnitGroupService.getAllOrganisationUnitGroupSets();
+        
+        object = new ArrayList<OrganisationUnit>();
+
+        for ( OrganisationUnit unit : organisationUnits )
+        {
+            if ( unit.getFeatureType().equals( OrganisationUnit.FEATURETYPE_POINT ) )
+            {
+                int i = 0;
+                
+                String[] groupNames = new String[groupSets.size()];
+                
+                for ( OrganisationUnitGroupSet groupSet : groupSets )
+                {
+                    groupNames[ i++ ] = unit.getGroupNameInGroupSet( groupSet );
+                }
+                
+                unit.setGroupNames( groupNames );
+                
+                object.add( unit );
+            }
+        }
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2011-11-12 12:54:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2011-11-15 19:22:58 +0000
@@ -306,6 +306,15 @@
             ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
     </bean>
 
+    <bean id="org.hisp.dhis.mapping.action.GetGeoJsonFacilitiesAction"
+        class="org.hisp.dhis.mapping.action.GetGeoJsonFacilitiesAction"
+        scope="prototype">
+        <property name="organisationUnitService"
+            ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+        <property name="organisationUnitGroupService"
+            ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+    </bean>
+
 	<bean id="org.hisp.dhis.mapping.action.GetGeoJsonFromFileAction" class="org.hisp.dhis.mapping.action.GetGeoJsonFromFileAction"
 		scope="prototype">
 		<property name="locationManager" ref="locationManager"/>

=== 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	2011-11-12 12:54:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2011-11-15 19:22:58 +0000
@@ -331,6 +331,11 @@
             <result name="success" type="velocity-json">/dhis-web-mapping/geojson.vm</result>
         </action>
 
+        <action name="getGeoJsonFacilities"
+            class="org.hisp.dhis.mapping.action.GetGeoJsonFacilitiesAction">
+            <result name="success" type="velocity-json">/dhis-web-mapping/geojsonFacilities.vm</result>
+        </action>
+
 		<action name="getGeoJsonFromFile"
             class="org.hisp.dhis.mapping.action.GetGeoJsonFromFileAction">
 			<result name="success" type="stream">

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonFacilities.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonFacilities.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/geojsonFacilities.vm	2011-11-15 19:22:58 +0000
@@ -0,0 +1,1 @@
+#set($size=$object.size()){"type":"FeatureCollection","features":[#foreach($unit in $object){"geometry":{"type":"Point","coordinates":$!encoder.jsonEncode($!{unit.validCoordinates})},"properties":{"id":"$!{unit.id}","name":"$!encoder.jsonEncode(${unit.name})"#foreach($set in $groupSets)#set($n=$velocityCount - 1),"$!encoder.jsonEncode(${set.getName()})":"$!encoder.jsonEncode(${unit.groupNames[$n]})"#end}}#if($velocityCount<$size),#end#end],"crs":{"type":"EPSG","properties":{"code":"4326"}}}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/index.html'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/index.html	2011-10-26 08:39:56 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/index.html	2011-11-15 19:22:58 +0000
@@ -86,8 +86,10 @@
         
         <!-- DHIS -->
         <script type="text/javascript" src="i18n.action"></script>
+<!--
         <script type="text/javascript">window.google = null;</script>
         <script src="http://maps.google.com/maps/api/js?v=3.5&amp;sensor=false";></script>
+-->
         <script type="text/javascript" src="javascript/global.js"></script>
         <script type="text/javascript" src="javascript/index.js"></script>
 </body>

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/javascript/index.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/javascript/index.js	2011-10-26 07:27:42 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/javascript/index.js	2011-11-15 19:22:58 +0000
@@ -253,7 +253,6 @@
         listeners: {
             'load': function(s) {
                 this.isLoaded = true;
-                this.filter('name', 'Type');
             }
         }
     });

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js	2011-08-31 09:58:04 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js	2011-11-15 19:22:58 +0000
@@ -334,7 +334,7 @@
                 'select': {
                     scope: this,
                     fn: function(cb) {
-                        if (cb.currentValue != cb.getValue() && cb.getRawValue() == 'Type') {
+                        if (cb.currentValue != cb.getValue()) {
                             cb.currentValue = cb.getValue();
                             G.stores.groupsByGroupSet.setBaseParam('id', cb.getValue());
                             G.stores.groupsByGroupSet.load({scope: this, callback: function() {
@@ -352,11 +352,6 @@
                                 this.classify(false, true);
                             }});
                         }
-                        else if (cb.getRawValue() != 'Type') {
-                            cb.currentValue = cb.getValue();
-                            this.cmp.group.removeAll();
-                            this.cmp.group.doLayout();
-                        }
                     }
                 }
             }
@@ -480,7 +475,7 @@
                         width: 270,
                         bodyStyle: 'padding:0 0 0 8px;',
                         items: [
-                            { html: '<div class="window-info">' + G.i18n.organisation_unit_level + ' (facility)</div>' },                            
+                            { html: '<div class="window-info">Facility level</div>' },                            
                             {
                                 xtype: 'panel',
                                 layout: 'form',
@@ -503,7 +498,7 @@
         
         var onHoverSelect = function onHoverSelect(feature) {
             if (feature.attributes.name) {
-                document.getElementById('featuredatatext').innerHTML = '<div style="color:black">' + feature.attributes.name + '</div><div style="color:#555">' + feature.attributes.type + '</div>';
+                document.getElementById('featuredatatext').innerHTML = '<div style="color:black">' + feature.attributes.name + '</div><div style="color:#555">' + feature.attributes[scope.cmp.groupSet.getRawValue()] + '</div>';
             }
             else {
                 document.getElementById('featuredatatext').innerHTML = '';
@@ -790,7 +785,7 @@
         G.vars.activeWidget = this;
         this.updateValues = true;
         
-        this.setUrl(G.conf.path_mapping + 'getGeoJson.action?' +
+        this.setUrl(G.conf.path_mapping + 'getGeoJsonFacilities.action?' +
             'parentId=' + this.organisationUnitSelection.parent.id +
             '&level=' + this.organisationUnitSelection.level.level
         );
@@ -811,7 +806,7 @@
     },
 
     applyValues: function() {
-		var options = {indicator: this.cmp.groupSet.getRawValue().toLowerCase()};
+		var options = {indicator: this.cmp.groupSet.getRawValue()};
         
         G.vars.activeWidget = this;
 		this.coreComp.updateOptions(options);