← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2496: Minor improvement

 

------------------------------------------------------------
revno: 2496
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-01-09 14:02:36 +0100
message:
  Minor improvement
modified:
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.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/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-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java	2011-01-08 16:27:43 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java	2011-01-09 13:02:36 +0000
@@ -40,6 +40,17 @@
 public interface CrossTabService
 {
     String ID = CrossTabService.class.getName();
+
+    /**
+     * Creates, populates and trims the crosstab table.
+     * 
+     * @param operands the collection of DataElementOperands.
+     * @param periodIds the collection of Period identifiers.
+     * @param organisationUnitIds the collection of OrganisationUnit identifiers.
+     * @return the DataElementOperands where data exists.
+     */
+    boolean populateAndTrimCrossTabTable( final Collection<DataElementOperand> operands,
+        final Collection<Integer> periodIds, final Collection<Integer> organisationUnitIds, String key );
     
     /**
      * Creates and populates the crosstab table.

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java	2011-01-08 16:27:43 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java	2011-01-09 13:02:36 +0000
@@ -87,6 +87,16 @@
     // CrossTabService implementation
     // -------------------------------------------------------------------------
 
+    public boolean populateAndTrimCrossTabTable( final Collection<DataElementOperand> operands,
+        final Collection<Integer> periodIds, final Collection<Integer> organisationUnitIds, String key )
+    {
+        Collection<DataElementOperand> operandsWithData = populateCrossTabTable( operands, periodIds, organisationUnitIds, key );
+        
+        trimCrossTabTable( operandsWithData, key );
+        
+        return operandsWithData != null;
+    }
+    
     public Collection<DataElementOperand> populateCrossTabTable( final Collection<DataElementOperand> operands,
         final Collection<Integer> periodIds, final Collection<Integer> organisationUnitIds, String key )
     {
@@ -181,11 +191,14 @@
     {
         // TODO use H2 in-memory table for datavaluecrosstab table ?
 
-        crossTabStore.createTrimmedCrossTabTable( operands, key );
-
-        crossTabStore.dropCrossTabTable( key );
-
-        crossTabStore.renameTrimmedCrossTabTable( key );
+        if ( operands != null && key != null )
+        {
+            crossTabStore.createTrimmedCrossTabTable( operands, key );
+    
+            crossTabStore.dropCrossTabTable( key );
+    
+            crossTabStore.renameTrimmedCrossTabTable( key );
+        }
     }
 
     public Map<DataElementOperand, Integer> getOperandIndexMap( Collection<DataElementOperand> operands, String key )

=== 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-01-08 16:27:43 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java	2011-01-09 13:02:36 +0000
@@ -45,7 +45,6 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
 
 /**
  * @author Lars Helge Overland

=== 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-01-08 16:27:43 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java	2011-01-09 13:02:36 +0000
@@ -281,8 +281,6 @@
             return 0;
         }
 
-        log.info( "Validated crosstab table: " + TimeUtils.getHMS() );
-
         state.setMessage( "crosstabulating_data" );
 
         Collection<Integer> childrenIds = organisationUnitService.getOrganisationUnitHierarchy().getChildren(
@@ -290,20 +288,15 @@
 
         Collection<Integer> intersectingPeriodIds = ConversionUtils.getIdentifiers( Period.class, periodService.getIntersectionPeriods( periods ) );
         
-        final Collection<DataElementOperand> operandsWithData = crossTabService.populateCrossTabTable(
-            allOperands, intersectingPeriodIds, childrenIds, key );
+        boolean valid = crossTabService.populateAndTrimCrossTabTable( allOperands, intersectingPeriodIds, childrenIds, key );
+
+        if ( !valid )
+        {
+            return 0;
+        }
         
         log.info( "Populated crosstab table: " + TimeUtils.getHMS() );
 
-        if ( operandsWithData == null )
-        {
-           return 0;
-        }
-        
-        crossTabService.trimCrossTabTable( operandsWithData, key );
-
-        log.info( "Trimmed crosstab table: " + TimeUtils.getHMS() );
-
         // ---------------------------------------------------------------------
         // Data element export
         // ---------------------------------------------------------------------