← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5358: WIP org unit groups in data mart

 

------------------------------------------------------------
revno: 5358
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-12-10 19:15:44 +0100
message:
  WIP org unit groups in data mart
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchy.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataElementOperandList.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.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/organisationunit/OrganisationUnitHierarchy.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchy.java	2011-12-10 16:56:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchy.java	2011-12-10 18:15:44 +0000
@@ -105,16 +105,29 @@
 
     public OrganisationUnitHierarchy prepareChildren( OrganisationUnit parent, OrganisationUnitGroup group )
     {
+        if ( group == null )
+        {
+            return prepareChildren( parent );
+        }
+        
         groupSubTrees.put( getKey( parent.getId(), group ), getChildren( parent.getId(), group ) );
         
         return this;
     }
 
-    public OrganisationUnitHierarchy prepareChildren( Collection<OrganisationUnit> parents, OrganisationUnitGroup group )
+    public OrganisationUnitHierarchy prepareChildren( Collection<OrganisationUnit> parents, Collection<OrganisationUnitGroup> groups )
     {
+        if ( groups == null )
+        {
+            return prepareChildren( parents );
+        }
+        
         for ( OrganisationUnit unit : parents )
         {
-            prepareChildren( unit, group );
+            for ( OrganisationUnitGroup group : groups )
+            {
+                prepareChildren( unit, group );
+            }
         }
         
         return this;
@@ -172,6 +185,11 @@
 
     public Set<Integer> getChildren( int parentId, OrganisationUnitGroup group )
     {
+        if ( group == null )
+        {
+            return getChildren( parentId );
+        }
+        
         Set<Integer> children = groupSubTrees.get( getKey( parentId, group ) );
         
         if ( children != null )
@@ -195,6 +213,11 @@
     
     public Set<Integer> getChildren( Collection<Integer> parentIds, Collection<OrganisationUnitGroup> groups )
     {
+        if ( groups == null )
+        {
+            return getChildren( parentIds );
+        }
+        
         Set<Integer> children = new HashSet<Integer>();
         
         for ( Integer id : parentIds )

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java	2011-12-10 16:56:25 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitHierarchyTest.java	2011-12-10 18:15:44 +0000
@@ -49,6 +49,7 @@
     public void testGetGroupChildren()
     {
         OrganisationUnitGroup group = new OrganisationUnitGroup( "Group" );
+        group.setId( 1 );
         
         OrganisationUnit unit2 = new OrganisationUnit( "Unit2" );
         OrganisationUnit unit4 = new OrganisationUnit( "Unit4" );

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataElementOperandList.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataElementOperandList.java	2011-06-06 05:46:14 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataElementOperandList.java	2011-12-10 18:15:44 +0000
@@ -32,6 +32,7 @@
 
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.period.Period;
 
 /**
@@ -48,20 +49,28 @@
     
     private boolean hasValues;
     
+    private int offset;
+    
     public DataElementOperandList( List<DataElementOperand> operands )
     {
         this.operands = operands;
     }
     
-    public void init( Period period, OrganisationUnit unit )
+    public void init( Period period, OrganisationUnit unit, OrganisationUnitGroup group )
     {
         this.hasValues = false;
+        this.offset = group != null ? 3 : 2;
         
         if ( valid() )
         {
-            this.valueList = new Object[operands.size() + 2];
+            this.valueList = new Object[operands.size() + offset];
             this.valueList[0] = period.getId();
             this.valueList[1] = unit.getId();
+            
+            if ( group != null )
+            {
+                this.valueList[2] = group.getId();
+            }
         }
     }
     
@@ -73,7 +82,7 @@
             
             if ( index != -1 && value != null )
             {                
-                this.valueList[index + 2] = value;
+                this.valueList[index + offset] = value;
                 this.hasValues = true;
             }
         }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java	2011-12-06 22:23:13 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java	2011-12-10 18:15:44 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.datamart.DataElementOperandList;
 import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
 import org.hisp.dhis.datamart.aggregation.dataelement.DataElementAggregator;
+import org.hisp.dhis.datamart.engine.DataMartEngine;
 import org.hisp.dhis.jdbc.batchhandler.GenericBatchHandler;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
@@ -153,12 +154,14 @@
         
         final BatchHandler<Object> cacheHandler = inMemoryBatchHandlerFactory.createBatchHandler( GenericBatchHandler.class ).setTableName( AGGREGATEDDATA_CACHE_PREFIX + key ).init();
         
-        final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnits );
+        final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnits, organisationUnitGroups );
 
         final Map<DataElementOperand, Double> valueMap = new HashMap<DataElementOperand, Double>();
         
         final AggregatedDataValue aggregatedValue = new AggregatedDataValue();
         
+        organisationUnitGroups = ( organisationUnitGroups != null ) ? organisationUnitGroups : DataMartEngine.DUMMY_ORG_UNIT_GROUPS;
+        
         for ( final Period period : periods )
         {
             final Collection<DataElementOperand> sumIntOperands = sumIntAggregator.filterOperands( operands, period.getPeriodType() );
@@ -171,11 +174,11 @@
             {
                 for ( final OrganisationUnit unit : organisationUnits )
                 {
-                    operandList.init( period, unit );
+                    operandList.init( period, unit, group );
                     
                     final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
                     
-                    final Collection<Integer> orgUnitChildren = hierarchy.getChildren( unit.getId() );
+                    final Collection<Integer> orgUnitChildren = hierarchy.getChildren( unit.getId(), group );
                     
                     valueMap.clear();                
                     valueMap.putAll( sumIntAggregator.getAggregatedValues( sumIntOperands, period, level, orgUnitChildren, key ) );
@@ -197,7 +200,7 @@
                             aggregatedValue.setPeriodId( period.getId() );
                             aggregatedValue.setPeriodTypeId( period.getPeriodType().getId() );
                             aggregatedValue.setOrganisationUnitId( unit.getId() );
-                            aggregatedValue.setOrganisationUnitGroupId( group.getId() );
+                            aggregatedValue.setOrganisationUnitGroupId( group != null ? group.getId() : 0 );
                             aggregatedValue.setLevel( level );
                             aggregatedValue.setValue( value );
                             

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java	2011-08-13 10:41:20 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DataMartEngine.java	2011-12-10 18:15:44 +0000
@@ -28,14 +28,22 @@
  */
 
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.hisp.dhis.common.ProcessState;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 
 /**
  * @author Lars Helge Overland
  */
 public interface DataMartEngine
 {
+    final Set<OrganisationUnitGroup> DUMMY_ORG_UNIT_GROUPS = new HashSet<OrganisationUnitGroup>()
+    { {
+        add( null );
+    } };
+    
     /**
      * Exports aggregated values to the data mart tables.
      * 

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java	2011-12-06 22:23:13 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java	2011-12-10 18:15:44 +0000
@@ -50,7 +50,6 @@
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.jdbc.batchhandler.AggregatedDataValueBatchHandler;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
@@ -69,12 +68,7 @@
  */
 public class DefaultDataMartEngine
     implements DataMartEngine
-{    
-    private static final Set<OrganisationUnitGroup> DUMMY_ORG_UNIT_GROUPS = new HashSet<OrganisationUnitGroup>()
-    { {
-        add( new OrganisationUnitGroup( "" ) );
-    } };
-    
+{
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -298,7 +292,7 @@
             for ( List<OrganisationUnit> organisationUnitPage : organisationUnitPages )
             {
                 futures.add( dataElementDataMart.exportDataValues( allOperands, periods, organisationUnitPage, 
-                    DUMMY_ORG_UNIT_GROUPS, new DataElementOperandList( indicatorOperands ), AggregatedDataValueBatchHandler.class, key ) );
+                    null, new DataElementOperandList( indicatorOperands ), AggregatedDataValueBatchHandler.class, key ) );
             }
 
             ConcurrentUtils.waitForCompletion( futures );