dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21206
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9966: Impl task/runnable classes for resource tables and analytics tables
------------------------------------------------------------
revno: 9966
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-03-04 15:44:15 +0100
message:
Impl task/runnable classes for resource tables and analytics tables
removed:
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/scheduling/
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/scheduling/
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/scheduling/TaskTest.java
added:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/ScheduledTasks.java
dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/scheduling/
dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/scheduling/TaskTest.java
renamed:
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/scheduling/DataMartTask.java => dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DataMartTask.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java
dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-analytics/pom.xml
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-reporting/pom.xml
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/SchedulingManager.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/datamart/action/StartExportAction.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/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-api/src/main/java/org/hisp/dhis/period/Cal.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java 2012-09-03 19:48:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java 2013-03-04 14:44:15 +0000
@@ -122,6 +122,19 @@
}
/**
+ * Sets the current month and day.
+ *
+ * @param month the month starting at 1.
+ * @param day the day of the month starting at 1.
+ */
+ public Cal set( int month, int day )
+ {
+ calendar.set( Calendar.MONTH, month - 1 );
+ calendar.set( Calendar.DAY_OF_MONTH, day );
+ return this;
+ }
+
+ /**
* Sets the current time.
*
* @param date the date to base time on.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java 2013-03-03 21:10:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java 2013-03-04 14:44:15 +0000
@@ -34,6 +34,7 @@
{
DATAMART,
ANALYTICS_UPDATE,
+ RESOURCETABLE_UPDATE,
DATAVALUE_IMPORT,
METADATA_IMPORT,
METADATA_EXPORT
=== added directory 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling'
=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java 2013-03-04 14:44:15 +0000
@@ -0,0 +1,84 @@
+package org.hisp.dhis.resourcetable.scheduling;
+
+/*
+ * Copyright (c) 2004-2012, 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 org.hisp.dhis.resourcetable.ResourceTableService;
+import org.hisp.dhis.scheduling.TaskCategory;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.system.notification.NotificationLevel;
+import org.hisp.dhis.system.notification.Notifier;
+import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class ResourceTableTask
+ implements Runnable
+{
+ @Autowired
+ private ResourceTableService resourceTableService;
+
+ @Autowired
+ private Notifier notifier;
+
+ // -------------------------------------------------------------------------
+ // Must be set externally
+ // -------------------------------------------------------------------------
+
+ private User user;
+
+ public void setUser( User user )
+ {
+ this.user = user;
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ public ResourceTableTask()
+ {
+ }
+
+ // -------------------------------------------------------------------------
+ // Runnable implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void run()
+ {
+ TaskId taskId = new TaskId( TaskCategory.RESOURCETABLE_UPDATE, user );
+
+ notifier.notify( taskId, TaskCategory.RESOURCETABLE_UPDATE, "Generating resource tables" );
+
+ resourceTableService.generateAll();
+
+ notifier.notify( taskId, TaskCategory.RESOURCETABLE_UPDATE, NotificationLevel.INFO, "Resource tables generated", true );
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2013-03-01 17:59:05 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2013-03-04 14:44:15 +0000
@@ -130,4 +130,8 @@
<property name="sqlViewExpandStore" ref="org.hisp.dhis.sqlview.SqlViewExpandStore" />
</bean>
+ <!-- Scheduled tasks -->
+
+ <bean id="resourceTableTask" class="org.hisp.dhis.resourcetable.scheduling.ResourceTableTask" />
+
</beans>
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/pom.xml'
--- dhis-2/dhis-services/dhis-service-analytics/pom.xml 2012-12-03 21:13:51 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/pom.xml 2013-03-04 14:44:15 +0000
@@ -27,10 +27,6 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
- <artifactId>dhis-service-administration</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-support-system</artifactId>
</dependency>
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java 2013-03-03 21:10:52 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java 2013-03-04 14:44:15 +0000
@@ -36,7 +36,8 @@
/**
* Rebuilds the analytics tables.
*
+ * @param last3Years whether to update last 3 years of data only or all.
* @param taskId the TaskId.
*/
- Future<?> update( TaskId taskId );
+ Future<?> update( boolean last3Years, TaskId id );
}
=== added directory 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling'
=== added file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java 2013-03-04 14:44:15 +0000
@@ -0,0 +1,124 @@
+package org.hisp.dhis.analytics.scheduling;
+
+/*
+ * Copyright (c) 2004-2012, 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.scheduling.TaskCategory.ANALYTICS_UPDATE;
+import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
+
+import java.util.concurrent.ExecutionException;
+
+import javax.annotation.Resource;
+
+import org.hisp.dhis.analytics.AnalyticsTableService;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.system.notification.Notifier;
+import org.hisp.dhis.system.util.DebugUtils;
+import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class AnalyticsTableTask
+ implements Runnable
+{
+ @Resource(name="org.hisp.dhis.analytics.AnalyticsTableService")
+ private AnalyticsTableService analyticsTableService;
+
+ @Resource(name="org.hisp.dhis.analytics.CompletenessTableService")
+ private AnalyticsTableService completenessTableService;
+
+ @Resource(name="org.hisp.dhis.analytics.CompletenessTargetTableService")
+ private AnalyticsTableService completenessTargetTableService;
+
+ @Autowired
+ private Notifier notifier;
+
+ private boolean last3Years;
+
+ public void setLast3Years( boolean last3Years )
+ {
+ this.last3Years = last3Years;
+ }
+
+ // -------------------------------------------------------------------------
+ // Must be set externally
+ // -------------------------------------------------------------------------
+
+ private User user;
+
+ public void setUser( User user )
+ {
+ this.user = user;
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ public AnalyticsTableTask()
+ {
+ }
+
+ // -------------------------------------------------------------------------
+ // Runnable implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void run()
+ {
+ TaskId taskId = new TaskId( ANALYTICS_UPDATE, user );
+
+ notifier.clear( taskId, ANALYTICS_UPDATE );
+
+ try
+ {
+ notifier.notify( taskId, ANALYTICS_UPDATE, "Updating analytics tables" );
+
+ analyticsTableService.update( last3Years, taskId ).get();
+
+ notifier.notify( taskId, ANALYTICS_UPDATE, "Updating completeness tables" );
+
+ completenessTableService.update( last3Years, taskId ).get();
+
+ notifier.notify( taskId, ANALYTICS_UPDATE, "Updating compeleteness target table" );
+
+ completenessTargetTableService.update( last3Years, taskId ).get();
+
+ notifier.notify( taskId, ANALYTICS_UPDATE, INFO, "Analytics tables updated", true );
+ }
+ catch ( ExecutionException ex )
+ {
+ throw new RuntimeException( "Failed to execute task: " + DebugUtils.getStackTrace( ex ), ex );
+ }
+ catch ( InterruptedException ex )
+ {
+ throw new RuntimeException( "Task was interrupted: " + DebugUtils.getStackTrace( ex ), ex );
+ }
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java 2013-03-03 21:10:52 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java 2013-03-04 14:44:15 +0000
@@ -28,6 +28,7 @@
*/
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
@@ -43,6 +44,7 @@
import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Cal;
import org.hisp.dhis.scheduling.TaskId;
import org.hisp.dhis.system.notification.Notifier;
import org.hisp.dhis.system.util.Clock;
@@ -80,13 +82,14 @@
// -------------------------------------------------------------------------
@Async
- public Future<?> update( TaskId taskId )
+ public Future<?> update( boolean last3YearsOnly, TaskId taskId )
{
Clock clock = new Clock().startClock().logTime( "Starting update" );
try
{
- final Date earliest = tableManager.getEarliestData();
+ final Date threeYrsAgo = new Cal().subtract( Calendar.YEAR, 2 ).set( 1, 1 ).time();
+ final Date earliest = last3YearsOnly ? threeYrsAgo : tableManager.getEarliestData();
final Date latest = tableManager.getLatestData();
final String tableName = tableManager.getTableName();
final List<String> tables = PartitionUtils.getTempTableNames( earliest, latest, tableName );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml 2013-01-25 10:33:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml 2013-03-04 14:44:15 +0000
@@ -26,4 +26,14 @@
<bean id="org.hisp.dhis.analytics.QueryPlanner" class="org.hisp.dhis.analytics.data.DefaultQueryPlanner" />
+ <!-- Scheduled tasks -->
+
+ <bean id="analyticsAllTask" class="org.hisp.dhis.analytics.scheduling.AnalyticsTableTask">
+ <property name="last3Years" value="false" />
+ </bean>
+
+ <bean id="analyticsLast3YearsTask" class="org.hisp.dhis.analytics.scheduling.AnalyticsTableTask">
+ <property name="last3Years" value="true" />
+ </bean>
+
</beans>
=== removed directory 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/scheduling'
=== 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 2013-03-03 22:51:24 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml 2013-03-04 14:44:15 +0000
@@ -102,28 +102,6 @@
<property name="statementManager" ref="inMemoryStatementManager" />
</bean>
- <!-- Scheduling -->
-
- <bean id="abstractDataMartTask" class="org.hisp.dhis.datamart.scheduling.DataMartTask" scope="prototype">
- <constructor-arg ref="org.hisp.dhis.datamart.DataMartEngine" />
- <constructor-arg ref="org.hisp.dhis.completeness.DataSetCompletenessEngine" />
- <constructor-arg ref="org.hisp.dhis.period.PeriodService" />
- <constructor-arg ref="org.hisp.dhis.setting.SystemSettingManager" />
- </bean>
-
- <bean id="dataMartLast12MonthsTask" class="org.hisp.dhis.datamart.scheduling.DataMartTask" parent="abstractDataMartTask">
- <property name="last6Months" value="true"/>
- <property name="last6To12Months" value="true"/>
- </bean>
-
- <bean id="dataMartLast6MonthsTask" class="org.hisp.dhis.datamart.scheduling.DataMartTask" parent="abstractDataMartTask">
- <property name="last6Months" value="true"/>
- </bean>
-
- <bean id="dataMartFrom6To12MonthsTask" class="org.hisp.dhis.datamart.scheduling.DataMartTask" parent="abstractDataMartTask">
- <property name="last6To12Months" value="true"/>
- </bean>
-
<!-- Deletion AOP definitions -->
<aop:config>
=== removed directory 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/scheduling'
=== removed file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/scheduling/TaskTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/scheduling/TaskTest.java 2013-03-03 22:51:24 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/scheduling/TaskTest.java 1970-01-01 00:00:00 +0000
@@ -1,87 +0,0 @@
-package org.hisp.dhis.datamart.scheduling;
-
-/*
- * Copyright (c) 2004-2012, 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.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.hisp.dhis.period.BiMonthlyPeriodType;
-import org.hisp.dhis.period.FinancialJulyPeriodType;
-import org.hisp.dhis.period.MonthlyPeriodType;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.QuarterlyPeriodType;
-import org.hisp.dhis.period.SixMonthlyPeriodType;
-import org.hisp.dhis.period.YearlyPeriodType;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Lars Helge Overland
- */
-public class TaskTest
-{
- @Test
- public void testGetPeriods()
- {
- Set<String> periodTypes = new HashSet<String>();
- periodTypes.add( MonthlyPeriodType.NAME );
- periodTypes.add( BiMonthlyPeriodType.NAME );
- periodTypes.add( QuarterlyPeriodType.NAME );
- periodTypes.add( SixMonthlyPeriodType.NAME );
- periodTypes.add( YearlyPeriodType.NAME );
- periodTypes.add( FinancialJulyPeriodType.NAME );
-
- DataMartTask dataMartTask = new DataMartTask();
-
- dataMartTask.setLast6Months( true );
- dataMartTask.setLast6To12Months( true );
-
- List<Period> periods = dataMartTask.getPeriods( periodTypes );
-
- assertNotNull( periods );
- assertEquals( 28, periods.size() ); // 12 + 6 + 4 + 2 + 1 + 1
-
- dataMartTask.setLast6Months( true );
- dataMartTask.setLast6To12Months( false );
-
- periods = dataMartTask.getPeriods( periodTypes );
-
- assertNotNull( periods );
- assertEquals( 14, periods.size() ); // 6 + 3 + 2 + 1 + 1 + 1
-
- dataMartTask.setLast6Months( false );
- dataMartTask.setLast6To12Months( true );
-
- periods = dataMartTask.getPeriods( periodTypes );
-
- assertNotNull( periods );
- assertEquals( 14, periods.size() ); // 6 + 3 + 2 + 1 + 1 + 1
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/pom.xml'
--- dhis-2/dhis-services/dhis-service-reporting/pom.xml 2012-11-14 16:52:37 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/pom.xml 2013-03-04 14:44:15 +0000
@@ -27,8 +27,16 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-analytics</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-service-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-administration</artifactId>
+ </dependency>
<!-- JasperReports -->
=== renamed file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/scheduling/DataMartTask.java' => 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DataMartTask.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/scheduling/DataMartTask.java 2013-03-03 22:51:24 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DataMartTask.java 2013-03-04 14:44:15 +0000
@@ -1,4 +1,4 @@
-package org.hisp.dhis.datamart.scheduling;
+package org.hisp.dhis.scheduling;
/*
* Copyright (c) 2004-2012, University of Oslo
@@ -45,6 +45,8 @@
import org.hisp.dhis.scheduling.TaskId;
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.system.util.ConversionUtils;
+import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* @author Lars Helge Overland
@@ -54,25 +56,18 @@
{
private static final Log log = LogFactory.getLog( DataMartTask.class );
+ @Autowired
private DataMartEngine dataMartEngine;
+ @Autowired
private DataSetCompletenessEngine completenessEngine;
-
+
+ @Autowired
private PeriodService periodService;
-
+
+ @Autowired
private SystemSettingManager systemSettingManager;
- // -------------------------------------------------------------------------
- // Params
- // -------------------------------------------------------------------------
-
- private TaskId taskId;
-
- public void setTaskId( TaskId taskId )
- {
- this.taskId = taskId;
- }
-
private List<Period> periods;
public void setPeriods( List<Period> periods )
@@ -95,6 +90,17 @@
}
// -------------------------------------------------------------------------
+ // Must be set externally
+ // -------------------------------------------------------------------------
+
+ private User user;
+
+ public void setUser( User user )
+ {
+ this.user = user;
+ }
+
+ // -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -102,23 +108,16 @@
{
}
- public DataMartTask( DataMartEngine dataMartEngine, DataSetCompletenessEngine completenessEngine,
- PeriodService periodService, SystemSettingManager systemSettingManager )
- {
- this.dataMartEngine = dataMartEngine;
- this.completenessEngine = completenessEngine;
- this.periodService = periodService;
- this.systemSettingManager = systemSettingManager;
- }
-
// -------------------------------------------------------------------------
// Runnable implementation
// -------------------------------------------------------------------------
- @Override
+ @Override
@SuppressWarnings("unchecked")
public void run()
{
+ TaskId taskId = new TaskId( TaskCategory.DATAMART, user );
+
Set<String> periodTypes = (Set<String>) systemSettingManager.getSystemSetting( KEY_SCHEDULED_PERIOD_TYPES, DEFAULT_SCHEDULED_PERIOD_TYPES );
List<Period> periods = getPeriods( periodTypes );
=== added file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/ScheduledTasks.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/ScheduledTasks.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/ScheduledTasks.java 2013-03-04 14:44:15 +0000
@@ -0,0 +1,54 @@
+package org.hisp.dhis.scheduling;
+
+/*
+ * Copyright (c) 2004-2012, 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.ArrayList;
+import java.util.List;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class ScheduledTasks
+ implements Runnable
+{
+ private List<Runnable> tasks = new ArrayList<Runnable>();
+
+ public void addTask( Runnable task )
+ {
+ this.tasks.add( task );
+ }
+
+ @Override
+ public void run()
+ {
+ for ( Runnable task : tasks )
+ {
+ task.run();
+ }
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/SchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/SchedulingManager.java 2012-09-10 10:28:33 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/SchedulingManager.java 2013-03-04 14:44:15 +0000
@@ -34,9 +34,12 @@
*/
public interface SchedulingManager
{
+ final String TASK_RESOURCE_TABLE = "resourceTableTask";
final String TASK_DATAMART_LAST_12_MONTHS = "dataMartLast12MonthsTask";
final String TASK_DATAMART_LAST_6_MONTS = "dataMartLast6MonthsTask";
final String TASK_DATAMART_FROM_6_TO_12_MONTS = "dataMartFrom6To12MonthsTask";
+ final String TASK_ANALYTICS_ALL = "analyticsAllTask";
+ final String TASK_ANALYTICS_LAST_3_YEARS = "analyticsLast3YearsTask";
void scheduleTasks();
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2013-03-03 22:51:24 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2013-03-04 14:44:15 +0000
@@ -246,13 +246,31 @@
<property name="scheduler" ref="scheduler" />
<property name="tasks">
<map>
+ <entry key="resourceTableTask" value-ref="resourceTableTask" />
<entry key="dataMartLast12MonthsTask" value-ref="dataMartLast12MonthsTask" />
<entry key="dataMartLast6MonthsTask" value-ref="dataMartLast6MonthsTask" />
<entry key="dataMartFrom6To12MonthsTask" value-ref="dataMartFrom6To12MonthsTask" />
+ <entry key="analyticsAllTask" value-ref="analyticsAllTask" />
+ <entry key="analyticsLast3YearsTask" value-ref="analyticsLast3YearsTask" />
</map>
</property>
</bean>
+ <!-- Scheduled tasks -->
+
+ <bean id="dataMartLast12MonthsTask" class="org.hisp.dhis.scheduling.DataMartTask">
+ <property name="last6Months" value="true"/>
+ <property name="last6To12Months" value="true"/>
+ </bean>
+
+ <bean id="dataMartLast6MonthsTask" class="org.hisp.dhis.scheduling.DataMartTask">
+ <property name="last6Months" value="true"/>
+ </bean>
+
+ <bean id="dataMartFrom6To12MonthsTask" class="org.hisp.dhis.scheduling.DataMartTask">
+ <property name="last6To12Months" value="true"/>
+ </bean>
+
<!-- DeletionHandler -->
<bean id="org.hisp.dhis.report.ReportDeletionHandler" class="org.hisp.dhis.report.ReportDeletionHandler">
=== added directory 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/scheduling'
=== added file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/scheduling/TaskTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/scheduling/TaskTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/scheduling/TaskTest.java 2013-03-04 14:44:15 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.scheduling;
+
+/*
+ * Copyright (c) 2004-2012, 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.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hisp.dhis.period.BiMonthlyPeriodType;
+import org.hisp.dhis.period.FinancialJulyPeriodType;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.QuarterlyPeriodType;
+import org.hisp.dhis.period.SixMonthlyPeriodType;
+import org.hisp.dhis.period.YearlyPeriodType;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class TaskTest
+{
+ @Test
+ public void testGetPeriods()
+ {
+ Set<String> periodTypes = new HashSet<String>();
+ periodTypes.add( MonthlyPeriodType.NAME );
+ periodTypes.add( BiMonthlyPeriodType.NAME );
+ periodTypes.add( QuarterlyPeriodType.NAME );
+ periodTypes.add( SixMonthlyPeriodType.NAME );
+ periodTypes.add( YearlyPeriodType.NAME );
+ periodTypes.add( FinancialJulyPeriodType.NAME );
+
+ DataMartTask dataMartTask = new DataMartTask();
+
+ dataMartTask.setLast6Months( true );
+ dataMartTask.setLast6To12Months( true );
+
+ List<Period> periods = dataMartTask.getPeriods( periodTypes );
+
+ assertNotNull( periods );
+ assertEquals( 28, periods.size() ); // 12 + 6 + 4 + 2 + 1 + 1
+
+ dataMartTask.setLast6Months( true );
+ dataMartTask.setLast6To12Months( false );
+
+ periods = dataMartTask.getPeriods( periodTypes );
+
+ assertNotNull( periods );
+ assertEquals( 14, periods.size() ); // 6 + 3 + 2 + 1 + 1 + 1
+
+ dataMartTask.setLast6Months( false );
+ dataMartTask.setLast6To12Months( true );
+
+ periods = dataMartTask.getPeriods( periodTypes );
+
+ assertNotNull( periods );
+ assertEquals( 14, periods.size() ); // 6 + 3 + 2 + 1 + 1 + 1
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/datamart/action/StartExportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/datamart/action/StartExportAction.java 2013-03-04 10:57:36 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/datamart/action/StartExportAction.java 2013-03-04 14:44:15 +0000
@@ -33,12 +33,10 @@
import java.util.List;
import java.util.Set;
-import org.hisp.dhis.datamart.scheduling.DataMartTask;
import org.hisp.dhis.period.CalendarPeriodType;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.scheduling.TaskCategory;
-import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.scheduling.DataMartTask;
import org.hisp.dhis.system.scheduling.Scheduler;
import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.user.CurrentUserService;
@@ -121,12 +119,10 @@
periods.addAll( periodType.generatePeriods( start, end ) );
}
- TaskId taskId = new TaskId( TaskCategory.DATAMART, currentUserService.getCurrentUser() );
-
if ( periods.size() > 0 )
{
dataMartTask.setPeriods( periods );
- dataMartTask.setTaskId( taskId );
+ dataMartTask.setUser( currentUserService.getCurrentUser() );
scheduler.executeTask( dataMartTask );
}