← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 754: (GIS) No longer possible to assign n organisation units to 1 polygon.

 

------------------------------------------------------------
revno: 754
committer: Jan Henrik Overland janhenrik.overland@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-09-22 02:35:09 +0200
message:
  (GIS) No longer possible to assign n organisation units to 1 polygon.
added:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapOrganisationUnitRelationByFeatureIdAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapOrganisationUnitRelation.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
  dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapLegendSetAction.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/script/index.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/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2009-09-14 19:02:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2009-09-22 00:35:09 +0000
@@ -248,6 +248,8 @@
      *         OrganisationUnit.
      */
     MapOrganisationUnitRelation getMapOrganisationUnitRelation( Map map, OrganisationUnit organisationUnit );
+    
+    MapOrganisationUnitRelation getMapOrganisationUnitRelationByFeatureId( String featureId );
 
     /**
      * Returns a Collection of MapOrganisationUnitRelations.

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2009-09-14 19:02:15 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2009-09-22 00:35:09 +0000
@@ -400,6 +400,21 @@
     {
         return mappingStore.getMapOrganisationUnitRelation( map, organisationUnit );
     }
+    
+    public MapOrganisationUnitRelation getMapOrganisationUnitRelationByFeatureId( String featureId )
+    {   
+        Collection<MapOrganisationUnitRelation> relations = mappingStore.getAllMapOrganisationUnitRelations();
+        
+        for ( MapOrganisationUnitRelation relation : relations )
+        {
+            if ( relation.getFeatureId().equals( featureId ))
+            {
+                return relation;
+            }
+        }
+        
+        return null;
+    }
 
     public Collection<MapOrganisationUnitRelation> getAllMapOrganisationUnitRelations()
     {

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapLegendSetAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapLegendSetAction.java	2009-09-08 20:33:48 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapLegendSetAction.java	2009-09-22 00:35:09 +0000
@@ -62,7 +62,7 @@
     }
 
     // -------------------------------------------------------------------------
-    // Input
+    // Output
     // -------------------------------------------------------------------------
 
     private MapLegendSet object;

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapOrganisationUnitRelationByFeatureIdAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapOrganisationUnitRelationByFeatureIdAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetMapOrganisationUnitRelationByFeatureIdAction.java	2009-09-22 00:35:09 +0000
@@ -0,0 +1,55 @@
+package org.hisp.dhis.mapping.action;
+
+import org.hisp.dhis.mapping.MapOrganisationUnitRelation;
+import org.hisp.dhis.mapping.MappingService;
+
+import com.opensymphony.xwork2.Action;
+
+public class GetMapOrganisationUnitRelationByFeatureIdAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private MappingService mappingService;
+
+    public void setMappingService( MappingService mappingService )
+    {
+        this.mappingService = mappingService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private String featureId;
+
+    public void setFeatureId( String featureId )
+    {
+        this.featureId = featureId;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private MapOrganisationUnitRelation object;
+
+    public MapOrganisationUnitRelation getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        object = mappingService.getMapOrganisationUnitRelationByFeatureId( featureId );
+        
+        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	2009-09-14 19:02:15 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2009-09-22 00:35:09 +0000
@@ -126,7 +126,14 @@
     scope="prototype">
     <property name="mappingService"
       ref="org.hisp.dhis.mapping.MappingService"/>
-  </bean>	
+  </bean>
+
+  <bean id="org.hisp.dhis.mapping.action.GetMapOrganisationUnitRelationByFeatureIdAction"
+    class="org.hisp.dhis.mapping.action.GetMapOrganisationUnitRelationByFeatureIdAction"
+    scope="prototype">
+    <property name="mappingService"
+      ref="org.hisp.dhis.mapping.MappingService"/>
+  </bean>
   
   <bean id="org.hisp.dhis.mapping.action.GetAvailableMapOrganisationUnitRelationsAction"
     class="org.hisp.dhis.mapping.action.GetAvailableMapOrganisationUnitRelationsAction"

=== 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	2009-09-14 19:02:15 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2009-09-22 00:35:09 +0000
@@ -90,6 +90,10 @@
 	<action name="addOrUpdateMapOrganisationUnitRelations" class="org.hisp.dhis.mapping.action.AddOrUpdateMapOrganisationUnitRelationsAction">
       <result name="success" type="velocity-json">/dhis-web-mapping/void.vm</result>
     </action>
+	  
+	<action name="getMapOrganisationUnitRelationByFeatureId" class="org.hisp.dhis.mapping.action.GetMapOrganisationUnitRelationByFeatureIdAction">
+      <result name="success" type="velocity-json">/dhis-web-mapping/jsonMapOrganisationUnitRelation.vm</result>
+    </action>  
     
     <action name="getAvailableMapOrganisationUnitRelations" class="org.hisp.dhis.mapping.action.GetAvailableMapOrganisationUnitRelationsAction">
       <result name="success" type="velocity-json">/dhis-web-mapping/jsonMapOrganisationUnitRelations.vm</result>

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapOrganisationUnitRelation.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapOrganisationUnitRelation.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonMapOrganisationUnitRelation.vm	2009-09-22 00:35:09 +0000
@@ -0,0 +1,9 @@
+{ "mapOrganisationUnitRelation":
+  [{
+    "id": "$!{object.id}",
+    "map": "$!encoder.jsEncode( ${object.map.mapLayerPath} )",
+    "organisationUnit": "$!encoder.jsEncode( ${object.organisationUnit.name} )",
+    "organisationUnitId": "$!{object.organisationUnit.id}",
+    "featureId": "$!encoder.jsEncode( ${object.featureId} )"
+  }]
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2009-09-21 22:42:56 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2009-09-22 00:35:09 +0000
@@ -2230,9 +2230,9 @@
 			zoomOutButton,
             ' ',
 			zoomMaxExtentButton,
-			' ',' ','-',' ',
+			' ','-',' ',
 			favoritesButton,
-            ' ','-',' ',
+            '-',
             legendSetButton,
 			'->',
 			exitButton
@@ -2501,37 +2501,52 @@
 
 function onClickSelectChoropleth(feature) {
     if (ACTIVEPANEL == 'mapping') {
-        if (!Ext.getCmp('grid_gp').getSelectionModel().getSelected()) {
+		var selected = Ext.getCmp('grid_gp').getSelectionModel().getSelected();
+        if (!selected) {
             Ext.messageRed.msg('Assign organisation units', 'Please select an organisation unit in the list first.');
             return;
         }
-        
-        var selected = Ext.getCmp('grid_gp').getSelectionModel().getSelected();
-        var organisationUnitId = selected.data['organisationUnitId'];
-        var organisationUnit = selected.data['organisationUnit'];
-        
-        var nameColumn = MAPDATA.nameColumn;
-        var mlp = MAPDATA.mapLayerPath;
-        var featureId = feature.attributes[nameColumn];
-        var name = feature.attributes[nameColumn];
-
-        Ext.Ajax.request({
-            url: path + 'addOrUpdateMapOrganisationUnitRelation' + type,
-            method: 'GET',
-            params: { mapLayerPath: mlp, organisationUnitId: organisationUnitId, featureId: featureId },
-
-            success: function( responseObject ) {
-                Ext.messageBlack.msg('Assign organisation units', msg_highlight_start + organisationUnit + msg_highlight_end + ' (database) assigned to ' + msg_highlight_start + name + msg_highlight_end + ' (geojson).');
-                
-                Ext.getCmp('grid_gp').getStore().reload();
-                loadMapData('assignment');
-            },
-            failure: function() {
-                alert( 'Status', 'Error while retrieving data' );
-            } 
-        });
-        
-        popup_feature.hide();
+		
+        var featureId = feature.attributes[MAPDATA.nameColumn];
+		
+		Ext.Ajax.request({
+			url: path + 'getMapOrganisationUnitRelationByFeatureId' + type,
+            method: 'POST',
+			params: {featureId:featureId},
+			
+			success: function( responseObject ) {
+				var mour = Ext.util.JSON.decode( responseObject.responseText ).mapOrganisationUnitRelation[0];
+				var selected;
+				
+				if (mour.featureId == '') {
+					selected = Ext.getCmp('grid_gp').getSelectionModel().getSelected();
+					var organisationUnitId = selected.data.organisationUnitId;
+					var organisationUnit = selected.data.organisationUnit;
+
+					Ext.Ajax.request({
+						url: path + 'addOrUpdateMapOrganisationUnitRelation' + type,
+						method: 'GET',
+						params: { mapLayerPath: MAPDATA.mapLayerPath, organisationUnitId: organisationUnitId, featureId: featureId },
+
+						success: function( responseObject ) {
+							Ext.messageBlack.msg('Assign organisation units', msg_highlight_start + organisationUnit + msg_highlight_end + ' (database) assigned to ' + msg_highlight_start + featureId + msg_highlight_end + ' (geojson).');
+							Ext.getCmp('grid_gp').getStore().reload();
+							popup_feature.hide();
+							loadMapData('assignment');
+						},
+						failure: function() {
+							alert( 'Error: addOrUpdateMapOrganisationUnitRelation' );
+						} 
+					});
+				}
+				else {
+					Ext.messageRed.msg('Assign organisation units', msg_highlight_start + featureId + msg_highlight_end + ' is already assigned.');
+				}
+			},
+			failure: function() {
+				alert('Error: getMapOrganisationUnitRelationByFeatureId');
+			}
+		});
     }
 	else {
 		MAP.setCenter(feature.geometry.getBounds().getCenterLonLat(), MAP.getZoom()+1);