← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2006: Added missing bean dependency in aggregation service

 

------------------------------------------------------------
revno: 2006
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Fri 2010-06-18 16:38:59 +0200
message:
  Added missing bean dependency in aggregation service
modified:
  dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationServiceTest.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-aggregationengine-default/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/resources/META-INF/dhis/beans.xml	2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/resources/META-INF/dhis/beans.xml	2010-06-18 14:38:59 +0000
@@ -33,6 +33,8 @@
 		ref="org.hisp.dhis.period.PeriodService"/>
 	<property name="aggregationService"
 		ref="org.hisp.dhis.aggregation.AggregationService"/>
+	<property name="organisationUnitService"
+		ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
   </bean>
 	
   <bean id="org.hisp.dhis.aggregation.impl.dataelement.SumIntDataElementAggregation"
@@ -53,12 +55,10 @@
   
   <bean id="org.hisp.dhis.aggregation.impl.dataelement.AverageIntDataElementAggregation"
     class="org.hisp.dhis.aggregation.impl.dataelement.AverageIntDataElementAggregation">
-    <property name="aggregationStore">
-      <ref bean="org.hisp.dhis.aggregation.AggregationStore"/>
-    </property>
-    <property name="aggregationCache">
-      <ref bean="org.hisp.dhis.aggregation.impl.cache.AggregationCache"/>
-    </property>
+    <property name="aggregationStore"
+      ref="org.hisp.dhis.aggregation.AggregationStore"/>
+    <property name="aggregationCache"
+      ref="org.hisp.dhis.aggregation.impl.cache.AggregationCache"/>
   </bean>
   
   <bean id="org.hisp.dhis.aggregation.impl.dataelement.AverageBoolDataElementAggregation"
@@ -76,7 +76,7 @@
 	<property name="categoryService"
 		ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
 	<property name="aggregationCache"
-     ref="org.hisp.dhis.aggregation.impl.cache.AggregationCache"/>    
+        ref="org.hisp.dhis.aggregation.impl.cache.AggregationCache"/>    
   </bean>
   
 </beans>

=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationServiceTest.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationServiceTest.java	2010-06-09 06:19:11 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/test/java/org/hisp/dhis/aggregation/AggregationServiceTest.java	2010-06-18 14:38:59 +0000
@@ -27,16 +27,33 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static junit.framework.Assert.assertEquals;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+
 import org.amplecode.quick.StatementManager;
 import org.hisp.dhis.DhisTest;
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.datamart.DataMartService;
+import org.hisp.dhis.datamart.DataMartStore;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.QuarterlyPeriodType;
 import org.junit.Test;
 
 /**
@@ -46,51 +63,206 @@
 public class AggregationServiceTest
     extends DhisTest
 {
+    private final String T = "true";
+    private final String F = "false";
+    
     private AggregationService aggregationService;
 
-    private StatementManager statementManager;
-
     private DataElementCategoryCombo categoryCombo;
     
     private DataElementCategoryOptionCombo categoryOptionCombo;
+
+    private Collection<Integer> dataElementIds;
+    private Collection<Integer> indicatorIds;
+    private Collection<Integer> periodIds;
+    private Collection<Integer> organisationUnitIds;
+    
+    private DataElement dataElementA;
+    private DataElement dataElementB;
+    
+    private DataSet dataSet;
+    
+    private Period periodA;
+    private Period periodB;
+    private Period periodC;
+    private Period periodD;
+    
+    private OrganisationUnit unitA;
+    private OrganisationUnit unitB;
+    private OrganisationUnit unitC;
+    private OrganisationUnit unitD;
+    private OrganisationUnit unitE;
+    private OrganisationUnit unitF;
+    private OrganisationUnit unitG;
+    private OrganisationUnit unitH;
+    private OrganisationUnit unitI;    
+
+    private Date mar01 = getDate( 2005, 3, 1 );
+    private Date mar31 = getDate( 2005, 3, 31 );
+    private Date apr01 = getDate( 2005, 4, 1 );
+    private Date apr30 = getDate( 2005, 4, 30 );
+    private Date may01 = getDate( 2005, 5, 1 );
+    private Date may31 = getDate( 2005, 5, 31 );
     
     @Override
     public void setUpTest()
-        throws Exception
     {
         aggregationService = (AggregationService) getBean( AggregationService.ID );
-
-        dataValueService = (DataValueService) getBean( DataValueService.ID );
-
-        periodService = (PeriodService) getBean( PeriodService.ID );
-
+        
+        categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
+        
         dataElementService = (DataElementService) getBean( DataElementService.ID );
-
-        categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
-        
-        categoryCombo = categoryService.getDataElementCategoryComboByName( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );             
-        
-        categoryOptionCombo = categoryCombo.getOptionCombos().iterator().next();
         
         indicatorService = (IndicatorService) getBean( IndicatorService.ID );
 
+        dataSetService = (DataSetService) getBean( DataSetService.ID );
+        
+        periodService = (PeriodService) getBean( PeriodService.ID );
+
         organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
+
+        dataValueService = (DataValueService) getBean( DataValueService.ID );
+
+        expressionService = (ExpressionService) getBean( ExpressionService.ID );
+        
+        categoryCombo = categoryService.getDataElementCategoryComboByName( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
+        
+        categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+        
+        // ---------------------------------------------------------------------
+        // Setup identifier Collections
+        // ---------------------------------------------------------------------
+
+        dataElementIds = new HashSet<Integer>();
+        indicatorIds = new HashSet<Integer>();
+        periodIds = new HashSet<Integer>();
+        organisationUnitIds = new HashSet<Integer>();
+        
+        // ---------------------------------------------------------------------
+        // Setup DataElements
+        // ---------------------------------------------------------------------
+
+        dataElementA = createDataElement( 'A', DataElement.VALUE_TYPE_INT, DataElement.AGGREGATION_OPERATOR_SUM, categoryCombo );
+        dataElementB = createDataElement( 'B', DataElement.VALUE_TYPE_BOOL, DataElement.AGGREGATION_OPERATOR_SUM, categoryCombo );
+
+        dataElementIds.add( dataElementService.addDataElement( dataElementA ) );
+        dataElementIds.add( dataElementService.addDataElement( dataElementB ) );
+
+        // ---------------------------------------------------------------------
+        // Setup DataSets (to get correct PeriodType for DataElements)
+        // ---------------------------------------------------------------------
+
+        dataSet = createDataSet( 'A', new MonthlyPeriodType() );
+        dataSet.getDataElements().add( dataElementA );
+        dataSet.getDataElements().add( dataElementB );
+        dataSetService.addDataSet( dataSet );
+        dataElementA.getDataSets().add( dataSet );
+        dataElementB.getDataSets().add( dataSet );
+        dataElementService.updateDataElement( dataElementA );
+        dataElementService.updateDataElement( dataElementB );
+        
+        // ---------------------------------------------------------------------
+        // Setup Periods
+        // ---------------------------------------------------------------------
+        
+        PeriodType monthly = new MonthlyPeriodType();
+        PeriodType quarterly = new QuarterlyPeriodType();
+        
+        periodA = createPeriod( monthly, mar01, mar31 );
+        periodB = createPeriod( monthly, apr01, apr30 );
+        periodC = createPeriod( monthly, may01, may31 );
+        periodD = createPeriod( quarterly, mar01, may31 );
+        
+        periodIds.add( periodService.addPeriod( periodA ) );
+        periodIds.add( periodService.addPeriod( periodB ) );
+        periodIds.add( periodService.addPeriod( periodC ) );
+        periodIds.add( periodService.addPeriod( periodD ) );
+        
+        // ---------------------------------------------------------------------
+        // Setup OrganisationUnits
+        // ---------------------------------------------------------------------
+
+        unitA = createOrganisationUnit( 'A' );
+        unitB = createOrganisationUnit( 'B', unitA );
+        unitC = createOrganisationUnit( 'C', unitA );
+        unitD = createOrganisationUnit( 'D', unitB );
+        unitE = createOrganisationUnit( 'E', unitB );
+        unitF = createOrganisationUnit( 'F', unitB );
+        unitG = createOrganisationUnit( 'G', unitF);
+        unitH = createOrganisationUnit( 'H', unitF );
+        unitI = createOrganisationUnit( 'I' );
+
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitA ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitB ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitC ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitD ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitE ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitF ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitG ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitH ) );
+        organisationUnitIds.add( organisationUnitService.addOrganisationUnit( unitI ) );
+        
+        // ---------------------------------------------------------------------
+        // Setup DataValues
+        // ---------------------------------------------------------------------
+
+        dataValueService.addDataValue( createDataValue( dataElementA, periodA, unitC, "90", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodA, unitD, "10", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodA, unitE, "35", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodA, unitF, "25", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodA, unitG, "20", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodA, unitH, "60", categoryOptionCombo ) );
+        
+        dataValueService.addDataValue( createDataValue( dataElementA, periodB, unitC, "70", categoryOptionCombo ) );        
+        dataValueService.addDataValue( createDataValue( dataElementA, periodB, unitD, "40", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodB, unitE, "65", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodB, unitF, "55", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodB, unitG, "20", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodB, unitH, "15", categoryOptionCombo ) );
+        
+        dataValueService.addDataValue( createDataValue( dataElementA, periodC, unitC, "95", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodC, unitD, "40", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodC, unitE, "45", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodC, unitF, "30", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodC, unitG, "50", categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementA, periodC, unitH, "70", categoryOptionCombo ) );
+        
+        dataValueService.addDataValue( createDataValue( dataElementB, periodA, unitC, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodA, unitD, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodA, unitE, F, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodA, unitF, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodA, unitG, F, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodA, unitH, T, categoryOptionCombo ) );
+        
+        dataValueService.addDataValue( createDataValue( dataElementB, periodB, unitC, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodB, unitD, F, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodB, unitE, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodB, unitF, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodB, unitG, F, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodB, unitH, T, categoryOptionCombo ) );
+        
+        dataValueService.addDataValue( createDataValue( dataElementB, periodC, unitC, F, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodC, unitD, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodC, unitE, F, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodC, unitF, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodC, unitG, T, categoryOptionCombo ) );
+        dataValueService.addDataValue( createDataValue( dataElementB, periodC, unitH, T, categoryOptionCombo ) );
     }
-    
+
     @Override
     public boolean emptyDatabaseAfterTest()
     {
         return true;
     }
 
-    // -------------------------------------------------------------------------
-    // DataElement
-    // -------------------------------------------------------------------------
-
     @Test
-    public void testSumIntDataElementAggregatedValue()
-        throws Exception
+    public void testSumIntDataElementDataMart()
     {
-        //TODO
+        dataElementA.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
+        
+        dataElementService.updateDataElement( dataElementA );
+        
+        assertEquals( 90.0, aggregationService.getAggregatedDataValue( dataElementA, categoryOptionCombo, mar01, mar31, unitC ) );
+        assertEquals( 105.0, aggregationService.getAggregatedDataValue( dataElementA, categoryOptionCombo, mar01, mar31, unitF ) );
     }
 }