← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2953: Minor change in completeness service function

 

------------------------------------------------------------
revno: 2953
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-03-01 20:32:40 +0100
message:
  Minor change in completeness service function
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.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/completeness/DataSetCompletenessStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java	2011-03-01 17:14:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessStore.java	2011-03-01 19:32:40 +0000
@@ -32,7 +32,6 @@
 
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.source.Source;
 
 /**
  * @author Lars Helge Overland
@@ -42,9 +41,9 @@
 {
     String ID = DataSetCompletenessStore.class.getName();
     
-    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<? extends Source> sources );
+    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources );
     
-    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<? extends Source> sources, Date deadline );
+    int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources, Date deadline );
     
     /**
      * Gets the percentage value for the datasetcompleteness with the given parameters.
@@ -70,11 +69,11 @@
      */
     void deleteDataSetCompleteness();
     
-    int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period );
-    
-    int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline );
-    
-    int getNumberOfValues( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline );
+    int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period );
+    
+    int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period, Date deadline );
+    
+    int getNumberOfValues( DataSet dataSet, Collection<Integer> children, Period period, Date deadline );
     
     void createIndex();
     

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java	2011-03-01 17:14:27 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java	2011-03-01 19:32:40 +0000
@@ -29,6 +29,7 @@
 
 import static org.hisp.dhis.options.SystemSettingManager.DEFAULT_COMPLETENESS_OFFSET;
 import static org.hisp.dhis.options.SystemSettingManager.KEY_COMPLETENESS_OFFSET;
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -53,7 +54,6 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.RelativePeriods;
-import org.hisp.dhis.source.Source;
 import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter;
 import org.hisp.dhis.system.util.ConversionUtils;
 import org.hisp.dhis.system.util.FilterUtils;
@@ -130,11 +130,11 @@
     // Abstract methods
     // -------------------------------------------------------------------------
     
-    public abstract int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period );
-    
-    public abstract int getRegistrationsOnTime( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline );
-    
-    public abstract int getSources( DataSet dataSet, Collection<? extends Source> children );
+    public abstract int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period );
+    
+    public abstract int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline );
+    
+    public abstract int getSources( DataSet dataSet, Collection<Integer> children );
     
     // -------------------------------------------------------------------------
     // DataSetCompleteness
@@ -226,9 +226,9 @@
         int days = (Integer) systemSettingManager.getSystemSetting( KEY_COMPLETENESS_OFFSET, DEFAULT_COMPLETENESS_OFFSET );        
         Date deadline = getDeadline( period, days );
         
-        final Collection<? extends Source> children = organisationUnitService.getOrganisationUnitWithChildren( organisationUnitId );
+        final Collection<Integer> children = getIdentifiers( OrganisationUnit.class, organisationUnitService.getOrganisationUnitWithChildren( organisationUnitId ) );
         
-        final Collection<DataSet> dataSets = dataSetService.getDataSetsBySources( children );
+        final Collection<DataSet> dataSets = dataSetService.getAllDataSets(); // getDataSetsBySources( children ); TODO fix?
         
         final Collection<DataSetCompletenessResult> results = new ArrayList<DataSetCompletenessResult>();
         
@@ -270,11 +270,11 @@
         
         final Collection<DataSetCompletenessResult> results = new ArrayList<DataSetCompletenessResult>();
         
-        Collection<OrganisationUnit> children = null;
+        Collection<Integer> children = null;
         
         for ( final OrganisationUnit unit : units )
         {
-            children = organisationUnitService.getOrganisationUnitWithChildren( unit.getId() );
+            children = getIdentifiers( OrganisationUnit.class, organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ) );
             
             final DataSetCompletenessResult result = new DataSetCompletenessResult();
 
@@ -299,7 +299,7 @@
 
     public DataSetCompletenessResult getDataSetCompleteness( Period period, Date deadline, OrganisationUnit unit, DataSet dataSet )
     {        
-        final Collection<OrganisationUnit> children = organisationUnitService.getOrganisationUnitWithChildren( unit.getId() );
+        final Collection<Integer> children = getIdentifiers( OrganisationUnit.class, organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ) );
         
         final DataSetCompletenessResult result = new DataSetCompletenessResult();
         
@@ -333,6 +333,23 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
+    protected int getSourcesAssociatedWithDataSet( DataSet dataSet, Collection<Integer> sources )
+    {
+        int count = 0;
+
+        Collection<Integer> dataSetSources = getIdentifiers( OrganisationUnit.class, dataSet.getSources() );
+        
+        for ( Integer source : sources )
+        {
+            if ( dataSetSources.contains( source ) ) // TODO simplify?
+            {
+                count++;
+            }
+        }
+
+        return count;
+    }
+
     private Date getDeadline( Period period, int days )
     {
         Calendar cal = Calendar.getInstance();

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java	2010-08-27 07:07:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/CompulsoryDataSetCompletenessService.java	2011-03-01 19:32:40 +0000
@@ -32,7 +32,6 @@
 
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.source.Source;
 
 /**
  * @author Lars Helge Overland
@@ -40,18 +39,18 @@
 public class CompulsoryDataSetCompletenessService
     extends AbstractDataSetCompletenessService
 {    
-    public int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period )
     {
         return completenessStore.getRegistrations( dataSet, children, period );
     }
 
-    public int getRegistrationsOnTime( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline )
+    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
     {
         return completenessStore.getRegistrations( dataSet, children, period, deadline );
     }
     
-    public int getSources( DataSet dataSet, Collection<? extends Source> children )
+    public int getSources( DataSet dataSet, Collection<Integer> children )
     {
-        return dataSetService.getSourcesAssociatedWithDataSet( dataSet, children );
+        return getSourcesAssociatedWithDataSet( dataSet, children );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java	2010-08-27 07:07:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RatioDataSetCompletenessService.java	2011-03-01 19:32:40 +0000
@@ -33,7 +33,6 @@
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.source.Source;
 
 /**
  * @author Lars Helge Overland
@@ -42,17 +41,17 @@
 public class RatioDataSetCompletenessService
     extends AbstractDataSetCompletenessService
 {
-    public int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period )
     {
         return completenessStore.getNumberOfValues( dataSet, children, period, null );
     }
 
-    public int getRegistrationsOnTime( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline )
+    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
     {
         return completenessStore.getNumberOfValues( dataSet, children, period, null );
     }
     
-    public int getSources( DataSet dataSet, Collection<? extends Source> children )
+    public int getSources( DataSet dataSet, Collection<Integer> children )
     {
         Collection<DataElementOperand> operands = dataElementService.getAllGeneratedOperands( dataSet.getDataElements() );
         

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java	2011-03-01 17:14:27 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/RegistrationDataSetCompletenessService.java	2011-03-01 19:32:40 +0000
@@ -32,7 +32,6 @@
 
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.source.Source;
 
 /**
  * @author Lars Helge Overland
@@ -40,18 +39,18 @@
 public class RegistrationDataSetCompletenessService
     extends AbstractDataSetCompletenessService
 {
-    public int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period )
     {
         return completenessStore.getCompleteDataSetRegistrations( dataSet, period, children );
     }
 
-    public int getRegistrationsOnTime( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline )
+    public int getRegistrationsOnTime( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
     {
         return completenessStore.getCompleteDataSetRegistrations( dataSet, period, children, deadline );
     }
     
-    public int getSources( DataSet dataSet, Collection<? extends Source> children )
+    public int getSources( DataSet dataSet, Collection<Integer> children )
     {
-        return dataSetService.getSourcesAssociatedWithDataSet( dataSet, children );
+        return getSourcesAssociatedWithDataSet( dataSet, children );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java	2011-03-01 17:14:27 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/jdbc/JDBCDataSetCompletenessStore.java	2011-03-01 19:32:40 +0000
@@ -27,9 +27,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
 import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
-import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
-import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 
 import java.util.Collection;
 import java.util.Date;
@@ -42,8 +42,6 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.source.Source;
-import org.hisp.dhis.system.util.ConversionUtils;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.TextUtils;
 
@@ -72,9 +70,9 @@
     // -------------------------------------------------------------------------
 
     @SuppressWarnings("unchecked")
-    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<? extends Source> sources )
+    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources )
     {
-        final Collection<? extends Source> intersectingSources = CollectionUtils.intersection( sources, dataSet.getSources() );
+        final Collection<Integer> intersectingSources = CollectionUtils.intersection( sources, getIdentifiers( OrganisationUnit.class, dataSet.getSources() ) );
         
         if ( intersectingSources == null || intersectingSources.size() == 0 )
         {
@@ -86,15 +84,15 @@
             "FROM completedatasetregistration " +
             "WHERE datasetid = " + dataSet.getId() + " " +
             "AND periodid = " + period.getId() + " " +
-            "AND sourceid IN ( " + getCommaDelimitedString( getIdentifiers( OrganisationUnit.class, intersectingSources ) ) + " )";
+            "AND sourceid IN ( " + getCommaDelimitedString( intersectingSources ) + " )";
         
         return statementManager.getHolder().queryForInteger( sql );
     }
 
     @SuppressWarnings("unchecked")
-    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<? extends Source> sources, Date deadline )
+    public int getCompleteDataSetRegistrations( DataSet dataSet, Period period, Collection<Integer> sources, Date deadline )
     {
-        final Collection<? extends Source> intersectingSources = CollectionUtils.intersection( sources, dataSet.getSources() );
+        final Collection<Integer> intersectingSources = CollectionUtils.intersection( sources, getIdentifiers( OrganisationUnit.class, dataSet.getSources() ) );
         
         if ( intersectingSources == null || intersectingSources.size() == 0 )
         {
@@ -106,7 +104,7 @@
             "FROM completedatasetregistration " +
             "WHERE datasetid = " + dataSet.getId() + " " +
             "AND periodid = " + period.getId() + " " +
-            "AND sourceid IN ( " + getCommaDelimitedString( getIdentifiers( OrganisationUnit.class, intersectingSources ) ) + " ) " +
+            "AND sourceid IN ( " + getCommaDelimitedString( intersectingSources ) + " ) " +
             "AND date <= '" + getMediumDateString( deadline ) + "'";
         
         return statementManager.getHolder().queryForInteger( sql );
@@ -142,15 +140,15 @@
         statementManager.getHolder().executeUpdate( sql );
     }
 
-    public int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period )
     {
         return getRegistrations( dataSet, children, period, null );
     }
     
-    public int getRegistrations( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline )
+    public int getRegistrations( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
     {           
         final int compulsoryElements = dataSet.getCompulsoryDataElementOperands().size();        
-        final String childrenIds = TextUtils.getCommaDelimitedString( ConversionUtils.getIdentifiers( Source.class, children ) );
+        final String childrenIds = TextUtils.getCommaDelimitedString( children );
         final String deadlineCriteria = deadline != null ? "AND lastupdated < '" + DateUtils.getMediumDateString( deadline ) + "' " : "";
         
         final String sql = 
@@ -167,9 +165,9 @@
         return statementManager.getHolder().queryForInteger( sql );
     }
     
-    public int getNumberOfValues( DataSet dataSet, Collection<? extends Source> children, Period period, Date deadline )
+    public int getNumberOfValues( DataSet dataSet, Collection<Integer> children, Period period, Date deadline )
     {
-        final String childrenIds = TextUtils.getCommaDelimitedString( ConversionUtils.getIdentifiers( Source.class, children ) );
+        final String childrenIds = TextUtils.getCommaDelimitedString( children );
         final String deadlineCriteria = deadline != null ? "AND lastupdated < '" + DateUtils.getMediumDateString( deadline ) + "' " : "";
         
         final String sql =