← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10980: Impl support for retrieving org unit boundary and level in analytics api

 

------------------------------------------------------------
revno: 10980
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-24 13:48:35 +0200
message:
  Impl support for retrieving org unit boundary and level in analytics api
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.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-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java	2013-05-19 18:49:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java	2013-05-24 11:48:35 +0000
@@ -54,7 +54,7 @@
         }
         
         return identifier;
-    }    
+    }
 
     /**
      * Creates a two-dimensional array of dimension items based on the list of

=== 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	2013-05-15 15:15:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2013-05-24 11:48:35 +0000
@@ -75,6 +75,7 @@
 
     public static final String KEY_USER_ORGUNIT = "USER_ORGUNIT";
     public static final String KEY_USER_ORGUNIT_CHILDREN = "USER_ORGUNIT_CHILDREN";
+    public static final String KEY_LEVEL = "LEVEL-";
 
     private static final List<String> FEATURETYPES = Arrays.asList( FEATURETYPE_NONE, FEATURETYPE_MULTIPOLYGON, FEATURETYPE_POLYGON, FEATURETYPE_POINT );
 

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-05-23 16:57:03 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-05-24 11:48:35 +0000
@@ -88,6 +88,7 @@
     
     private static final String DIMENSION_NAME_SEP = ":";
     private static final String OPTION_SEP = ";";
+    private static final String ITEM_SEP = "-";
 
     public static final List<String> DATA_DIMS = Arrays.asList( INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATAELEMENT_OPERAND_ID, DATASET_DIM_ID );
     public static final List<String> FIXED_DIMS = Arrays.asList( DATA_X_DIM_ID, INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PERIOD_DIM_ID, ORGUNIT_DIM_ID );
@@ -710,6 +711,48 @@
     }
     
     /**
+     * Retrieves the level from a level parameter string, which is on the format
+     * LEVEL-<level>-<item> .
+     */
+    public static int getLevelFromLevelParam( String param )
+    {
+        if ( param == null )   
+        {
+            return 0;
+        }
+        
+        String[] split = param.split( ITEM_SEP );
+        
+        if ( split.length > 1 && MathUtils.isInteger( split[1] ) )
+        {
+            return Integer.parseInt( split[1] );
+        }
+        
+        return 0;
+    }
+    
+    /**
+     * Retrieves the boundary dimension item from a level parameter string, which
+     * is on the format LEVEL-<level>-<item> .
+     */
+    public static String getBoundaryFromLevelParam( String param )
+    {
+        if ( param == null )   
+        {
+            return null;
+        }
+        
+        String[] split = param.split( ITEM_SEP );
+        
+        if ( split.length > 2 && split[2] != null )
+        {
+            return split[2];
+        }
+        
+        return null;
+    }
+    
+    /**
      * Splits the given string on the ; character and returns the items in a 
      * list. Returns null if the given string is null.
      */

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-05-23 16:57:03 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-05-24 11:48:35 +0000
@@ -41,14 +41,15 @@
 import static org.hisp.dhis.common.DimensionalObject.DATAELEMENT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.DATASET_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.DATA_X_DIM_ID;
+import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
 import static org.hisp.dhis.common.DimensionalObject.INDICATOR_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
 import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
-import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
 import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.common.NameableObjectUtils.asList;
 import static org.hisp.dhis.common.NameableObjectUtils.asTypedList;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL;
 import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT;
 import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT_CHILDREN;
 import static org.hisp.dhis.reporttable.ReportTable.IRT2D;
@@ -753,6 +754,18 @@
                 {
                     ous.addAll( user.getOrganisationUnit().getSortedChildren() );
                 }
+                else if ( ou != null && ou.startsWith( KEY_LEVEL ) )
+                {
+                    int level = DataQueryParams.getLevelFromLevelParam( ou );
+                    String boundaryId = DataQueryParams.getBoundaryFromLevelParam( ou );
+                    
+                    if ( level > 0 && boundaryId != null )
+                    {
+                        OrganisationUnit boundary = organisationUnitService.getOrganisationUnit( boundaryId );
+                        
+                        ous.addAll( organisationUnitService.getOrganisationUnitsAtLevel( level, boundary ) );
+                    }
+                }
                 else
                 {
                     OrganisationUnit unit = organisationUnitService.getOrganisationUnit( ou );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.java	2013-05-23 13:38:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.java	2013-05-24 11:48:35 +0000
@@ -57,7 +57,7 @@
     }
     
     @Test
-    public void testGetDimensionOptionsFromParam()
+    public void testGetDimensionItemsFromParam()
     {
         List<String> expected = new ArrayList<String>( Arrays.asList( "D348asd782j", "kj78HnH6hgT", "9ds9dS98s2" ) );
         
@@ -65,6 +65,22 @@
     }
     
     @Test
+    public void testGetLevelFromLevelParam()
+    {
+        assertEquals( 4, DataQueryParams.getLevelFromLevelParam( "LEVEL-4-dFsdfejdf2" ) );
+        assertEquals( 0, DataQueryParams.getLevelFromLevelParam( "LEVEL" ) );
+        assertEquals( 0, DataQueryParams.getLevelFromLevelParam( "LEVEL-gFd" ) );        
+    }
+    
+    @Test
+    public void testGetBoundaryFromLevelParam()
+    {
+        assertEquals( "dFsdfejdf2", DataQueryParams.getBoundaryFromLevelParam( "LEVEL-4-dFsdfejdf2" ) );
+        assertEquals( null, DataQueryParams.getBoundaryFromLevelParam( "LEVEL-4-" ) );
+        assertEquals( null, DataQueryParams.getBoundaryFromLevelParam( "LEVEL-4" ) );
+    }
+    
+    @Test
     public void testGetMeasureCriteriaFromParam()
     {
         Map<MeasureFilter, Double> expected = new HashMap<MeasureFilter, Double>();