← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21430: Impl DimensionService.getDataDimensionalItemObject, now used in expression sevice.

 

------------------------------------------------------------
revno: 21430
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2015-12-12 13:43:41 +0100
message:
  Impl DimensionService.getDataDimensionalItemObject, now used in expression sevice.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.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-12-12 11:49:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java	2015-12-12 12:43:41 +0000
@@ -63,4 +63,14 @@
      * @return a dimensional item object.
      */
     DimensionalItemObject getOrAddDataDimensionalItemObject( String dimensionItem );
+
+    /**
+     * Gets a dimension item object which are among the data dimension item 
+     * objects. The composite dimensional items will be transient and the
+     * associated objects will be persistent.
+     * 
+     * @param dimensionItem the dimension item identifier.
+     * @return a dimensional item object.
+     */
+    DimensionalItemObject getDataDimensionalItemObject( String dimensionItem );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java	2015-11-19 23:23:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java	2015-12-12 12:43:41 +0000
@@ -220,7 +220,9 @@
     ProgramTrackedEntityAttribute getOrAddProgramTrackedEntityAttribute( String programUid, String attributeUid );
     
     /**
-     * Returns a program tracked entity attribute.
+     * Returns a program tracked entity attribute. The program tracked entity
+     * attribute itself will be transient and the associated program and tracked
+     * entity attribute will be persistent.
      * 
      * @param programUid the program identifier.
      * @param attributeUid the tracked entity attribute identifier.

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java	2015-12-12 11:49:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java	2015-12-12 12:43:41 +0000
@@ -385,6 +385,44 @@
         return null;
     }
 
+    @Override
+    public DimensionalItemObject getDataDimensionalItemObject( String dimensionItem )
+    {
+        if ( DimensionalObjectUtils.isCompositeDimensionalObject( dimensionItem ) )
+        {
+            String id0 = splitSafe( dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 0 );
+            String id1 = splitSafe( dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 1 );
+
+            DataElementOperand operand = null;
+            ProgramDataElement programDataElement = null;                    
+            ProgramTrackedEntityAttribute programAttribute = null;
+            
+            if ( ( operand = operandService.getDataElementOperand( id0, id1 ) ) != null )
+            {
+                return operand;
+            }
+            else if ( ( programDataElement = programService.getProgramDataElement( id0, id1 ) ) != null )
+            {
+                return programDataElement;
+            }
+            else if ( ( programAttribute = attributeService.getProgramTrackedEntityAttribute( id0, id1 ) ) != null )
+            {
+                return programAttribute;
+            }
+        }
+        else if ( CodeGenerator.isValidCode( dimensionItem ) )
+        {
+            DimensionalItemObject itemObject = identifiableObjectManager.get( DataDimensionItem.DATA_DIMENSION_CLASSES, dimensionItem );
+            
+            if ( itemObject != null )
+            {
+                return itemObject;
+            }
+        }
+        
+        return null;
+    }
+
     //--------------------------------------------------------------------------
     // Supportive methods
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2015-12-12 11:49:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2015-12-12 12:43:41 +0000
@@ -382,7 +382,7 @@
         {
             String dimensionItem = matcher.group( 2 );
             
-            DimensionalItemObject dimensionItemObject = dimensionService.getOrAddDataDimensionalItemObject( dimensionItem );
+            DimensionalItemObject dimensionItemObject = dimensionService.getDataDimensionalItemObject( dimensionItem );
             
             if ( dimensionItemObject != null )
             {
@@ -489,7 +489,7 @@
         {
             String dimensionItem = matcher.group( 2 );
             
-            if ( dimensionService.getOrAddDataDimensionalItemObject( dimensionItem ) == null )
+            if ( dimensionService.getDataDimensionalItemObject( dimensionItem ) == null )
             {
                 return ExpressionValidationOutcome.DIMENSIONAL_ITEM_OBJECT_DOES_NOT_EXIST;
             }
@@ -579,7 +579,7 @@
         {
             String dimensionItem = matcher.group( 2 );
             
-            DimensionalItemObject dimensionItemObject = dimensionService.getOrAddDataDimensionalItemObject( dimensionItem );
+            DimensionalItemObject dimensionItemObject = dimensionService.getDataDimensionalItemObject( dimensionItem );
             
             if ( dimensionItemObject == null )
             {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2015-11-19 23:23:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2015-12-12 12:43:41 +0000
@@ -349,6 +349,6 @@
             return null;
         }
         
-        return programAttributeStore.get( program, attribute );
+        return new ProgramTrackedEntityAttribute( program, attribute );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java	2015-12-12 11:49:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java	2015-12-12 12:43:41 +0000
@@ -261,7 +261,7 @@
     }
     
     @Test
-    public void testGetDimensionalItemObject()
+    public void testGetOrAddDimensionalItemObject()
     {
         String idA = deA.getUid();
         String idB = prA.getUid() + DimensionalObjectUtils.COMPOSITE_DIM_OBJECT_PLAIN_SEP + deA.getUid();
@@ -273,4 +273,18 @@
         
         assertEquals( deA, dimensionService.getOrAddDataDimensionalItemObject( idA ) );
     }
+
+    @Test
+    public void testGetDimensionalItemObject()
+    {
+        String idA = deA.getUid();
+        String idB = prA.getUid() + DimensionalObjectUtils.COMPOSITE_DIM_OBJECT_PLAIN_SEP + deA.getUid();
+        String idC = prA.getUid() + DimensionalObjectUtils.COMPOSITE_DIM_OBJECT_PLAIN_SEP + atA.getUid();
+        
+        assertNotNull( dimensionService.getDataDimensionalItemObject( idA ) );
+        assertNotNull( dimensionService.getDataDimensionalItemObject( idB ) );
+        assertNotNull( dimensionService.getDataDimensionalItemObject( idC ) );
+        
+        assertEquals( deA, dimensionService.getDataDimensionalItemObject( idA ) );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2015-12-10 12:39:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java	2015-12-12 12:43:41 +0000
@@ -127,6 +127,8 @@
     private ProgramIndicator piA;
     
     private Period period;
+    
+    private Program prA;
 
     private OrganisationUnit unitA;
     private OrganisationUnit unitB;
@@ -215,7 +217,7 @@
         
         period = createPeriod( getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) );
 
-        Program prA = createProgram( 'A' );
+        prA = createProgram( 'A' );
         
         idObjectManager.save( prA );
         
@@ -309,8 +311,8 @@
         assertEquals( 5, items.size() );
         assertTrue( items.contains( opA ) );
         assertTrue( items.contains( deB ) );
-        assertTrue( items.contains( pdeA ) );
-        assertTrue( items.contains( pteaA ) );
+        assertTrue( items.contains( new ProgramDataElement( prA, deA ) ) );
+        assertTrue( items.contains( new ProgramTrackedEntityAttribute( prA, teaA ) ) );
         assertTrue( items.contains( piA ) );
     }
 
@@ -329,8 +331,8 @@
         assertTrue( items.contains( opA ) );
         assertTrue( items.contains( opB ) );
         assertTrue( items.contains( deB ) );
-        assertTrue( items.contains( pdeA ) );
-        assertTrue( items.contains( pteaA ) );
+        assertTrue( items.contains( new ProgramDataElement( prA, deA ) ) );
+        assertTrue( items.contains( new ProgramTrackedEntityAttribute( prA, teaA ) ) );
         assertTrue( items.contains( piA ) );
     }