← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5550: Re-impl support for real-time aggregation in charts

 

------------------------------------------------------------
revno: 5550
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-12-22 18:00:08 +0100
message:
  Re-impl support for real-time aggregation in charts
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/ReportTableManager.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml


--
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/chart/ChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2011-12-22 16:01:28 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2011-12-22 17:00:08 +0000
@@ -27,9 +27,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -38,10 +41,6 @@
 import org.jfree.chart.axis.CategoryLabelPositions;
 import org.jfree.chart.plot.PlotOrientation;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author Lars Helge Overland
  */

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-12-22 16:18:28 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-12-22 17:00:08 +0000
@@ -34,6 +34,8 @@
 import static org.hisp.dhis.chart.Chart.TYPE_PIE;
 import static org.hisp.dhis.chart.Chart.TYPE_STACKED_BAR;
 import static org.hisp.dhis.chart.Chart.TYPE_STACKED_COLUMN;
+import static org.hisp.dhis.options.SystemSettingManager.AGGREGATION_STRATEGY_REAL_TIME;
+import static org.hisp.dhis.options.SystemSettingManager.KEY_AGGREGATION_STRATEGY;
 import static org.hisp.dhis.reporttable.ReportTable.getIdentifier;
 import static org.hisp.dhis.system.util.ConversionUtils.getArray;
 
@@ -48,13 +50,11 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.amplecode.quick.StatementManager;
 import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.SplineInterpolator;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.analysis.UnivariateRealInterpolator;
 import org.apache.commons.math.stat.regression.SimpleRegression;
-import org.hisp.dhis.aggregation.AggregationService;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.chart.ChartGroup;
 import org.hisp.dhis.chart.ChartService;
@@ -177,15 +177,6 @@
         this.reportTableManager = reportTableManager;
     }
 
-    // TODO remove support for aggregation service
-    
-    private AggregationService aggregationService;
-
-    public void setAggregationService( AggregationService aggregationService )
-    {
-        this.aggregationService = aggregationService;
-    }
-
     private SystemSettingManager systemSettingManager;
 
     public void setSystemSettingManager( SystemSettingManager systemSettingManager )
@@ -193,13 +184,6 @@
         this.systemSettingManager = systemSettingManager;
     }
 
-    private StatementManager statementManager;
-
-    public void setStatementManager( StatementManager statementManager )
-    {
-        this.statementManager = statementManager;
-    }
-
     // -------------------------------------------------------------------------
     // ChartService implementation
     // -------------------------------------------------------------------------
@@ -744,7 +728,16 @@
 
     private CategoryDataset[] getCategoryDataSet( Chart chart )
     {
-        Map<String, Double> valueMap = reportTableManager.getAggregatedValueMap( chart );
+        Map<String, Double> valueMap = null;
+        
+        if ( AGGREGATION_STRATEGY_REAL_TIME.equals( systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, AGGREGATION_STRATEGY_REAL_TIME ) ) )
+        {
+            valueMap = reportTableManager.getAggregatedValueMapRealTime( chart ); // Temp fix
+        }
+        else
+        {
+            valueMap = reportTableManager.getAggregatedValueMap( chart );
+        }        
         
         DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
         DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java	2011-11-24 14:36:19 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java	2011-12-22 17:00:08 +0000
@@ -185,7 +185,6 @@
         return pivotTable;
     }
     
-
     public List<Grid> getGrids( PivotTable pivotTable )
     {
         List<Grid> grids = new ArrayList<Grid>();

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java	2011-12-22 16:18:28 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/JDBCReportTableManager.java	2011-12-22 17:00:08 +0000
@@ -32,6 +32,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.amplecode.quick.StatementManager;
+import org.hisp.dhis.aggregation.AggregationService;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
@@ -64,6 +66,20 @@
         this.jdbcTemplate = jdbcTemplate;
     }
 
+    private AggregationService aggregationService;
+
+    public void setAggregationService( AggregationService aggregationService )
+    {
+        this.aggregationService = aggregationService;
+    }
+
+    private StatementManager statementManager;
+
+    public void setStatementManager( StatementManager statementManager )
+    {
+        this.statementManager = statementManager;
+    }
+
     // -------------------------------------------------------------------------
     // ReportTableManager implementation
     // -------------------------------------------------------------------------
@@ -184,7 +200,7 @@
 
     public Map<String, Double> getAggregatedValueMap( Chart chart )
     {
-        // A bit misplaced but we will merge chart and report table soon
+        // A bit misplaced but we will merge chart and report table
 
         Map<String, Double> map = new HashMap<String, Double>();
 
@@ -234,4 +250,54 @@
         
         return map;
     }
+    
+    /**
+     * TODO Temporary fix, we will phase out support for aggregation engine
+     */
+    public Map<String, Double> getAggregatedValueMapRealTime( Chart chart )
+    {
+        statementManager.initialise();
+        
+        Map<String, Double> map = new HashMap<String, Double>();
+
+        if ( chart.hasDataElements() )
+        {
+            for ( DataElement dataElement : chart.getDataElements() )
+            {
+                for ( OrganisationUnit organisationUnit : chart.getOrganisationUnits() )
+                {
+                    for ( Period period : chart.getRelativePeriods() )
+                    {
+                        String id = getIdentifier( getIdentifier( DataElement.class, dataElement.getId() ),
+                            getIdentifier( Period.class, period.getId() ),
+                            getIdentifier( OrganisationUnit.class, organisationUnit.getId() ) );
+
+                        map.put( id, aggregationService.getAggregatedDataValue( dataElement, null, period.getStartDate(), period.getEndDate(), organisationUnit ) );
+                    }
+                }
+            }
+        }
+        
+        if ( chart.hasIndicators() )
+        {
+            for ( Indicator indicator : chart.getIndicators() )
+            {
+                for ( OrganisationUnit organisationUnit : chart.getOrganisationUnits() )
+                {
+                    for ( Period period : chart.getRelativePeriods() )
+                    {
+                        String id = getIdentifier( getIdentifier( Indicator.class, indicator.getId() ),
+                            getIdentifier( Period.class, period.getId() ),
+                            getIdentifier( OrganisationUnit.class, organisationUnit.getId() ) );
+                        
+                        map.put( id, aggregationService.getAggregatedIndicatorValue( indicator, period.getStartDate(), period.getEndDate(), organisationUnit ) );
+                    }
+                }
+            }
+        }
+        
+        statementManager.destroy();
+        
+        return map;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/ReportTableManager.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/ReportTableManager.java	2011-12-21 20:06:49 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/jdbc/ReportTableManager.java	2011-12-22 17:00:08 +0000
@@ -53,4 +53,12 @@
      * @param chart the Chart for which to create the value map.
      */
     Map<String, Double> getAggregatedValueMap( Chart chart );
+
+    /**
+     * Generates a map with a key identifying the dimensions of each value based
+     * on real-time aggregation.
+     * 
+     * @param chart the Chart for which to create the value map.
+     */
+    Map<String, Double> getAggregatedValueMapRealTime( Chart chart );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-12-22 16:18:28 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-12-22 17:00:08 +0000
@@ -15,6 +15,8 @@
 
   <bean id="org.hisp.dhis.reporttable.jdbc.ReportTableManager" class="org.hisp.dhis.reporttable.jdbc.JDBCReportTableManager">
 	<property name="jdbcTemplate" ref="jdbcTemplate" />
+    <property name="aggregationService" ref="org.hisp.dhis.aggregation.AggregationService" />
+	<property name="statementManager" ref="statementManager" />
   </bean>
 
   <bean id="org.hisp.dhis.reporttable.ReportTableStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
@@ -86,9 +88,7 @@
     <property name="minMaxDataElementService" ref="org.hisp.dhis.minmax.MinMaxDataElementService" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 	<property name="reportTableManager" ref="org.hisp.dhis.reporttable.jdbc.ReportTableManager" />
-    <property name="aggregationService" ref="org.hisp.dhis.aggregation.AggregationService" />
     <property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
-	<property name="statementManager" ref="statementManager" />
   </bean>
 
   <!-- Document -->