← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4398: Get root unit null safe.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 4398 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-08-20 13:22:13 +0200
message:
  Get root unit null safe.
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.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-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.java	2011-08-20 10:16:56 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.java	2011-08-20 11:14:22 +0000
@@ -31,6 +31,7 @@
 import static org.hisp.dhis.mapping.MappingService.MAP_DATE_TYPE_FIXED;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -71,9 +72,9 @@
     {
         this.userSettingService = userSettingService;
     }
-    
+
     private ConfigurationService configurationService;
-    
+
     public void setConfigurationService( ConfigurationService configurationService )
     {
         this.configurationService = configurationService;
@@ -85,7 +86,7 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
-    
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -128,21 +129,21 @@
     {
         return overlays;
     }
-    
+
     private DataElementGroup infrastructuralDataElements;
 
     public DataElementGroup getInfrastructuralDataElements()
     {
         return infrastructuralDataElements;
     }
-    
+
     private PeriodType infrastructuralPeriodType;
 
     public PeriodType getInfrastructuralPeriodType()
     {
         return infrastructuralPeriodType;
     }
-    
+
     private OrganisationUnit rootNode;
 
     public OrganisationUnit getRootNode()
@@ -165,23 +166,27 @@
         else
         {
             mapView = mappingService.getMapView( id );
-            
+
             mapDateType = mapView.getMapDateType();
         }
-        
-        baseLayers = new ArrayList<MapLayer>( mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_BASELAYER ) );
-        
+
+        baseLayers = new ArrayList<MapLayer>(
+            mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_BASELAYER ) );
+
         Collections.sort( baseLayers, new MapLayerNameComparator() );
-        
+
         overlays = new ArrayList<MapLayer>( mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_OVERLAY ) );
-        
+
         Collections.sort( overlays, new MapLayerNameComparator() );
 
         infrastructuralDataElements = configurationService.getConfiguration().getInfrastructuralDataElements();
-        
+
         infrastructuralPeriodType = configurationService.getConfiguration().getInfrastructuralPeriodTypeDefaultIfNull();
+
+        Collection<OrganisationUnit> rootUnits = new ArrayList<OrganisationUnit>(
+            organisationUnitService.getOrganisationUnitsAtLevel( 1 ) );
         
-        rootNode = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitsAtLevel( 1 ) ).iterator().next();
+        rootNode = rootUnits.size() > 0 ? rootUnits.iterator().next() : new OrganisationUnit();
 
         return SUCCESS;
     }