← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3385: Sentralized method

 

------------------------------------------------------------
revno: 3385
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-04-14 11:05:18 +0200
message:
  Sentralized method
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.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/crosstab/jdbc/CrossTabStore.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java
  dhis-2/dhis-services/dhis-service-datamart-default/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/datavalue/DataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java	2010-05-06 16:05:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java	2011-04-14 09:05:18 +0000
@@ -31,6 +31,7 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -253,7 +254,14 @@
     
     DataValue getLatestDataValues( DataElement dataElement, PeriodType periodType, OrganisationUnit organisationUnit );
     
-    
+    /**
+     * Filters and returns the data element operands which have registered data values
+     * out of the given collection.
+     * 
+     * @param operands the data element operands to filter.
+     * @return the data element operands with registered data values.
+     */
+    Collection<DataElementOperand> getOperandsWithDataValues( Collection<DataElementOperand> operands );    
 }
 
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java	2010-05-06 16:05:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java	2011-04-14 09:05:18 +0000
@@ -31,6 +31,7 @@
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -244,4 +245,13 @@
      */   
     
     DataValue getLatestDataValues( DataElement dataElement, PeriodType periodType, OrganisationUnit organisationUnit );
+    
+    /**
+     * Filters and returns the data element operands which have registered data values
+     * out of the given collection.
+     * 
+     * @param operands the data element operands to filter.
+     * @return the data element operands with registered data values.
+     */
+    Collection<DataElementOperand> getOperandsWithDataValues( Collection<DataElementOperand> operands );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2011-02-17 20:35:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2011-04-14 09:05:18 +0000
@@ -35,6 +35,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -198,5 +199,8 @@
         return true;
     }
 
-    
+    public Collection<DataElementOperand> getOperandsWithDataValues( Collection<DataElementOperand> operands )
+    {
+        return dataValueStore.getOperandsWithDataValues( operands );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java	2010-10-29 12:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java	2011-04-14 09:05:18 +0000
@@ -32,6 +32,7 @@
 import java.util.Collections;
 import java.util.HashSet;
 
+import org.amplecode.quick.StatementHolder;
 import org.amplecode.quick.StatementManager;
 import org.hibernate.Criteria;
 import org.hibernate.Query;
@@ -40,6 +41,7 @@
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -375,4 +377,28 @@
 
         return (DataValue) query.uniqueResult();
     }
+    
+    public Collection<DataElementOperand> getOperandsWithDataValues( Collection<DataElementOperand> operands )
+    {
+        final Collection<DataElementOperand> operandsWithData = new ArrayList<DataElementOperand>();
+        
+        final StatementHolder holder = statementManager.getHolder();
+        
+        for ( DataElementOperand operand : operands )
+        {
+            final String sql = 
+                "SELECT COUNT(*) FROM datavalue " + 
+                "WHERE dataelementid=" + operand.getDataElementId() + " " +
+                "AND categoryoptioncomboid=" + operand.getOptionComboId();
+            
+            Integer count = holder.queryForInteger( sql );
+            
+            if ( count != null && count > 0 )
+            {
+                operandsWithData.add( operand );
+            }
+        }
+        
+        return operandsWithData;
+    }    
 }

=== 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-04-13 16:09:45 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java	2011-04-14 09:05:18 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.datamart.CrossTabDataValue;
 import org.hisp.dhis.datamart.crosstab.jdbc.CrossTabStore;
+import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.jdbc.batchhandler.GenericBatchHandler;
 import org.hisp.dhis.system.util.PaginatedList;
 
@@ -85,6 +86,13 @@
     {
         this.aggregatedDataValueService = aggregatedDataValueService;
     }
+    
+    private DataValueService dataValueService;
+
+    public void setDataValueService( DataValueService dataValueService )
+    {
+        this.dataValueService = dataValueService;
+    }
 
     // -------------------------------------------------------------------------
     // CrossTabService implementation
@@ -92,7 +100,7 @@
 
     public Collection<DataElementOperand> getOperandsWithData( Collection<DataElementOperand> operands )
     {
-        return crossTabStore.getOperandsWithData( operands );
+        return dataValueService.getOperandsWithDataValues( operands );
     }
     
     public List<String> populateCrossTabTable( final Collection<DataElementOperand> operands,

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java	2011-04-13 16:09:45 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java	2011-04-14 09:05:18 +0000
@@ -44,15 +44,6 @@
     final String TABLE_PREFIX_TRIMMED = "datavaluecrosstabtrimmed_";
     
     /**
-     * Filters and returns the DataElementOperands with data from the given
-     * collection of DataElementOperands.
-     * 
-     * @param operands the DataElementOperands.
-     * @return the DataElementOperands with data.
-     */
-    Collection<DataElementOperand> getOperandsWithData( Collection<DataElementOperand> operands );
-    
-    /**
      * Creates a crosstab table where the first column is the period identifier,
      * the second column is the source identifer, and each subsequent column
      * corresponds to an operand.

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java	2011-04-13 16:09:45 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java	2011-04-14 09:05:18 +0000
@@ -63,30 +63,6 @@
     // CrossTabStore implementation
     // -------------------------------------------------------------------------
 
-    public Collection<DataElementOperand> getOperandsWithData( Collection<DataElementOperand> operands )
-    {
-        final Collection<DataElementOperand> operandsWithData = new ArrayList<DataElementOperand>();
-        
-        final StatementHolder holder = statementManager.getHolder();
-        
-        for ( DataElementOperand operand : operands )
-        {
-            final String sql = 
-                "SELECT COUNT(*) FROM datavalue " + 
-                "WHERE dataelementid=" + operand.getDataElementId() + " " +
-                "AND categoryoptioncomboid=" + operand.getOptionComboId();
-            
-            Integer count = holder.queryForInteger( sql );
-            
-            if ( count != null && count > 0 )
-            {
-                operandsWithData.add( operand );
-            }
-        }
-        
-        return operandsWithData;
-    }
-    
     public void createCrossTabTable( final List<DataElementOperand> operands, String key )
     {
         final StatementHolder holder = statementManager.getHolder();

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml	2011-02-03 16:35:12 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml	2011-04-14 09:05:18 +0000
@@ -88,6 +88,8 @@
       ref="org.hisp.dhis.datamart.crosstab.jdbc.CrossTabStore"/>
     <property name="aggregatedDataValueService"
 	  ref="org.hisp.dhis.aggregation.AggregatedDataValueService"/>
+	<property name="dataValueService"
+	  ref="org.hisp.dhis.datavalue.DataValueService"/>
   </bean>
   
   <!-- AggregationCache -->