← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2521: Impl user interface for datamart scheduling. Its pretty simple at the moment and logging and more...

 

------------------------------------------------------------
revno: 2521
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-01-11 14:11:31 +0100
message:
  Impl user interface for datamart scheduling. Its pretty simple at the moment and logging and more parameters should be added but this is what we will have time for in this release.
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/data_mart_export.png
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/scheduling.png
  dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/GetScheduledExportStatusAction.java
  dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ScheduleExportAction.java
  dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/index.vm
  dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewScheduledExport.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartScheduler.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.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/engine/DefaultDataMartEngine.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/DataMartTask.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/SpringDataMartScheduler.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties
  dhis-2/dhis-web/dhis-web-datamart/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/menu.vm
  dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm


--
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/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-01-06 09:03:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-01-11 13:11:31 +0000
@@ -149,6 +149,14 @@
     }
     
     /**
+     * Gets a list of Periods relative to current date.
+     */
+    public List<Period> getRelativePeriods()
+    {
+        return getRelativePeriods( 1, null, null, false );
+    }
+    
+    /**
      * Gets a list of Periods based on the given input and the state of this RelativePeriods.
      * 
      * @param months the number of months back in time representing the current month.
@@ -164,8 +172,8 @@
      * Gets a list of Periods based on the given input and the state of this RelativePeriods.
      * 
      * @param months the number of months back in time representing the current reporting month.
-     * @param format the i18n format.
      * @param date the date representing now (for testing purposes).
+     * @param format the i18n format.
      * @return a list of relative Periods.
      */
     protected List<Period> getRelativePeriods( int months, Date date, I18nFormat format, boolean dynamicNames )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java	2009-12-24 08:55:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/GapAnalysisService.java	2011-01-11 13:11:31 +0000
@@ -74,6 +74,8 @@
         
         for ( DataElement dataElement : dataElements )
         {
+            // TODO filter periods with data element period type
+            
             if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
             {                    
                 Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo().getOptionCombos();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java	2010-04-07 12:27:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java	2011-01-11 13:11:31 +0000
@@ -78,6 +78,8 @@
 
         for ( DataElement dataElement : dataElements )
         {
+            // TODO filter periods with data element period type
+            
             if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
             {
                 Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo()
@@ -106,8 +108,7 @@
     {
         Double stdDev = dataAnalysisStore.getStandardDeviation( dataElement, categoryOptionCombo, organisationUnit );
 
-        if ( !isEqual( stdDev, 0.0 ) ) // No values found or no outliers exist
-        // when 0.0
+        if ( !isEqual( stdDev, 0.0 ) ) // No values found or no outliers exist when 0.0
         {
             Double avg = dataAnalysisStore.getAverage( dataElement, categoryOptionCombo, organisationUnit );
 

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartScheduler.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartScheduler.java	2011-01-07 16:43:23 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartScheduler.java	2011-01-11 13:11:31 +0000
@@ -39,9 +39,9 @@
     final String STATUS_STOPPED  = "stopped";
     final String STATUS_NOT_STARTED = "not_started";
 
-    public void scheduleDataMartExport( int id );
-    
-    boolean stopDataMartExport( int id );
-    
-    String getDataMartExportStatus( int id );
+    public void scheduleDataMartExport();
+    
+    boolean stopDataMartExport();
+    
+    String getDataMartExportStatus();
 }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java	2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java	2011-01-11 13:11:31 +0000
@@ -47,6 +47,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.springframework.util.CollectionUtils;
 
 /**
  * @author Lars Helge Overland
@@ -79,7 +80,7 @@
     public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands, 
         final Period period, final OrganisationUnit unit, int unitLevel, final OrganisationUnitHierarchy hierarchy, List<String> keys )
     {
-        if ( operands == null || operands.size() == 0 )
+        if ( CollectionUtils.isEmpty( operands ) )
         {
             return new HashMap<DataElementOperand, Double>();
         }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java	2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java	2011-01-11 13:11:31 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.springframework.util.CollectionUtils;
 
 /**
  * @author Lars Helge Overland
@@ -83,7 +84,7 @@
     public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands, 
         final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
     {
-        if ( operands == null || operands.size() == 0 )
+        if ( CollectionUtils.isEmpty( operands ) )
         {
             return new HashMap<DataElementOperand, Double>();
         }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java	2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java	2011-01-11 13:11:31 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.springframework.util.CollectionUtils;
 
 /**
  * @author Lars Helge Overland
@@ -83,7 +84,7 @@
     public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands, 
         final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
     {
-        if ( operands == null || operands.size() == 0 )
+        if ( CollectionUtils.isEmpty( operands ) )
         {
             return new HashMap<DataElementOperand, Double>();
         }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java	2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java	2011-01-11 13:11:31 +0000
@@ -48,6 +48,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.springframework.util.CollectionUtils;
 
 /**
  * @author Lars Helge Overland
@@ -80,7 +81,7 @@
     public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands, 
         final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
     {
-        if ( operands == null || operands.size() == 0 )
+        if ( CollectionUtils.isEmpty( operands ) )
         {
             return new HashMap<DataElementOperand, Double>();
         }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java	2011-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java	2011-01-11 13:11:31 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.springframework.util.CollectionUtils;
 
 /**
  * @author Lars Helge Overland
@@ -83,7 +84,7 @@
     public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands, 
         final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, List<String> keys )
     {
-        if ( operands == null || operands.size() == 0 )
+        if ( CollectionUtils.isEmpty( operands ) )
         {
             return new HashMap<DataElementOperand, Double>();
         }

=== 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-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java	2011-01-11 13:11:31 +0000
@@ -136,11 +136,8 @@
     
                             if ( value != null && value.length() > MAX_LENGTH )
                             {
-                                log.warn( "Value ignored, too long: '" + value + "', for dataelement: '"
-                                    + operand.getDataElementId() + "', categoryoptioncombo: '"
-                                    + operand.getOptionComboId() + "', period: '" + periodId + "', source: '"
-                                    + sourceId + "'" );
-    
+                                log.warn( "Value ignored, too long: '" + value + "'" );
+                                
                                 value = null;
                             }
     
@@ -159,8 +156,6 @@
                             batchHandler.addObject( valueList );
                         }
                     }
-    
-                    log.debug( "Crosstabulated data for period " + periodId );
                 }
     
                 batchHandler.flush();

=== 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-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java	2011-01-11 13:11:31 +0000
@@ -248,7 +248,7 @@
         allOperands.addAll( indicatorOperands );
         allOperands.addAll( calculatedOperands );
 
-        log.info( "Filtered data elements: " + TimeUtils.getHMS() );
+        log.info( "Filtered data elements, number of operands: " + allOperands.size() + ", " + TimeUtils.getHMS() );
 
         // ---------------------------------------------------------------------
         // Create and trim crosstabtable
@@ -266,7 +266,7 @@
             return 0;
         }
 
-        log.info( "Number of crosstab tables: " + keys.size() + " " + TimeUtils.getHMS() );
+        log.info( "Number of crosstab tables: " + keys.size() + ", number of operands with data: " + allOperands.size() + ", " + TimeUtils.getHMS() );
 
         // ---------------------------------------------------------------------
         // Remove operands without data

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2010-12-07 08:30:02 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java	2011-01-11 13:11:31 +0000
@@ -81,13 +81,6 @@
     // -------------------------------------------------------------------------
 
     @Transactional
-    public int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
-        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
-    {
-        return export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, null );
-    }
-    
-    @Transactional
     public int export( int id )
     {
         DataMartExport dataMartExport = getDataMartExport( id );
@@ -96,7 +89,7 @@
         
         if ( dataMartExport.getRelatives() != null )
         {
-            allPeriods.addAll( periodService.reloadPeriods( dataMartExport.getRelatives().getRelativePeriods( 1, null, false ) ) );
+            allPeriods.addAll( periodService.reloadPeriods( dataMartExport.getRelatives().getRelativePeriods() ) );
         }
         
         return dataMartEngine.export( 
@@ -106,6 +99,13 @@
             getIdentifiers( OrganisationUnit.class, dataMartExport.getOrganisationUnits() ), 
             new OutputHolderState() );
     }
+
+    @Transactional
+    public int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
+        Collection<Integer> periodIds, Collection<Integer> organisationUnitIds )
+    {
+        return export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, null );
+    }
     
     @Transactional
     public int export( Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/DataMartTask.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/DataMartTask.java	2011-01-07 16:43:23 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/DataMartTask.java	2011-01-11 13:11:31 +0000
@@ -27,7 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+import java.util.HashSet;
+
 import org.hisp.dhis.datamart.DataMartService;
+import org.hisp.dhis.period.RelativePeriods;
 
 /**
  * @author Lars Helge Overland
@@ -36,18 +40,25 @@
     implements Runnable
 {
     private DataMartService dataMartService;
-    
-    private int id;
  
-    public DataMartTask( DataMartService dataMartService, int id )
+    private Collection<Integer> dataElementIds;
+    private Collection<Integer> indicatorIds;
+    private Collection<Integer> organisationUnitIds;
+    private RelativePeriods relatives;
+    
+    public DataMartTask( DataMartService dataMartService, Collection<Integer> dataElementIds, Collection<Integer> indicatorIds,
+        Collection<Integer> organisationUnitIds, RelativePeriods relatives )
     {
         this.dataMartService = dataMartService;
-        this.id = id;
+        this.dataElementIds = dataElementIds;
+        this.indicatorIds = indicatorIds;
+        this.organisationUnitIds = organisationUnitIds;
+        this.relatives = relatives;
     }
     
     @Override
     public void run()
     {
-        dataMartService.export( id );
+        dataMartService.export( dataElementIds, indicatorIds, new HashSet<Integer>(), organisationUnitIds, relatives );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/SpringDataMartScheduler.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/SpringDataMartScheduler.java	2011-01-07 16:43:23 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/task/SpringDataMartScheduler.java	2011-01-11 13:11:31 +0000
@@ -27,12 +27,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Collection;
 import java.util.concurrent.ScheduledFuture;
 
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.datamart.DataMartScheduler;
 import org.hisp.dhis.datamart.DataMartService;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorService;
+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;
 import org.springframework.scheduling.TaskScheduler;
 import org.springframework.scheduling.support.CronTrigger;
 
@@ -42,7 +49,7 @@
 public class SpringDataMartScheduler
     implements DataMartScheduler
 {
-    private Map<Integer, ScheduledFuture<?>> scheduledFutureMap = new HashMap<Integer, ScheduledFuture<?>>(); // Gives class state but no better way to handle this?
+    private ScheduledFuture<?> scheduledFuture = null; // Gives class state but no better way to handle this?
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -62,37 +69,60 @@
         this.taskScheduler = taskScheduler;
     }
 
+    private DataElementService dataElementService;
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+    private IndicatorService indicatorService;
+
+    public void setIndicatorService( IndicatorService indicatorService )
+    {
+        this.indicatorService = indicatorService;
+    }
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
     // -------------------------------------------------------------------------
     // DataMartSceduler implementation
     // -------------------------------------------------------------------------
 
-    public void scheduleDataMartExport( int id )
-    {
-        ScheduledFuture<?> future = taskScheduler.schedule( new DataMartTask( dataMartService, id ), new CronTrigger( CRON_NIGHTLY ) );
-        
-        scheduledFutureMap.put( id, future );
-    }
-    
-    public boolean stopDataMartExport( int id )
-    {
-        ScheduledFuture<?> future = scheduledFutureMap.get( id );
-        
-        return future.cancel( true );
-    }
-    
-    public String getDataMartExportStatus( int id )
-    {
-        ScheduledFuture<?> future = scheduledFutureMap.get( id );
-        
-        if ( future == null )
+    public void scheduleDataMartExport()
+    {
+        Collection<Integer> dataElementIds = ConversionUtils.getIdentifiers( DataElement.class, dataElementService.getAllDataElements() );
+        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 );
+        
+        DataMartTask task = new DataMartTask( dataMartService, dataElementIds, indicatorIds, organisationUnitIds, relatives );
+        
+        scheduledFuture = taskScheduler.schedule( task, new CronTrigger( CRON_NIGHTLY ) );        
+    }
+    
+    public boolean stopDataMartExport()
+    {
+        return scheduledFuture != null ? scheduledFuture.cancel( true ) : false;
+    }
+    
+    public String getDataMartExportStatus()
+    {
+        if ( scheduledFuture == null )
         {
             return STATUS_NOT_STARTED;
         }
-        else if ( future.isCancelled() )
+        else if ( scheduledFuture.isCancelled() )
         {
             return STATUS_STOPPED;
         }
-        else if ( future.isDone() )
+        else if ( scheduledFuture.isDone() )
         {
             return STATUS_DONE;
         }

=== 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-01-10 15:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml	2011-01-11 13:11:31 +0000
@@ -191,12 +191,20 @@
 	<property name="batchHandlerFactory" ref="batchHandlerFactory"/>
   </bean>
   
+  <!-- Scheduler -->
+  
   <bean id="org.hisp.dhis.datamart.DataMartScheduler"
     class="org.hisp.dhis.datamart.task.SpringDataMartScheduler">
     <property name="dataMartService"
       ref="org.hisp.dhis.datamart.DataMartService"/>
     <property name="taskScheduler" 
     	ref="taskScheduler"/>
+    <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"/>
   </bean>
   
   <!-- DeletionHandler -->

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/data_mart_export.png'
Binary files dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/data_mart_export.png	1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/data_mart_export.png	2011-01-11 13:11:31 +0000 differ
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/scheduling.png'
Binary files dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/scheduling.png	1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/icons/scheduling.png	2011-01-11 13:11:31 +0000 differ
=== added file 'dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/GetScheduledExportStatusAction.java'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/GetScheduledExportStatusAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/GetScheduledExportStatusAction.java	2011-01-11 13:11:31 +0000
@@ -0,0 +1,86 @@
+package org.hisp.dhis.datamart.action;
+
+/*
+ * 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 static org.hisp.dhis.datamart.DataMartScheduler.STATUS_RUNNING;
+
+import org.hisp.dhis.datamart.DataMartScheduler;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GetScheduledExportStatusAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private DataMartScheduler dataMartScheduler;
+
+    public void setDataMartScheduler( DataMartScheduler dataMartScheduler )
+    {
+        this.dataMartScheduler = dataMartScheduler;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private String status;
+
+    public String getStatus()
+    {
+        return status;
+    }
+
+    private boolean running;
+    
+    public boolean isRunning()
+    {
+        return running;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+    {
+        String status_ = dataMartScheduler.getDataMartExportStatus();
+        
+        status = status_; 
+        
+        running = status_.equals( STATUS_RUNNING );
+        
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ScheduleExportAction.java'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ScheduleExportAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ScheduleExportAction.java	2011-01-11 13:11:31 +0000
@@ -0,0 +1,71 @@
+package org.hisp.dhis.datamart.action;
+
+/*
+ * 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 static org.hisp.dhis.datamart.DataMartScheduler.STATUS_RUNNING;
+
+import org.hisp.dhis.datamart.DataMartScheduler;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class ScheduleExportAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private DataMartScheduler dataMartScheduler;
+
+    public void setDataMartScheduler( DataMartScheduler dataMartScheduler )
+    {
+        this.dataMartScheduler = dataMartScheduler;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+    {
+        if ( dataMartScheduler.getDataMartExportStatus().equals( STATUS_RUNNING ) )
+        {
+            dataMartScheduler.stopDataMartExport();
+        }
+        else
+        {
+            dataMartScheduler.scheduleDataMartExport();
+        }
+        
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml	2010-06-24 11:50:08 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml	2011-01-11 13:11:31 +0000
@@ -100,4 +100,20 @@
       ref="org.hisp.dhis.datamart.DataMartService"/>
   </bean>
   
+  <!-- Schedule -->
+  
+  <bean id="org.hisp.dhis.datamart.action.GetScheduledExportStatusAction"
+    class="org.hisp.dhis.datamart.action.GetScheduledExportStatusAction"
+    scope="prototype">
+    <property name="dataMartScheduler"
+      ref="org.hisp.dhis.datamart.DataMartScheduler"/>
+  </bean>
+  
+  <bean id="org.hisp.dhis.datamart.action.ScheduleExportAction"
+    class="org.hisp.dhis.datamart.action.ScheduleExportAction"
+    scope="prototype">
+    <property name="dataMartScheduler"
+      ref="org.hisp.dhis.datamart.DataMartScheduler"/>
+  </bean>
+  
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties	2011-01-06 09:03:29 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties	2011-01-11 13:11:31 +0000
@@ -46,7 +46,7 @@
 export_process_not_initialized= Export process not initalized
 datamart_intro= Please select an item from the menu.
 export_saved= Export saved
-data_mart_management= Data mart management
+data_mart_export_management = Data mart export management
 confirm_delete_data_mart_export= Are you sure you want to delete datamart export?
 number_of_data_elements= Number of data elements
 number_of_indicators= Number of indicators
@@ -73,4 +73,18 @@
 quarters_last_year = Quarters last year
 last_year = Last year
 prev = Prev
-next = Next
\ No newline at end of file
+next = Next
+scheduled_export_is = Scheduled export is
+running = running
+done = done
+stopped = stopped
+not_started = not started
+refresh = Refresh
+data_mart_export = Data Mart Export
+data_mart_scheduling = Data Mart Scheduling
+data_mart_scheduling_management = Data mart scheduling management
+start = Start
+stop = Stop
+refresh = Refresh
+intro_data_mart_export = Create data mart exports. Data mart exports contains data elements, indicators, organisation units and periods.
+intro_data_mart_scheduling = Set up and manage scheduled data mart exports, which will run at 2 AM every night for all data elements, indicators, organisation units and periods for this year.
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/resources/struts.xml	2010-12-07 08:30:02 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/resources/struts.xml	2011-01-11 13:11:31 +0000
@@ -11,8 +11,10 @@
     <!-- DataMart -->
     
     <action name="index" class="org.hisp.dhis.datamart.action.NoAction">
-      <result name="success" type="redirect">getDataMartExports.action</result>
-    </action>	
+      <result name="success" type="velocity">/main.vm</result>
+      <param name="page">/dhis-web-datamart/index.vm</param>
+      <param name="menu">/dhis-web-datamart/menu.vm</param>
+    </action>
 		
     <action name="getOptions" class="org.hisp.dhis.datamart.action.GetOptionsAction">
       <result name="success" type="velocity">/main.vm</result>
@@ -73,5 +75,17 @@
       <result name="input" type="velocity-xml">/dhis-web-datamart/responseInput.vm</result>
     </action>
     
+    <!-- Schedule -->
+    
+    <action name="getScheduledExportStatus" class="org.hisp.dhis.datamart.action.GetScheduledExportStatusAction">
+      <result name="success" type="velocity">/main.vm</result>
+      <param name="page">/dhis-web-datamart/viewScheduledExport.vm</param>
+      <param name="menu">/dhis-web-datamart/menu.vm</param>
+    </action>
+    
+    <action name="scheduleExport" class="org.hisp.dhis.datamart.action.ScheduleExportAction">
+      <result name="success" type="redirect">getScheduledExportStatus.action</result>
+    </action>
+    
 	</package>
 </struts>

=== added file 'dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/index.vm'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/index.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/index.vm	2011-01-11 13:11:31 +0000
@@ -0,0 +1,7 @@
+
+<h3>$i18n.getString( "dhis-web-datamart" )</h3>
+
+<ul class="introList">
+	#introListImgItem( "getDataMartExports.action" "data_mart_export" "data_mart_export" )
+	#introListImgItem( "getScheduledExportStatus.action" "data_mart_scheduling" "scheduling" )
+</ul>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/menu.vm'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/menu.vm	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/menu.vm	2011-01-11 13:11:31 +0000
@@ -1,5 +1,6 @@
 
 <h2>$i18n.getString( "datamart" ) </h2>
 	<ul>
-		<li><a href="getDataMartExports.action">$i18n.getString( "data_mart" )&nbsp;</a></li>
+		<li><a href="getDataMartExports.action">$i18n.getString( "data_mart_export" )&nbsp;</a></li>
+		<li><a href="getScheduledExportStatus.action">$i18n.getString( "data_mart_scheduling" )&nbsp;</a></li>		
 	</ul>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm	2010-12-30 04:29:49 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewExportForm.vm	2011-01-11 13:11:31 +0000
@@ -1,5 +1,5 @@
 
-<h3>$i18n.getString( "data_mart_management" ) #openHelp( "datamart" ) </h3>
+<h3>$i18n.getString( "data_mart_export_management" ) #openHelp( "datamart" ) </h3>
 
 <table class="mainPageTable">
     <tr>

=== added file 'dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewScheduledExport.vm'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewScheduledExport.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/webapp/dhis-web-datamart/viewScheduledExport.vm	2011-01-11 13:11:31 +0000
@@ -0,0 +1,15 @@
+
+<h3>$i18n.getString( "data_mart_scheduling_management" )</h3>
+
+<span id="info">$i18n.getString( "scheduled_export_is" ) $!i18n.getString( $status )</span>
+
+<p>
+<input type="button" style="width:140px" onclick="window.location.href='scheduleExport.action'"
+#if ( $running )
+value="$i18n.getString( 'stop' )"
+#else
+value="$i18n.getString( 'start' )"
+#end
+>
+<input type="button" style="width:140px" onclick="window.location.href='getScheduledExportStatus.action'" value="$i18n.getString( 'refresh' )">
+</p>
\ No newline at end of file