← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9394: WIP

 

------------------------------------------------------------
revno: 9394
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-12-25 19:30:44 +0100
message:
  WIP
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.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/resourcetable/ResourceTableStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2012-12-23 14:38:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2012-12-25 18:30:44 +0000
@@ -44,8 +44,8 @@
     final String TABLE_NAME_CATEGORY_OPTION_COMBO_NAME = "_categoryoptioncomboname";
     final String TABLE_NAME_ORGANISATION_UNIT_STRUCTURE = "_orgunitstructure";
     final String TABLE_NAME_DATA_ELEMENT_STRUCTURE = "_dataelementstructure";
-    final String TABLE_NAME_PERIOD_AGGREGATION_STRUCTURE = "_period_aggregation_structure";
-    final String TABLE_NAME_PERIOD_DISAGGREGATION_STRUCTURE = "_period_disaggregation_structure";
+    final String TABLE_NAME_PERIOD_STRUCTURE = "_periodstructure";
+    final String TABLE_NAME_PERIOD_NO_DISAGGREGATION_STRUCTURE = "_period_no_disagg_structure";
     
     // -------------------------------------------------------------------------
     // OrganisationUnitStructure

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2012-12-23 14:38:42 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2012-12-25 18:30:44 +0000
@@ -443,7 +443,7 @@
     // PeriodTable
     // -------------------------------------------------------------------------
 
-    public void generatePeriodTable( boolean disAggregation )
+    public void generatePeriodTable( boolean noDisaggregation )
     {
         // ---------------------------------------------------------------------
         // Create table
@@ -451,13 +451,13 @@
 
         Collection<Period> periods = periodService.getAllPeriods();
         
-        resourceTableStore.createPeriodStructure( disAggregation );
+        resourceTableStore.createPeriodStructure( noDisaggregation );
         
         // ---------------------------------------------------------------------
         // Populate table
         // ---------------------------------------------------------------------
 
-        String tableName = disAggregation ? TABLE_NAME_PERIOD_DISAGGREGATION_STRUCTURE : TABLE_NAME_PERIOD_AGGREGATION_STRUCTURE;
+        String tableName = noDisaggregation ? TABLE_NAME_PERIOD_NO_DISAGGREGATION_STRUCTURE : TABLE_NAME_PERIOD_STRUCTURE;
         
         BatchHandler<Object> batchHandler = batchHandlerFactory.createBatchHandler( GenericBatchHandler.class ).
             setTableName( tableName ).init();
@@ -465,7 +465,7 @@
         for ( Period period : periods )
         {
             final Date startDate = period.getStartDate();
-            final PeriodType rowPeriodType = period.getPeriodType();
+            final PeriodType rowType = period.getPeriodType();
             
             final List<String> values = new ArrayList<String>();
             
@@ -473,11 +473,7 @@
             
             for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
             {
-                if ( !disAggregation && ( rowPeriodType.getFrequencyOrder() <= periodType.getFrequencyOrder() ) )
-                {
-                    values.add( periodType.createPeriod( startDate ).getIsoDate() );
-                }
-                else if ( disAggregation && ( rowPeriodType.getFrequencyOrder() >= periodType.getFrequencyOrder() ) )
+                if ( rowType.getFrequencyOrder() <= periodType.getFrequencyOrder() || !noDisaggregation )
                 {
                     values.add( periodType.createPeriod( startDate ).getIsoDate() );
                 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2012-12-23 14:38:42 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2012-12-25 18:30:44 +0000
@@ -227,9 +227,9 @@
     // PeriodTable
     // -------------------------------------------------------------------------
 
-    public void createPeriodStructure( boolean disAggregation )
+    public void createPeriodStructure( boolean noDisaggregation )
     {
-        String tableName = disAggregation ? TABLE_NAME_PERIOD_DISAGGREGATION_STRUCTURE : TABLE_NAME_PERIOD_AGGREGATION_STRUCTURE;
+        String tableName = noDisaggregation ? TABLE_NAME_PERIOD_NO_DISAGGREGATION_STRUCTURE : TABLE_NAME_PERIOD_STRUCTURE;
         
         try
         {
@@ -249,8 +249,6 @@
         
         sql += ")";
         
-        log.info( "Create period structure SQL: " + sql );
-        
         jdbcTemplate.update( sql );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2012-12-23 14:38:42 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2012-12-25 18:30:44 +0000
@@ -27,12 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
-import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -59,6 +53,8 @@
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.scheduling.annotation.Async;
 
+import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
+
 /**
  * This class manages the analytics table. The analytics table is a denormalized
  * table designed for analysis which contains raw data values. It has columns for
@@ -160,22 +156,17 @@
     @Async
     public Future<?> populateTableAsync( String tableName, Date startDate, Date endDate )
     {
-        populateTable( tableName, startDate, endDate, "cast(dv.value as double precision)", VALUE_TYPE_INT, AGGREGATION_OPERATOR_SUM );
-        
-        populateTable( tableName, startDate, endDate, "1 as value" , VALUE_TYPE_BOOL, AGGREGATION_OPERATOR_SUM );
-
-        populateTable( tableName, startDate, endDate, "cast(dv.value as double precision)", VALUE_TYPE_INT, AGGREGATION_OPERATOR_AVERAGE );
-        
-        populateTable( tableName, startDate, endDate, "1 as value" , VALUE_TYPE_BOOL, AGGREGATION_OPERATOR_AVERAGE );
+        populateSumTable( tableName, startDate, endDate, "cast(dv.value as double precision)", "int" );
+        
+        populateSumTable( tableName, startDate, endDate, "1 as value" , "bool" );
         
         return null;
     }
     
-    private void populateTable( String tableName, Date startDate, Date endDate, String valueExpression, String valueType, String aggregationType )
+    private void populateSumTable( String tableName, Date startDate, Date endDate, String valueExpression, String valueType )
     {
         final String start = DateUtils.getMediumDateString( startDate );
-        final String end = DateUtils.getMediumDateString( endDate );        
-        final String periodTable = AGGREGATION_OPERATOR_SUM.equals( aggregationType ) ? "_period_aggregation_structure" : "_period_disaggregation_structure";
+        final String end = DateUtils.getMediumDateString( endDate );
         
         String insert = "insert into " + tableName + " (";
         
@@ -200,12 +191,12 @@
             "left join _dataelementgroupsetstructure degs on dv.dataelementid=degs.dataelementid " +
             "left join _organisationunitgroupsetstructure ougs on dv.sourceid=ougs.organisationunitid " +
             "left join _orgunitstructure ous on dv.sourceid=ous.organisationunitid " +
-            "left join " + periodTable + " ps on dv.periodid=ps.periodid " +
+            "left join _period_no_disagg_structure ps on dv.periodid=ps.periodid " +
             "left join dataelement de on dv.dataelementid=de.dataelementid " +
             "left join categoryoptioncombo coc on dv.categoryoptioncomboid=coc.categoryoptioncomboid " +
             "left join period pe on dv.periodid=pe.periodid " +
             "where de.valuetype='" + valueType + "' " +
-            "and de.aggregationtype = '" + aggregationType + "' " +
+            "and de.aggregationtype = 'sum' " +
             "and pe.startdate >= '" + start + "' " +
             "and pe.startdate <= '" + end + "'" +
             "and dv.value != ''" +