← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2814: Impl scheduled DataSetCompletenessTask

 

------------------------------------------------------------
revno: 2814
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-02-03 21:15:02 +0100
message:
  Impl scheduled DataSetCompletenessTask
added:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataSetCompletenessTask.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/scheduling/action/ScheduleTasksAction.java
  dhis-2/dhis-web/dhis-web-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/completeness/DataSetCompletenessService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java	2011-02-03 17:03:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/completeness/DataSetCompletenessService.java	2011-02-03 20:15:02 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.external.configuration.NoConfigurationFoundException;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.RelativePeriods;
 
 /**
  * @author Lars Helge Overland
@@ -46,6 +47,14 @@
     /**
      * 
      * @param dataSetIds
+     * @param relatives
+     * @param organisationUnitIds
+     */
+    void exportDataSetCompleteness( Collection<Integer> dataSetIds, RelativePeriods relatives, Collection<Integer> organisationUnitIds );
+    
+    /**
+     * 
+     * @param dataSetIds
      * @param periodIds
      * @param organisationUnitIds
      */

=== 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-02-03 17:03:02 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java	2011-02-03 20:15:02 +0000
@@ -32,6 +32,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
+import java.util.List;
 
 import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;
@@ -52,7 +53,9 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 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.util.ConversionUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -160,6 +163,18 @@
     // -------------------------------------------------------------------------
     // DataSetCompleteness
     // -------------------------------------------------------------------------
+
+    public void exportDataSetCompleteness( Collection<Integer> dataSetIds, RelativePeriods relatives, Collection<Integer> organisationUnitIds )
+    {
+        if ( relatives != null )
+        {
+            List<Period> periods = relatives.getRelativePeriods( 1, null, false );
+            
+            Collection<Integer> periodIds = ConversionUtils.getIdentifiers( Period.class, periodService.reloadPeriods( periods ) );
+            
+            exportDataSetCompleteness( dataSetIds, periodIds, organisationUnitIds );
+        }
+    }
     
     public void exportDataSetCompleteness( Collection<Integer> dataSetIds, 
         Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java	2011-02-03 16:35:12 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java	2011-02-03 20:15:02 +0000
@@ -30,8 +30,6 @@
 import java.util.Collection;
 import java.util.HashSet;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.datamart.DataMartService;
@@ -48,8 +46,6 @@
 public class DataMartTask
     implements Runnable
 {
-    private static final Log log = LogFactory.getLog( DataMartTask.class );
-    
     private DataMartService dataMartService;
  
     private DataElementService dataElementService;
@@ -74,9 +70,7 @@
         Collection<Integer> indicatorIds = ConversionUtils.getIdentifiers( Indicator.class, indicatorService.getAllIndicators() );
         Collection<Integer> organisationUnitIds = ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnitService.getAllOrganisationUnits() );
         
-        RelativePeriods relatives = new RelativePeriods( false, true, true, true, false, false, false );
-        
-        log.info( "Starting scheduled data mart task" );
+        RelativePeriods relatives = new RelativePeriods( false, true, true, true, true, true, true );
         
         dataMartService.export( dataElementIds, indicatorIds, new HashSet<Integer>(), organisationUnitIds, relatives, true );
     }

=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataSetCompletenessTask.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataSetCompletenessTask.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataSetCompletenessTask.java	2011-02-03 20:15:02 +0000
@@ -0,0 +1,70 @@
+package org.hisp.dhis.system.scheduling;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.completeness.DataSetCompletenessService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.RelativePeriods;
+import org.hisp.dhis.system.util.ConversionUtils;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class DataSetCompletenessTask
+    implements Runnable
+{
+    private DataSetCompletenessService completenessService;
+    
+    private DataSetService dataSetService;
+    
+    private OrganisationUnitService organisationUnitService;
+
+    public DataSetCompletenessTask( DataSetCompletenessService completenessService, 
+        DataSetService dataSetService, OrganisationUnitService organisationUnitService )
+    {
+        this.completenessService = completenessService;
+        this.dataSetService = dataSetService;
+        this.organisationUnitService = organisationUnitService;
+    }
+    
+    @Override
+    public void run()
+    {
+        Collection<Integer> dataSetIds = ConversionUtils.getIdentifiers( DataSet.class, dataSetService.getAllDataSets() );
+        Collection<Integer> organisationUnitIds = ConversionUtils.getIdentifiers( OrganisationUnit.class, organisationUnitService.getAllOrganisationUnits() );
+
+        RelativePeriods relatives = new RelativePeriods( false, true, true, true, true, true, true );
+        
+        completenessService.exportDataSetCompleteness( dataSetIds, relatives, organisationUnitIds );        
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/scheduling/action/ScheduleTasksAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/scheduling/action/ScheduleTasksAction.java	2011-02-03 16:35:12 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/scheduling/action/ScheduleTasksAction.java	2011-02-03 20:15:02 +0000
@@ -27,11 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.ServiceProvider;
+import org.hisp.dhis.completeness.DataSetCompletenessService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.datamart.DataMartService;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.system.scheduling.DataMartTask;
+import org.hisp.dhis.system.scheduling.DataSetCompletenessTask;
 import org.hisp.dhis.system.scheduling.Scheduler;
 
 import com.opensymphony.xwork2.Action;
@@ -59,6 +63,13 @@
     {
         this.dataMartService = dataMartService;
     }
+    
+    private ServiceProvider<DataSetCompletenessService> serviceProvider;
+
+    public void setServiceProvider( ServiceProvider<DataSetCompletenessService> serviceProvider )
+    {
+        this.serviceProvider = serviceProvider;
+    }
 
     private DataElementService dataElementService;
 
@@ -80,6 +91,13 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
+    
+    private DataSetService dataSetService;
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
 
     // -------------------------------------------------------------------------
     // Input
@@ -124,20 +142,24 @@
     public String execute()
     {
         DataMartTask dataMartTask = new DataMartTask( dataMartService, dataElementService, indicatorService, organisationUnitService );
- 
+        DataSetCompletenessTask completenessTask = new DataSetCompletenessTask( serviceProvider.provide( "registration" ), dataSetService, organisationUnitService );
+        
         if ( !statusOnly )
         {
             if ( execute )
             {
                 scheduler.executeTask( dataMartTask );
+                scheduler.executeTask( completenessTask );
             }
             else if ( scheduler.getTaskStatus( DataMartTask.class ).equals( Scheduler.STATUS_RUNNING ) )
             {
                 scheduler.stopTask( DataMartTask.class );
+                scheduler.stopTask( DataSetCompletenessTask.class );
             }
             else
             {
-                scheduler.scheduleTask( dataMartTask, Scheduler.CRON_NIGHTLY_1AM );
+                scheduler.scheduleTask( dataMartTask, Scheduler.CRON_NIGHTLY_2AM );
+                scheduler.scheduleTask( completenessTask, Scheduler.CRON_NIGHTLY_1AM );
             }
         }
         

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-02-03 16:35:12 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2011-02-03 20:15:02 +0000
@@ -491,12 +491,16 @@
     <property name="scheduler" ref="scheduler"/>
     <property name="dataMartService"
       ref="org.hisp.dhis.datamart.DataMartService"/>
+    <property name="serviceProvider"
+      ref="dataCompletenessServiceProvider"/>
     <property name="dataElementService"
       ref="org.hisp.dhis.dataelement.DataElementService"/>
     <property name="indicatorService"
       ref="org.hisp.dhis.indicator.IndicatorService"/>
     <property name="organisationUnitService"
       ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+    <property name="dataSetService"
+      ref="org.hisp.dhis.dataset.DataSetService"/>
   </bean>
   
 </beans>