← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5710: Data mart scheduling, including last year

 

------------------------------------------------------------
revno: 5710
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-01-11 21:46:15 +0100
message:
  Data mart scheduling, including last year
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.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-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	2012-01-09 07:21:44 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/scheduling/DataMartTask.java	2012-01-11 20:46:15 +0000
@@ -55,6 +55,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.RelativePeriods;
+import org.hisp.dhis.period.YearlyPeriodType;
 import org.hisp.dhis.system.util.ConversionUtils;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
@@ -99,6 +100,10 @@
         this.from6To12Months = from6To12Months;
     }
 
+    public DataMartTask()
+    {
+    }
+    
     public DataMartTask( DataMartService dataMartService, DataSetCompletenessService completenessService, 
         DataElementService dataElementService, IndicatorService indicatorService, PeriodService periodService,
         OrganisationUnitService organisationUnitService, OrganisationUnitGroupService organisationUnitGroupService,
@@ -115,8 +120,8 @@
         this.systemSettingManager = systemSettingManager;
     }
     
-    @Override
-    @SuppressWarnings("unchecked")    
+    @Override  
+    @SuppressWarnings("unchecked")  
     public void run()
     {
         Collection<Integer> dataElementIds = ConversionUtils.getIdentifiers( DataElement.class, dataElementService.getAllDataElements() );
@@ -126,9 +131,29 @@
         Collection<Integer> organisationUnitGroupIds = ConversionUtils.getIdentifiers( OrganisationUnitGroup.class, organisationUnitGroupService.getOrganisationUnitGroupsWithGroupSets() );
         
         Set<String> periodTypes = (Set<String>) systemSettingManager.getSystemSetting( KEY_SCHEDULED_PERIOD_TYPES, DEFAULT_SCHEDULED_PERIOD_TYPES );
+        
+        List<Period> periods = getPeriods( periodTypes );
+        
+        log.info( "Using periods: " + periods );
+        
+        Collection<Integer> periodIds = ConversionUtils.getIdentifiers( Period.class, periodService.reloadPeriods( periods ) );
+        
+        dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, organisationUnitGroupIds, null, true );
+        completenessService.exportDataSetCompleteness( dataSetIds, periodIds, organisationUnitIds ); 
+    }
 
+    /**
+     * Generates periods based on parameters and period types argument.
+     */
+    private List<Period> getPeriods( Set<String> periodTypes )
+    {
         List<Period> periods = new RelativePeriods().getRelativePeriods( periodTypes ).getRelativePeriods( 0 );
         
+        if ( periodTypes.contains( YearlyPeriodType.NAME ) ) // Add last year
+        {
+            periods.addAll( new RelativePeriods().setLastYear( true ).getRelativePeriods( 0 ) );
+        }
+        
         final Date date = new Cal().now().subtract( Calendar.MONTH, 6 ).time();
         
         if ( last6Months )
@@ -148,15 +173,10 @@
                 public boolean retain( Period period )
                 {
                     return period != null && period.getStartDate().compareTo( date ) <= 0;
-                }                
+                }
             } );
         }
         
-        log.info( "Using periods: " + periods );
-        
-        Collection<Integer> periodIds = ConversionUtils.getIdentifiers( Period.class, periodService.reloadPeriods( periods ) );
-        
-        dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds, organisationUnitGroupIds, null, true );
-        completenessService.exportDataSetCompleteness( dataSetIds, periodIds, organisationUnitIds ); 
+        return periods;
     }
 }