← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21199: Simplified DimensionService.getDimension

 

------------------------------------------------------------
revno: 21199
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-11-26 18:25:40 +0100
message:
  Simplified DimensionService.getDimension
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/dimension/DefaultDimensionService.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	2015-02-18 17:33:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java	2015-11-26 17:25:40 +0000
@@ -37,8 +37,6 @@
  */
 public interface DimensionService
 {
-    DimensionalObject getDimension( String uid );
-    
     DimensionalObject getDimension( String uid, DimensionType dimensionType );
     
     List<NameableObject> getCanReadDimensionItems( String uid );

=== 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	2015-11-25 20:23:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObject.java	2015-11-26 17:25:40 +0000
@@ -47,6 +47,7 @@
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 
 /**
@@ -82,6 +83,12 @@
         PERIOD_DIM_ID, "Period",
         ORGUNIT_DIM_ID, "Organisation unit" );
     
+    Set<Class<? extends IdentifiableObject>> DYNAMIC_DIMENSION_CLASSES = ImmutableSet.<Class<? extends IdentifiableObject>>builder().
+        add( DataElementCategory.class ).
+        add( DataElementGroupSet.class ).
+        add( OrganisationUnitGroupSet.class ).
+        add( CategoryOptionGroupSet.class ).build();
+    
     Map<DimensionType, Class<? extends DimensionalObject>> DYNAMIC_DIMENSION_TYPE_CLASS_MAP = ImmutableMap.<DimensionType, Class<? extends DimensionalObject>>builder().
         put( DimensionType.CATEGORY, DataElementCategory.class ).
         put( DimensionType.DATAELEMENT_GROUPSET, DataElementGroupSet.class ).

=== 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	2015-11-15 20:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2015-11-26 17:25:40 +0000
@@ -127,68 +127,6 @@
     //--------------------------------------------------------------------------
 
     @Override
-    public DimensionalObject getDimension( String uid )
-    {
-        DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid );
-
-        if ( cat != null )
-        {
-            cat.setDimensionType( DimensionType.CATEGORY );
-            return cat;
-        }
-
-        DataElementGroupSet degs = identifiableObjectManager.get( DataElementGroupSet.class, uid );
-
-        if ( degs != null )
-        {
-            degs.setDimensionType( DimensionType.DATAELEMENT_GROUPSET );
-            return degs;
-        }
-
-        OrganisationUnitGroupSet ougs = identifiableObjectManager.get( OrganisationUnitGroupSet.class, uid );
-
-        if ( ougs != null )
-        {
-            ougs.setDimensionType( DimensionType.ORGANISATIONUNIT_GROUPSET );
-            return ougs;
-        }
-
-        CategoryOptionGroupSet cogs = identifiableObjectManager.get( CategoryOptionGroupSet.class, uid );
-
-        if ( cogs != null )
-        {
-            cogs.setDimensionType( DimensionType.CATEGORYOPTION_GROUPSET );
-            return cogs;
-        }
-        
-        TrackedEntityAttribute tea = identifiableObjectManager.get( TrackedEntityAttribute.class, uid );
-        
-        if ( tea != null )
-        {
-            tea.setDimensionType( DimensionType.PROGRAM_ATTRIBUTE );
-            return tea;
-        }
-        
-        DataElement pde = identifiableObjectManager.get( DataElement.class, uid );
-        
-        if ( pde != null && DataElementDomain.TRACKER.equals( pde.getDomainType() ) )
-        {
-            pde.setDimensionType( DimensionType.PROGRAM_DATAELEMENT );
-            return pde;
-        }
-        
-        ProgramIndicator pin = identifiableObjectManager.get( ProgramIndicator.class, uid );
-        
-        if ( pin != null )
-        {
-            pin.setDimensionType( DimensionType.PROGRAM_INDICATOR );
-            return pin;
-        }
-        
-        return null;
-    }
-    
-    @Override
     public DimensionalObject getDimension( String uid, DimensionType dimensionType )
     {
         if ( uid == null || dimensionType == null )
@@ -208,9 +146,9 @@
     
     @Override
     public List<NameableObject> getCanReadDimensionItems( String uid )
-    {
-        DimensionalObject dimension = getDimension( uid );
-
+    {        
+        DimensionalObject dimension = identifiableObjectManager.get( DimensionalObject.DYNAMIC_DIMENSION_CLASSES, uid );
+        
         List<NameableObject> items = new ArrayList<>();
 
         if ( dimension != null && dimension.hasItems() )
@@ -401,7 +339,7 @@
     @Override
     public DimensionalObject getDimensionalObjectCopy( String uid, boolean filterCanRead )
     {
-        DimensionalObject dimension = getDimension( uid );
+        DimensionalObject dimension = identifiableObjectManager.get( DimensionalObject.DYNAMIC_DIMENSION_CLASSES, uid );
         
         BaseDimensionalObject copy = new BaseDimensionalObject();
         copy.mergeWith( dimension, MergeStrategy.MERGE_IF_NOT_NULL );