← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9423: Remove Aggregate task strategy param in Automated Aggregation function.

 

------------------------------------------------------------
revno: 9423
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-01-03 13:54:08 +0700
message:
  Remove Aggregate task strategy param in Automated Aggregation function.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ScheduleCaseAggregateConditionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.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-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java	2012-10-10 08:50:17 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionSchedulingManager.java	2013-01-03 06:54:08 +0000
@@ -36,10 +36,7 @@
  */
 public interface CaseAggregateConditionSchedulingManager
 {
-    final String TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTHS = "aggregateLast12MonthsTask";
-    final String TASK_AGGREGATE_QUERY_BUILDER_LAST_6_MONTS = "aggregateLast6MonthsTask";
-    final String TASK_AGGREGATE_QUERY_BUILDER_FROM_6_TO_12_MONTS = "aggregateFrom6To12MonthsTask";
-    
+    final String TASK_AGGREGATE_QUERY_BUILDER = "aggregateQueryBuilder";
     void scheduleTasks();
     
     void scheduleTasks( Map<String, String> keyCronMap );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java	2012-11-16 03:50:03 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/CaseAggregateConditionTask.java	2013-01-03 06:54:08 +0000
@@ -27,13 +27,8 @@
 
 package org.hisp.dhis.patient.scheduling;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
 
 import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
 import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
@@ -47,8 +42,8 @@
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.CalendarPeriodType;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.RelativePeriods;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
 
@@ -77,24 +72,6 @@
     private DataSetService dataSetService;
 
     // -------------------------------------------------------------------------
-    // Params
-    // -------------------------------------------------------------------------
-
-    private boolean last6Months;
-
-    public void setLast6Months( boolean last6Months )
-    {
-        this.last6Months = last6Months;
-    }
-
-    private boolean last6To12Months;
-
-    public void setLast6To12Months( boolean last6To12Months )
-    {
-        this.last6To12Months = last6To12Months;
-    }
-
-    // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
 
@@ -121,54 +98,46 @@
     {
         Collection<OrganisationUnit> orgunits = organisationUnitService.getAllOrganisationUnits();
 
-        // ---------------------------------------------------------------------
-        // Get Period list in system-setting
-        // ---------------------------------------------------------------------
-
         Collection<DataSet> dataSets = dataSetService.getAllDataSets();
 
         for ( DataSet dataSet : dataSets )
         {
-            String periodType = dataSet.getPeriodType().getName();
-            List<Period> periods = getPeriods( periodType );
-
-            String sql = "select caseaggregationconditionid, aggregationdataelementid, optioncomboid "
-                + "from caseaggregationcondition cagg inner join datasetmembers dm "
-                + "on cagg.aggregationdataelementid=dm.dataelementid " + "inner join dataset ds "
-                + "on ds.datasetid = dm.datasetid " + "inner join periodtype pt "
-                + "on pt.periodtypeid=ds.periodtypeid " + "where ds.datasetid = " + dataSet.getId();
-
-            SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
-
-            while ( rs.next() )
+            Period period = getPeriod( dataSet.getPeriodType().getName() );
+
+            if ( period != null )
             {
-                // -------------------------------------------------------------
-                // Get formula, agg-dataelement and option-combo
-                // -------------------------------------------------------------
-
-                int dataelementId = rs.getInt( "aggregationdataelementid" );
-                int optionComboId = rs.getInt( "optioncomboid" );
-
-                DataElement dElement = dataElementService.getDataElement( dataelementId );
-                DataElementCategoryOptionCombo optionCombo = categoryService
-                    .getDataElementCategoryOptionCombo( optionComboId );
-
-                CaseAggregationCondition aggCondition = aggregationConditionService.getCaseAggregationCondition( rs
-                    .getInt( "caseaggregationconditionid" ) );
-
-                // ---------------------------------------------------------------------
-                // Aggregation
-                // ---------------------------------------------------------------------
-
-                for ( OrganisationUnit orgUnit : orgunits )
+                String sql = "select caseaggregationconditionid, aggregationdataelementid, optioncomboid "
+                    + "from caseaggregationcondition cagg inner join datasetmembers dm "
+                    + "on cagg.aggregationdataelementid=dm.dataelementid " + "inner join dataset ds "
+                    + "on ds.datasetid = dm.datasetid " + "inner join periodtype pt "
+                    + "on pt.periodtypeid=ds.periodtypeid " + "where ds.datasetid = " + dataSet.getId();
+
+                SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
+
+                while ( rs.next() )
                 {
-                    for ( Period period : periods )
+                    // -------------------------------------------------------------
+                    // Get formula, agg-dataelement and option-combo
+                    // -------------------------------------------------------------
+
+                    int dataelementId = rs.getInt( "aggregationdataelementid" );
+                    int optionComboId = rs.getInt( "optioncomboid" );
+
+                    DataElement dElement = dataElementService.getDataElement( dataelementId );
+                    DataElementCategoryOptionCombo optionCombo = categoryService
+                        .getDataElementCategoryOptionCombo( optionComboId );
+
+                    CaseAggregationCondition aggCondition = aggregationConditionService.getCaseAggregationCondition( rs
+                        .getInt( "caseaggregationconditionid" ) );
+
+                    // ---------------------------------------------------------------------
+                    // Aggregation
+                    // ---------------------------------------------------------------------
+
+                    for ( OrganisationUnit orgUnit : orgunits )
                     {
                         DataValue dataValue = dataValueService.getDataValue( orgUnit, dElement, period, optionCombo );
 
-                        if ( dataValue != null && dataValue.getStoredBy().equals( STORED_BY_DHIS_SYSTEM ) )
-                            continue;
-
                         Integer resultValue = aggregationConditionService.parseConditition( aggCondition, orgUnit,
                             period );
 
@@ -183,6 +152,7 @@
                                     null, optionCombo );
                                 dataValueService.addDataValue( dataValue );
                             }
+
                             // -----------------------------------------------------
                             // Update dataValue
                             // -----------------------------------------------------
@@ -216,33 +186,14 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    private List<Period> getPeriods( String periodType )
+    private Period getPeriod( String periodTypeName )
     {
-        Set<String> periodTypes = new HashSet<String>();
-        periodTypes.add( periodType );
-
-        List<Period> relatives = new ArrayList<Period>();
-
-        if ( last6Months )
-        {
-            relatives.addAll( new RelativePeriods().getLast6Months( periodTypes ) );
-        }
-
-        if ( last6To12Months )
-        {
-            relatives.addAll( new RelativePeriods().getLast6To12Months( periodTypes ) );
-        }
-
-        Iterator<Period> iter = relatives.iterator();
-        Date currentDate = new Date();
-        while ( iter.hasNext() )
-        {
-            if ( currentDate.before( iter.next().getEndDate() ) )
-            {
-                iter.remove();
-            }
-        }
-        return relatives;
+        Date date = new Date();
+
+        CalendarPeriodType periodType = (CalendarPeriodType) CalendarPeriodType.getPeriodTypeByName( periodTypeName );
+
+        Period period = periodType.createPeriod( date );
+
+        return (period.getEndDate().equals( date ) || period.getEndDate().before( date )) ? period : null;
     }
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2012-12-21 09:23:20 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2013-01-03 06:54:08 +0000
@@ -444,9 +444,7 @@
 		<property name="scheduler" ref="scheduler" />
 		<property name="tasks">
 			<map>
-				<entry key="aggregateLast12MonthsTask" value-ref="aggregateLast12MonthsTask" />
-				<entry key="aggregateLast6MonthsTask" value-ref="aggregateLast6MonthsTask" />
-				<entry key="aggregateFrom6To12MonthsTask" value-ref="aggregateFrom6To12MonthsTask" />
+				<entry key="aggregateQueryBuilder" value-ref="aggregateQueryBuilder" />
 			</map>
 		</property>
 	</bean>
@@ -462,20 +460,8 @@
 		<constructor-arg ref="org.hisp.dhis.dataset.DataSetService" />
 	</bean>
 
-	<bean id="aggregateLast12MonthsTask" class="org.hisp.dhis.patient.scheduling.CaseAggregateConditionTask"
-		parent="abstractRunCaseAggregateConditionTask">
-		<property name="last6Months" value="true" />
-		<property name="last6To12Months" value="true" />
-	</bean>
-
-	<bean id="aggregateLast6MonthsTask" class="org.hisp.dhis.patient.scheduling.CaseAggregateConditionTask"
-		parent="abstractRunCaseAggregateConditionTask">
-		<property name="last6Months" value="true" />
-	</bean>
-
-	<bean id="aggregateFrom6To12MonthsTask" class="org.hisp.dhis.patient.scheduling.CaseAggregateConditionTask"
-		parent="abstractRunCaseAggregateConditionTask">
-		<property name="last6To12Months" value="true" />
+	<bean id="aggregateQueryBuilder" class="org.hisp.dhis.patient.scheduling.CaseAggregateConditionTask"
+		parent="abstractRunCaseAggregateConditionTask">
 	</bean>
 
 	<!-- Startup -->

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ScheduleCaseAggregateConditionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ScheduleCaseAggregateConditionAction.java	2012-11-16 03:50:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ScheduleCaseAggregateConditionAction.java	2013-01-03 06:54:08 +0000
@@ -43,10 +43,6 @@
 public class ScheduleCaseAggregateConditionAction
     implements Action
 {
-    private static final String STRATEGY_LAST_12_DAILY = "last12Daily";
-
-    private static final String STRATEGY_LAST_6_DAILY_6_TO_12_WEEKLY = "last6Daily6To12Weekly";
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -68,13 +64,6 @@
     {
         this.execute = execute;
     }
-    
-    private String aggQueryBuilderStrategy;
-
-    public void setAggQueryBuilderStrategy( String aggQueryBuilderStrategy )
-    {
-        this.aggQueryBuilderStrategy = aggQueryBuilderStrategy;
-    }
 
     // -------------------------------------------------------------------------
     // Output
@@ -107,7 +96,7 @@
             schedulingManager.executeTasks();
         }
         else
-        {       
+        {
             if ( Scheduler.STATUS_RUNNING.equals( schedulingManager.getTaskStatus() ) )
             {
                 schedulingManager.stopTasks();
@@ -116,20 +105,8 @@
             {
                 Map<String, String> keyCronMap = new HashMap<String, String>();
 
-                if ( STRATEGY_LAST_12_DAILY.equals( aggQueryBuilderStrategy ) )
-                {
-                    keyCronMap.put(
-                        CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_12_MONTHS,
-                        Scheduler.CRON_DAILY_0AM );
-                }
-                else if ( STRATEGY_LAST_6_DAILY_6_TO_12_WEEKLY.equals( aggQueryBuilderStrategy ) )
-                {
-                    keyCronMap.put( CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_LAST_6_MONTS,
-                        Scheduler.CRON_DAILY_0AM_EXCEPT_SUNDAY );
-                    keyCronMap.put(
-                        CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER_FROM_6_TO_12_MONTS,
-                        Scheduler.CRON_WEEKLY_SUNDAY_0AM );
-                }
+                keyCronMap.put( CaseAggregateConditionSchedulingManager.TASK_AGGREGATE_QUERY_BUILDER,
+                    Scheduler.CRON_DAILY_0AM );
 
                 schedulingManager.scheduleTasks( keyCronMap );
             }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js	2012-11-16 03:50:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js	2013-01-03 06:54:08 +0000
@@ -46,8 +46,7 @@
 function schedulingAggCondTasks()
 {
 	$.post( 'scheduleCaseAggTasks.action',{
-		execute:false,
-		aggQueryBuilderStrategy:getFieldValue("aggQueryBuilderStrategy")
+		execute:false
 	}, function( json ){
 		var status = json.scheduleTasks.status;
 		if( status=='not_started' ){
@@ -72,8 +71,7 @@
 	if ( ok )
 	{
 		$.post( 'scheduleCaseAggTasks.action',{
-			execute:true,
-			aggQueryBuilderStrategy:getFieldValue("aggQueryBuilderStrategy")
+			execute:true
 		},function( json ){
 			setMessage(i18n_execute_success);
 		});

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.vm	2012-11-16 03:50:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewScheduledCaseAggTasks.vm	2013-01-03 06:54:08 +0000
@@ -17,26 +17,7 @@
 <input type='hidden' id='execute' name='execute'/>
 	
 <table>
-<tr>
-	<td style="height:10px"></td>
-</tr>
-<tr>
-	<td style="height:10px"></td>
-</tr>
-<tr>
-	<th>$i18n.getString( "aggregate_task_strategy" )</th>
-</tr>
-<tr>
-	<td>
-		<select id="aggQueryBuilderStrategy" name="aggQueryBuilderStrategy" class="scheduling" style="width:100%">
-		<option value="last12Daily"#if( $aggQueryBuilderStrategy && $aggQueryBuilderStrategy == "last12Daily" ) selected="selected"#end>$i18n.getString( "last_12_months_daily" )</option>
-		<option value="last6Daily6To12Weekly"#if( $aggQueryBuilderStrategy && $aggQueryBuilderStrategy == "last6Daily6To12Weekly" ) selected="selected"#end>$i18n.getString( "last_6_months_daily_6_to_12_months_weekly" )</option>		
-		</select>
-	</td>
-</tr>
-<tr>
-	<td style="height:10px"></td>
-</tr>
+
 <tr>
 	<td>
 		<input type="button" style="width:140px" onclick="schedulingAggCondTasks();"