← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16850: Analytics. Centralized method for getting dimension by dimension type.

 

------------------------------------------------------------
revno: 16850
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-09-29 16:21:33 +0200
message:
  Analytics. Centralized method for getting dimension by dimension type.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.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/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension/DimensionServiceTest.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/DimensionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java	2014-06-25 15:03:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java	2014-09-29 14:21:33 +0000
@@ -39,6 +39,8 @@
 {
     DimensionalObject getDimension( String uid );
     
+    DimensionalObject getDimension( String uid, DimensionType dimensionType );
+    
     List<NameableObject> getCanReadDimensionItems( String uid );
     
     <T extends IdentifiableObject> List<T> getCanReadObjects( List<T> objects );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java	2014-07-13 13:53:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java	2014-09-29 14:21:33 +0000
@@ -29,9 +29,17 @@
  */
 
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementGroupSet;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+
 /**
 * @author Lars Helge Overland
 */
@@ -68,6 +76,15 @@
         PERIOD_DIM_ID, "Period",
         ORGUNIT_DIM_ID, "Organisation unit" );
     
+    final Map<DimensionType, Class<? extends DimensionalObject>> DIMENSION_TYPE_CLASS_MAP = new HashMap<DimensionType, Class<? extends DimensionalObject>>() { {
+        put( DimensionType.CATEGORY, DataElementCategory.class );
+        put( DimensionType.DATAELEMENT_GROUPSET, DataElementGroupSet.class );
+        put( DimensionType.ORGANISATIONUNIT_GROUPSET, OrganisationUnitGroupSet.class );
+        put( DimensionType.CATEGORYOPTION_GROUPSET, CategoryOptionGroupSet.class );
+        put( DimensionType.TRACKED_ENTITY_ATTRIBUTE, TrackedEntityAttribute.class );
+        put( DimensionType.TRACKED_ENTITY_DATAELEMENT, DataElement.class );        
+    } };
+    
     /**
      * Gets the dimension identifier.
      */

=== 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	2014-09-24 13:47:50 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2014-09-29 14:21:33 +0000
@@ -45,6 +45,7 @@
 import org.hisp.dhis.common.BaseDimensionalObject;
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.CombinationGenerator;
+import org.hisp.dhis.common.DimensionService;
 import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.DimensionalObjectUtils;
@@ -172,6 +173,9 @@
 
     @Autowired
     private DataElementOperandService operandService;
+    
+    @Autowired
+    private DimensionService dimensionService;
 
     @Autowired
     private SystemSettingManager systemSettingManager;
@@ -1184,22 +1188,9 @@
 
             if ( !FIXED_DIMS.contains( dimension.getDimension() ) && items.isEmpty() )
             {
-                if ( DimensionType.ORGANISATIONUNIT_GROUPSET.equals( dimension.getDimensionType() ) )
-                {
-                    items = asList( organisationUnitGroupService.getOrganisationUnitGroupSet( dimension.getDimension() ).getOrganisationUnitGroups() );
-                }
-                else if ( DimensionType.DATAELEMENT_GROUPSET.equals( dimension.getDimensionType() ) )
-                {
-                    items = asList( dataElementService.getDataElementGroupSet( dimension.getDimension() ).getMembers() );
-                }
-                else if ( DimensionType.CATEGORYOPTION_GROUPSET.equals( dimension.getDimensionType() ) )
-                {
-                    items = asList( categoryService.getCategoryOptionGroupSet( dimension.getDimension() ).getMembers() );
-                }
-                else if ( DimensionType.CATEGORY.equals( dimension.getDimensionType() ) )
-                {
-                    items = asList( categoryService.getDataElementCategory( dimension.getDimension() ).getCategoryOptions() );
-                }
+                DimensionalObject dynamicDim = dimensionService.getDimension( dimension.getDimension(), dimension.getDimensionType() );
+                
+                items = dynamicDim != null ? dynamicDim.getItems() : items;
             }
 
             // -----------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2014-09-29 14:21:33 +0000
@@ -165,7 +165,17 @@
         
         return null;
     }
-
+    
+    public DimensionalObject getDimension( String uid, DimensionType dimensionType )
+    {
+        if ( uid == null || dimensionType == null )
+        {
+            return null;
+        }
+        
+        return identifiableObjectManager.get( DimensionalObject.DIMENSION_TYPE_CLASS_MAP.get( dimensionType ), uid );
+    }
+    
     public List<NameableObject> getCanReadDimensionItems( String uid )
     {
         DimensionalObject dimension = getDimension( uid );
@@ -294,8 +304,10 @@
         dimensions.addAll( cogs );
         dimensions.addAll( cs );
         
-        return dimensions;        
+        return dimensions;
     }
+    
+    
 
     @Override
     public void mergeAnalyticalObject( BaseAnalyticalObject object )

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension/DimensionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension/DimensionServiceTest.java	2014-03-26 18:14:37 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension/DimensionServiceTest.java	2014-09-29 14:21:33 +0000
@@ -40,6 +40,7 @@
 import org.hisp.dhis.common.BaseDimensionalObject;
 import org.hisp.dhis.common.BaseNameableObject;
 import org.hisp.dhis.common.DimensionService;
+import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
@@ -156,6 +157,14 @@
     }
     
     @Test
+    public void testGetDimensionalObjectByType()
+    {
+        String dim = ouGroupSetA.getUid();
+        
+        assertEquals( ouGroupSetA, dimensionService.getDimension( dim, DimensionType.ORGANISATIONUNIT_GROUPSET ) );
+    }
+    
+    @Test
     public void testMergeAnalyticalObject()
     {
         ReportTable reportTable = new ReportTable();