← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 994: Improved DimensionService.

 

------------------------------------------------------------
revno: 994
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Sat 2009-11-07 14:27:57 +0100
message:
  Improved DimensionService.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/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-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	2009-11-06 11:58:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java	2009-11-07 13:27:57 +0000
@@ -30,10 +30,8 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
-import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
 
 /**
@@ -75,15 +73,7 @@
     public Collection<DimensionSet> getDataElementDimensionSets()
     {
         Collection<DimensionSet> dimensionSets = new ArrayList<DimensionSet>();
-        
-        for ( DataElement dataElement : dataElementService.getAllDataElements() )
-        {
-            if ( dataElement.isDimensionSet() )
-            {
-                dimensionSets.add( dataElement );
-            }
-        }
-        
+        dimensionSets.addAll( dataElementService.getDataElementsWithGroupSets() );        
         dimensionSets.addAll( categoryService.getAllDataElementCategoryCombos() );
         
         return dimensionSets;
@@ -105,15 +95,7 @@
     public Collection<DimensionSet> getIndicatorDimensionSets()
     {
         Collection<DimensionSet> dimensionSets = new ArrayList<DimensionSet>();
-        
-        for ( DataElement dataElement : dataElementService.getAllDataElements() )
-        {
-            if ( dataElement.isDimensionSet() )
-            {
-                dimensionSets.add( dataElement );
-            }
-        }
-        
+        dimensionSets.addAll( indicatorService.getIndicatorsWithGroupSets() );
         dimensionSets.addAll( categoryService.getAllDataElementCategoryCombos() );
         
         return dimensionSets;
@@ -134,15 +116,10 @@
 
     public Collection<DimensionSet> getAllDimensionSets()
     {
-        Collection<DimensionSet> dimensionSets = getDataElementDimensionSets();
-        
-        for ( Indicator indicator : indicatorService.getAllIndicators() )
-        {
-            if ( indicator.isDimensionSet() )
-            {
-                dimensionSets.add( indicator );
-            }
-        }
+        Collection<DimensionSet> dimensionSets = new ArrayList<DimensionSet>();
+        dimensionSets.addAll( dataElementService.getDataElementsWithGroupSets() ); 
+        dimensionSets.addAll( indicatorService.getIndicatorsWithGroupSets() );
+        dimensionSets.addAll( categoryService.getAllDataElementCategoryCombos() );
         
         return dimensionSets;
     }

=== 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	2009-11-06 12:10:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java	2009-11-07 13:27:57 +0000
@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertTrue;
 
 import java.util.Collection;
@@ -50,7 +50,8 @@
     private DataElementGroupSet dataElementGroupSetA;
     private DataElementGroupSet dataElementGroupSetB;
     
-    private DataElement dataElementA;
+    private DataElement dataElementA;    
+    private DataElement dataElementB;
     
     @Override
     public void setUpTest()
@@ -66,11 +67,13 @@
         dataElementService.addDataElementGroupSet( dataElementGroupSetB );
         
         dataElementA = createDataElement( 'A' );
+        dataElementB = createDataElement( 'B' );
         
         dataElementA.getGroupSets().add( dataElementGroupSetA );
         dataElementA.getGroupSets().add( dataElementGroupSetA );
         
         dataElementService.addDataElement( dataElementA );
+        dataElementService.addDataElement( dataElementB );
     }
     
     @Test
@@ -78,7 +81,7 @@
     {
         Collection<DimensionSet> dimensionSets = dimensionService.getAllDimensionSets();
         
-        assertNotNull( dimensionSets );
         assertTrue( dimensionSets.contains( dataElementA ) );
+        assertFalse( dimensionSets.contains( dataElementB ) );
     }
 }