← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 596: (GIS) Improved error handling for orgunit map linking.

 

------------------------------------------------------------
revno: 596
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Sat 2009-09-05 18:59:16 +0200
message:
  (GIS) Improved error handling for orgunit map linking.
modified:
  dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.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.
=== 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-05 16:19:02 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2009-09-05 16:59:16 +0000
@@ -46,6 +46,8 @@
 import org.hisp.dhis.user.UserSettingService;
 import org.springframework.transaction.annotation.Transactional;
 
+import static org.hisp.dhis.system.util.MathUtils.isNumeric;
+
 /**
  * @author Jan Henrik Overland
  * @version $Id$
@@ -54,9 +56,8 @@
 public class DefaultMappingService
     implements MappingService
 {
-    private static final String PAIR_SEPARATOR = "-";
-
-    private static final String RELATION_SEPARATOR = ",";
+    private static final String RELATION_SEPARATOR = ";;";
+    private static final String PAIR_SEPARATOR = "::";
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -247,15 +248,40 @@
     public void addOrUpdateMapOrganisationUnitRelations( String mapLayerPath, String relations )
     {
         String[] rels = relations.split( RELATION_SEPARATOR );
-
+        
         for ( int i = 0; i < rels.length; i++ )
         {
             String[] rel = rels[i].split( PAIR_SEPARATOR );
 
+            if ( rel.length != 2 )
+            {
+                throw new IllegalArgumentException( "Pair '" + toString( rel ) + "' is invalid for input '" + rels[i] + "'" ); 
+            }
+            
+            if ( !isNumeric( rel[0]) )
+            {
+                throw new IllegalArgumentException( "Organisation unit id '" + rel[0] + "' belonging to feature id '" + rel[1] + "' is not numeric" );                
+            }
+            
             addOrUpdateMapOrganisationUnitRelation( mapLayerPath, Integer.parseInt( rel[0] ), rel[1] );
         }
     }
 
+    /**
+     * Provides a textual representation of the contents of a String array.
+     */
+    private String toString( String[] array )
+    {
+        StringBuffer buffer = new StringBuffer( "{" );
+        
+        for ( int i = 0; i < array.length; i++ )
+        {
+            buffer.append( "[" + array[i] + "]," );
+        }
+        
+        return buffer.append( "}" ).toString();
+    }
+    
     public void addOrUpdateMapOrganisationUnitRelation( String mapLayerPath, int organisationUnitId, String featureId )
     {
         Map map = getMapByMapLayerPath( mapLayerPath );