← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15286: Move all classes from package org.hisp.dhis.trackedentity.scheduling to project dhis-service-even...

 

------------------------------------------------------------
revno: 15286
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-05-16 16:12:25 +0800
message:
  Move all classes from package org.hisp.dhis.trackedentity.scheduling to project dhis-service-eventreporting.
removed:
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/DefaultProgramSchedulingManager.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/ProgramSchedulingManager.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/SendScheduledMessageTask.java
added:
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/ProgramSchedulingManager.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java
modified:
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/DefaultProgramSchedulingManager.java	2014-05-16 08:12:25 +0000
@@ -0,0 +1,139 @@
+package org.hisp.dhis.scheduling;
+
+/*
+ * Copyright (c) 2004-2014, 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.setting.SystemSettingManager.KEY_SEND_MESSAGE_SCHEDULED_TASKS;
+import static org.hisp.dhis.system.scheduling.Scheduler.STATUS_NOT_STARTED;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.system.scheduling.Scheduler;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version DefaultProgramSchedulingManager.java 12:51:02 PM Sep 10, 2012 $
+ */
+public class DefaultProgramSchedulingManager implements ProgramSchedulingManager
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SystemSettingManager systemSettingManager;
+    
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
+    }
+
+    private Scheduler scheduler;
+
+    public void setScheduler( Scheduler scheduler )
+    {
+        this.scheduler = scheduler;
+    }
+
+    private Map<String, Runnable> tasks = new HashMap<String, Runnable>();
+
+    public void setTasks( Map<String, Runnable> tasks )
+    {
+        this.tasks = tasks;
+    }
+
+    // -------------------------------------------------------------------------
+    // SchedulingManager implementation
+    // -------------------------------------------------------------------------
+
+    public void scheduleTasks()
+    {
+        Map<String, String> keyCronMap = getScheduledTasks();
+        
+        for ( String key : keyCronMap.keySet() )
+        {
+            String cron = keyCronMap.get( key );
+            Runnable task = tasks.get( key );
+            
+            if ( cron != null && task != null )
+            {
+                scheduler.scheduleTask( key, task, cron );
+            }
+        }
+    }
+    
+    public void scheduleTasks( Map<String, String> keyCronMap )
+    {
+        systemSettingManager.saveSystemSetting( KEY_SEND_MESSAGE_SCHEDULED_TASKS, new HashMap<String, String>( keyCronMap ) );
+        
+        scheduleTasks();
+    }
+    
+    public void stopTasks()
+    {
+        systemSettingManager.saveSystemSetting( KEY_SEND_MESSAGE_SCHEDULED_TASKS, null );
+        
+        scheduler.stopAllTasks();
+    }
+    
+    public void executeTasks()
+    {
+        Map<String, String> keyCronMap = getScheduledTasks();
+        
+        for ( String key : keyCronMap.keySet() )
+        {
+            Runnable task = tasks.get( key );
+            
+            if ( task != null )
+            {
+                scheduler.executeTask( task );
+            }
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    public Map<String, String> getScheduledTasks()
+    {
+        return (Map<String, String>) systemSettingManager.getSystemSetting( KEY_SEND_MESSAGE_SCHEDULED_TASKS, new HashMap<String, String>() );
+    }
+    
+    public String getTaskStatus()
+    {
+        Map<String, String> keyCronMap = getScheduledTasks();
+                
+        if ( keyCronMap.size() == 0 )
+        {
+            return STATUS_NOT_STARTED;
+        }
+        
+        return scheduler.getTaskStatus( keyCronMap.keySet().iterator().next() );
+    }
+}
+

=== added file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/ProgramSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/ProgramSchedulingManager.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/ProgramSchedulingManager.java	2014-05-16 08:12:25 +0000
@@ -0,0 +1,53 @@
+package org.hisp.dhis.scheduling;
+
+/*
+ * Copyright (c) 2004-2014, 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.Map;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version ProgramSchedulingManager.java 12:47:57 PM Sep 10, 2012 $
+ */
+public interface ProgramSchedulingManager
+{
+    final String TASK_SENDING_MESSAGE = "sendingMessageTask";
+    
+    void scheduleTasks();
+    
+    void scheduleTasks( Map<String, String> keyCronMap );
+    
+    void stopTasks();
+    
+    void executeTasks();
+    
+    Map<String, String> getScheduledTasks();
+    
+    String getTaskStatus();   
+}

=== added file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/SendScheduledMessageTask.java	2014-05-16 08:12:25 +0000
@@ -0,0 +1,263 @@
+package org.hisp.dhis.scheduling;
+
+/*
+ * Copyright (c) 2004-2014, 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.sms.outbound.OutboundSms.DHIS_SYSTEM_SENDER;
+import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
+import java.util.Collection;
+import java.util.List;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.program.SchedulingProgramObject;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.sms.SmsSender;
+import org.hisp.dhis.sms.SmsServiceException;
+import org.hisp.dhis.sms.outbound.OutboundSms;
+import org.hisp.dhis.sms.outbound.OutboundSmsService;
+import org.hisp.dhis.sms.outbound.OutboundSmsStatus;
+import org.hisp.dhis.system.notification.Notifier;
+import org.hisp.dhis.system.util.Clock;
+import org.hisp.dhis.system.util.SystemUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version SendScheduledMessageTask.java 12:57:53 PM Sep 10, 2012 $
+ */
+public class SendScheduledMessageTask
+    implements Runnable
+{
+    private ProgramStageInstanceService programStageInstanceService;
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
+    private ProgramInstanceService programInstanceService;
+
+    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
+    {
+        this.programInstanceService = programInstanceService;
+    }
+
+    private OutboundSmsService outboundSmsService;
+
+    public void setOutboundSmsService( OutboundSmsService outboundSmsService )
+    {
+        this.outboundSmsService = outboundSmsService;
+    }
+
+    private SmsSender smsSender;
+
+    public void setSmsSender( SmsSender smsSender )
+    {
+        this.smsSender = smsSender;
+    }
+
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+    private Notifier notifier;
+
+    public void setNotifier( Notifier notifier )
+    {
+        this.notifier = notifier;
+    }
+
+    // -------------------------------------------------------------------------
+    // Params
+    // -------------------------------------------------------------------------
+
+    private Boolean sendingMessage;
+
+    public void setSendingMessage( Boolean sendingMessage )
+    {
+        this.sendingMessage = sendingMessage;
+    }
+
+    private TaskId taskId;
+
+    public void setTaskId( TaskId taskId )
+    {
+        this.taskId = taskId;
+    }
+
+    // -------------------------------------------------------------------------
+    // Runnable implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void run()
+    {
+        final int cpuCores = SystemUtils.getCpuCores();
+
+        Clock clock = new Clock().startClock().logTime(
+            "Aggregate process started, number of CPU cores: " + cpuCores + ", " + SystemUtils.getMemoryString() );
+
+        if ( sendingMessage )
+        {
+            clock.logTime( "Start to send messages in outbound" );
+            notifier.notify( taskId, INFO, "Start to send messages in outbound", true );
+
+            sendMessage();
+
+            clock.logTime( "Sending messages in outbound completed" );
+            notifier.notify( taskId, INFO, "Sending messages in outbound completed", true );
+        }
+        else
+        {
+            clock.logTime( "Start to prepare reminder messages" );
+            notifier.clear( taskId ).notify( taskId, "Start to prepare reminder messages" );
+
+            scheduleProgramStageInstanceMessage();
+            scheduleProgramInstanceMessage();
+
+            sendMessage();
+
+            clock.logTime( "Preparing reminder messages completed" );
+            notifier.notify( taskId, INFO, "Preparing reminder messages completed", true );
+        }
+
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private void scheduleProgramStageInstanceMessage()
+    {
+        notifier.notify( taskId, "Start to prepare reminder messages for events" );
+
+        Collection<SchedulingProgramObject> schedulingProgramObjects = programStageInstanceService
+            .getSendMesssageEvents();
+
+        for ( SchedulingProgramObject schedulingProgramObject : schedulingProgramObjects )
+        {
+            String message = schedulingProgramObject.getMessage();
+
+            try
+            {
+                OutboundSms outboundSms = new OutboundSms( message, schedulingProgramObject.getPhoneNumber() );
+                outboundSms.setSender( DHIS_SYSTEM_SENDER );
+                outboundSmsService.saveOutboundSms( outboundSms );
+
+                String sortOrderSql = "SELECT max(sort_order) "
+                    + "FROM programstageinstance_outboundsms where programstageinstanceid="
+                    + schedulingProgramObject.getProgramStageInstanceId();
+                Integer sortOrder = jdbcTemplate.queryForObject( sortOrderSql, Integer.class );
+                if ( sortOrder == null )
+                {
+                    sortOrder = 0;
+                }
+                sortOrder = sortOrder + 1;
+
+                String sql = "INSERT INTO programstageinstance_outboundsms"
+                    + "( programstageinstanceid, outboundsmsid, sort_order) VALUES " + "("
+                    + schedulingProgramObject.getProgramStageInstanceId() + ", " + outboundSms.getId() + ","
+                    + sortOrder + ") ";
+
+                jdbcTemplate.execute( sql );
+
+                notifier.notify( taskId, "Reminder messages for event of " + outboundSms.getRecipients()
+                    + " is created " );
+            }
+            catch ( SmsServiceException e )
+            {
+                message = e.getMessage();
+            }
+        }
+
+        notifier.notify( taskId, INFO, "Preparing reminder messages for events completed", true );
+    }
+
+    private void scheduleProgramInstanceMessage()
+    {
+        notifier.notify( taskId, "Start to prepare reminder messages for enrollements" );
+
+        Collection<SchedulingProgramObject> schedulingProgramObjects = programInstanceService.getScheduleMesssages();
+
+        for ( SchedulingProgramObject schedulingProgramObject : schedulingProgramObjects )
+        {
+            String message = schedulingProgramObject.getMessage();
+            try
+            {
+                OutboundSms outboundSms = new OutboundSms( message, schedulingProgramObject.getPhoneNumber() );
+                outboundSms.setSender( DHIS_SYSTEM_SENDER );
+                outboundSmsService.saveOutboundSms( outboundSms );
+
+                String sortOrderSql = "select max(sort_order) "
+                    + "from programinstance_outboundsms where programinstanceid="
+                    + schedulingProgramObject.getProgramInstanceId();
+                Integer sortOrder = jdbcTemplate.queryForObject( sortOrderSql, Integer.class );
+                if ( sortOrder == null )
+                {
+                    sortOrder = 0;
+                }
+                sortOrder = sortOrder + 1;
+
+                String sql = "INSERT INTO programinstance_outboundsms"
+                    + "( programinstanceid, outboundsmsid, sort_order) VALUES " + "("
+                    + schedulingProgramObject.getProgramInstanceId() + ", " + outboundSms.getId() + "," + sortOrder
+                    + ") ";
+
+                jdbcTemplate.execute( sql );
+
+                notifier.notify( taskId, "Reminder messages for enrollement of " + outboundSms.getRecipients()
+                    + " is created " );
+            }
+            catch ( SmsServiceException e )
+            {
+                message = e.getMessage();
+            }
+        }
+
+        notifier.notify( taskId, INFO, "Sending reminder messages for enrollement completed", true );
+
+    }
+
+    private void sendMessage()
+    {
+        List<OutboundSms> outboundSmsList = outboundSmsService.getOutboundSms( OutboundSmsStatus.OUTBOUND );
+
+        if ( outboundSmsList != null )
+        {
+            for ( OutboundSms outboundSms : outboundSmsList )
+            {
+                outboundSms.setStatus( OutboundSmsStatus.SENT );
+                smsSender.sendMessage( outboundSms, null );
+            }
+        }
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml	2014-03-10 18:36:41 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml	2014-05-16 08:12:25 +0000
@@ -60,6 +60,43 @@
 		parent="abstractRunCaseAggregateConditionTask">
 	</bean>
 	
+	<bean id="org.hisp.dhis.scheduling.ProgramSchedulingManager"
+		class="org.hisp.dhis.scheduling.DefaultProgramSchedulingManager"
+		init-method="scheduleTasks">
+		<property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
+		<property name="scheduler" ref="scheduler" />
+		<property name="tasks">
+			<map>
+				<entry key="scheduleMessage" value-ref="scheduleMessage" />
+				<entry key="sendMessageScheduled" value-ref="sendMessageScheduled" />
+			</map>
+		</property>
+	</bean>
+
+	<bean id="abstractScheduledMessageTask"
+		class="org.hisp.dhis.scheduling.SendScheduledMessageTask">
+		<property name="programStageInstanceService"
+			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+		<property name="outboundSmsService"
+			ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
+		<property name="smsSender" ref="org.hisp.dhis.sms.SmsSender" />
+		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
+		<property name="notifier" ref="notifier" />
+		<property name="jdbcTemplate" ref="jdbcTemplate" />
+	</bean>
+
+	<bean id="sendMessageScheduled"
+		class="org.hisp.dhis.scheduling.SendScheduledMessageTask"
+		parent="abstractScheduledMessageTask">
+		<property name="sendingMessage" value="true" />
+	</bean>
+
+	<bean id="scheduleMessage"
+		class="org.hisp.dhis.scheduling.SendScheduledMessageTask"
+		parent="abstractScheduledMessageTask">
+		<property name="sendingMessage" value="false" />
+	</bean>
+	
 	<!-- DeletionManager -->
 
 	<bean

=== removed directory 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling'
=== removed file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/DefaultProgramSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/DefaultProgramSchedulingManager.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/DefaultProgramSchedulingManager.java	1970-01-01 00:00:00 +0000
@@ -1,139 +0,0 @@
-package org.hisp.dhis.trackedentity.scheduling;
-
-/*
- * Copyright (c) 2004-2014, 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.setting.SystemSettingManager.KEY_SEND_MESSAGE_SCHEDULED_TASKS;
-import static org.hisp.dhis.system.scheduling.Scheduler.STATUS_NOT_STARTED;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.hisp.dhis.setting.SystemSettingManager;
-import org.hisp.dhis.system.scheduling.Scheduler;
-
-/**
- * @author Chau Thu Tran
- *
- * @version DefaultProgramSchedulingManager.java 12:51:02 PM Sep 10, 2012 $
- */
-public class DefaultProgramSchedulingManager implements ProgramSchedulingManager
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private SystemSettingManager systemSettingManager;
-    
-    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
-    {
-        this.systemSettingManager = systemSettingManager;
-    }
-
-    private Scheduler scheduler;
-
-    public void setScheduler( Scheduler scheduler )
-    {
-        this.scheduler = scheduler;
-    }
-
-    private Map<String, Runnable> tasks = new HashMap<String, Runnable>();
-
-    public void setTasks( Map<String, Runnable> tasks )
-    {
-        this.tasks = tasks;
-    }
-
-    // -------------------------------------------------------------------------
-    // SchedulingManager implementation
-    // -------------------------------------------------------------------------
-
-    public void scheduleTasks()
-    {
-        Map<String, String> keyCronMap = getScheduledTasks();
-        
-        for ( String key : keyCronMap.keySet() )
-        {
-            String cron = keyCronMap.get( key );
-            Runnable task = tasks.get( key );
-            
-            if ( cron != null && task != null )
-            {
-                scheduler.scheduleTask( key, task, cron );
-            }
-        }
-    }
-    
-    public void scheduleTasks( Map<String, String> keyCronMap )
-    {
-        systemSettingManager.saveSystemSetting( KEY_SEND_MESSAGE_SCHEDULED_TASKS, new HashMap<String, String>( keyCronMap ) );
-        
-        scheduleTasks();
-    }
-    
-    public void stopTasks()
-    {
-        systemSettingManager.saveSystemSetting( KEY_SEND_MESSAGE_SCHEDULED_TASKS, null );
-        
-        scheduler.stopAllTasks();
-    }
-    
-    public void executeTasks()
-    {
-        Map<String, String> keyCronMap = getScheduledTasks();
-        
-        for ( String key : keyCronMap.keySet() )
-        {
-            Runnable task = tasks.get( key );
-            
-            if ( task != null )
-            {
-                scheduler.executeTask( task );
-            }
-        }
-    }
-    
-    @SuppressWarnings("unchecked")
-    public Map<String, String> getScheduledTasks()
-    {
-        return (Map<String, String>) systemSettingManager.getSystemSetting( KEY_SEND_MESSAGE_SCHEDULED_TASKS, new HashMap<String, String>() );
-    }
-    
-    public String getTaskStatus()
-    {
-        Map<String, String> keyCronMap = getScheduledTasks();
-                
-        if ( keyCronMap.size() == 0 )
-        {
-            return STATUS_NOT_STARTED;
-        }
-        
-        return scheduler.getTaskStatus( keyCronMap.keySet().iterator().next() );
-    }
-}
-

=== removed file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/ProgramSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/ProgramSchedulingManager.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/ProgramSchedulingManager.java	1970-01-01 00:00:00 +0000
@@ -1,53 +0,0 @@
-package org.hisp.dhis.trackedentity.scheduling;
-
-/*
- * Copyright (c) 2004-2014, 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.Map;
-
-/**
- * @author Chau Thu Tran
- *
- * @version ProgramSchedulingManager.java 12:47:57 PM Sep 10, 2012 $
- */
-public interface ProgramSchedulingManager
-{
-    final String TASK_SENDING_MESSAGE = "sendingMessageTask";
-    
-    void scheduleTasks();
-    
-    void scheduleTasks( Map<String, String> keyCronMap );
-    
-    void stopTasks();
-    
-    void executeTasks();
-    
-    Map<String, String> getScheduledTasks();
-    
-    String getTaskStatus();   
-}

=== removed file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/SendScheduledMessageTask.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/SendScheduledMessageTask.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/scheduling/SendScheduledMessageTask.java	1970-01-01 00:00:00 +0000
@@ -1,263 +0,0 @@
-package org.hisp.dhis.trackedentity.scheduling;
-
-/*
- * Copyright (c) 2004-2014, 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.sms.outbound.OutboundSms.DHIS_SYSTEM_SENDER;
-import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
-import java.util.Collection;
-import java.util.List;
-import org.hisp.dhis.program.ProgramInstanceService;
-import org.hisp.dhis.program.ProgramStageInstanceService;
-import org.hisp.dhis.program.SchedulingProgramObject;
-import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.sms.SmsSender;
-import org.hisp.dhis.sms.SmsServiceException;
-import org.hisp.dhis.sms.outbound.OutboundSms;
-import org.hisp.dhis.sms.outbound.OutboundSmsService;
-import org.hisp.dhis.sms.outbound.OutboundSmsStatus;
-import org.hisp.dhis.system.notification.Notifier;
-import org.hisp.dhis.system.util.Clock;
-import org.hisp.dhis.system.util.SystemUtils;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-/**
- * @author Chau Thu Tran
- * 
- * @version SendScheduledMessageTask.java 12:57:53 PM Sep 10, 2012 $
- */
-public class SendScheduledMessageTask
-    implements Runnable
-{
-    private ProgramStageInstanceService programStageInstanceService;
-
-    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
-    {
-        this.programStageInstanceService = programStageInstanceService;
-    }
-
-    private ProgramInstanceService programInstanceService;
-
-    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
-    {
-        this.programInstanceService = programInstanceService;
-    }
-
-    private OutboundSmsService outboundSmsService;
-
-    public void setOutboundSmsService( OutboundSmsService outboundSmsService )
-    {
-        this.outboundSmsService = outboundSmsService;
-    }
-
-    private SmsSender smsSender;
-
-    public void setSmsSender( SmsSender smsSender )
-    {
-        this.smsSender = smsSender;
-    }
-
-    private JdbcTemplate jdbcTemplate;
-
-    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
-    {
-        this.jdbcTemplate = jdbcTemplate;
-    }
-
-    private Notifier notifier;
-
-    public void setNotifier( Notifier notifier )
-    {
-        this.notifier = notifier;
-    }
-
-    // -------------------------------------------------------------------------
-    // Params
-    // -------------------------------------------------------------------------
-
-    private Boolean sendingMessage;
-
-    public void setSendingMessage( Boolean sendingMessage )
-    {
-        this.sendingMessage = sendingMessage;
-    }
-
-    private TaskId taskId;
-
-    public void setTaskId( TaskId taskId )
-    {
-        this.taskId = taskId;
-    }
-
-    // -------------------------------------------------------------------------
-    // Runnable implementation
-    // -------------------------------------------------------------------------
-
-    @Override
-    public void run()
-    {
-        final int cpuCores = SystemUtils.getCpuCores();
-
-        Clock clock = new Clock().startClock().logTime(
-            "Aggregate process started, number of CPU cores: " + cpuCores + ", " + SystemUtils.getMemoryString() );
-
-        if ( sendingMessage )
-        {
-            clock.logTime( "Start to send messages in outbound" );
-            notifier.notify( taskId, INFO, "Start to send messages in outbound", true );
-
-            sendMessage();
-
-            clock.logTime( "Sending messages in outbound completed" );
-            notifier.notify( taskId, INFO, "Sending messages in outbound completed", true );
-        }
-        else
-        {
-            clock.logTime( "Start to prepare reminder messages" );
-            notifier.clear( taskId ).notify( taskId, "Start to prepare reminder messages" );
-
-            scheduleProgramStageInstanceMessage();
-            scheduleProgramInstanceMessage();
-
-            sendMessage();
-
-            clock.logTime( "Preparing reminder messages completed" );
-            notifier.notify( taskId, INFO, "Preparing reminder messages completed", true );
-        }
-
-    }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private void scheduleProgramStageInstanceMessage()
-    {
-        notifier.notify( taskId, "Start to prepare reminder messages for events" );
-
-        Collection<SchedulingProgramObject> schedulingProgramObjects = programStageInstanceService
-            .getSendMesssageEvents();
-
-        for ( SchedulingProgramObject schedulingProgramObject : schedulingProgramObjects )
-        {
-            String message = schedulingProgramObject.getMessage();
-
-            try
-            {
-                OutboundSms outboundSms = new OutboundSms( message, schedulingProgramObject.getPhoneNumber() );
-                outboundSms.setSender( DHIS_SYSTEM_SENDER );
-                outboundSmsService.saveOutboundSms( outboundSms );
-
-                String sortOrderSql = "SELECT max(sort_order) "
-                    + "FROM programstageinstance_outboundsms where programstageinstanceid="
-                    + schedulingProgramObject.getProgramStageInstanceId();
-                Integer sortOrder = jdbcTemplate.queryForObject( sortOrderSql, Integer.class );
-                if ( sortOrder == null )
-                {
-                    sortOrder = 0;
-                }
-                sortOrder = sortOrder + 1;
-
-                String sql = "INSERT INTO programstageinstance_outboundsms"
-                    + "( programstageinstanceid, outboundsmsid, sort_order) VALUES " + "("
-                    + schedulingProgramObject.getProgramStageInstanceId() + ", " + outboundSms.getId() + ","
-                    + sortOrder + ") ";
-
-                jdbcTemplate.execute( sql );
-
-                notifier.notify( taskId, "Reminder messages for event of " + outboundSms.getRecipients()
-                    + " is created " );
-            }
-            catch ( SmsServiceException e )
-            {
-                message = e.getMessage();
-            }
-        }
-
-        notifier.notify( taskId, INFO, "Preparing reminder messages for events completed", true );
-    }
-
-    private void scheduleProgramInstanceMessage()
-    {
-        notifier.notify( taskId, "Start to prepare reminder messages for enrollements" );
-
-        Collection<SchedulingProgramObject> schedulingProgramObjects = programInstanceService.getScheduleMesssages();
-
-        for ( SchedulingProgramObject schedulingProgramObject : schedulingProgramObjects )
-        {
-            String message = schedulingProgramObject.getMessage();
-            try
-            {
-                OutboundSms outboundSms = new OutboundSms( message, schedulingProgramObject.getPhoneNumber() );
-                outboundSms.setSender( DHIS_SYSTEM_SENDER );
-                outboundSmsService.saveOutboundSms( outboundSms );
-
-                String sortOrderSql = "select max(sort_order) "
-                    + "from programinstance_outboundsms where programinstanceid="
-                    + schedulingProgramObject.getProgramInstanceId();
-                Integer sortOrder = jdbcTemplate.queryForObject( sortOrderSql, Integer.class );
-                if ( sortOrder == null )
-                {
-                    sortOrder = 0;
-                }
-                sortOrder = sortOrder + 1;
-
-                String sql = "INSERT INTO programinstance_outboundsms"
-                    + "( programinstanceid, outboundsmsid, sort_order) VALUES " + "("
-                    + schedulingProgramObject.getProgramInstanceId() + ", " + outboundSms.getId() + "," + sortOrder
-                    + ") ";
-
-                jdbcTemplate.execute( sql );
-
-                notifier.notify( taskId, "Reminder messages for enrollement of " + outboundSms.getRecipients()
-                    + " is created " );
-            }
-            catch ( SmsServiceException e )
-            {
-                message = e.getMessage();
-            }
-        }
-
-        notifier.notify( taskId, INFO, "Sending reminder messages for enrollement completed", true );
-
-    }
-
-    private void sendMessage()
-    {
-        List<OutboundSms> outboundSmsList = outboundSmsService.getOutboundSms( OutboundSmsStatus.OUTBOUND );
-
-        if ( outboundSmsList != null )
-        {
-            for ( OutboundSms outboundSms : outboundSmsList )
-            {
-                outboundSms.setStatus( OutboundSmsStatus.SENT );
-                smsSender.sendMessage( outboundSms, null );
-            }
-        }
-    }
-}

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-05-13 12:54:58 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml	2014-05-16 08:12:25 +0000
@@ -312,45 +312,6 @@
 		<property name="sessionFactory" ref="sessionFactory" />
 	</bean>
 
-	<!-- Scheduling -->
-
-	<bean id="org.hisp.dhis.trackedentity.scheduling.ProgramSchedulingManager"
-		class="org.hisp.dhis.trackedentity.scheduling.DefaultProgramSchedulingManager"
-		init-method="scheduleTasks">
-		<property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
-		<property name="scheduler" ref="scheduler" />
-		<property name="tasks">
-			<map>
-				<entry key="scheduleMessage" value-ref="scheduleMessage" />
-				<entry key="sendMessageScheduled" value-ref="sendMessageScheduled" />
-			</map>
-		</property>
-	</bean>
-
-	<bean id="abstractScheduledMessageTask"
-		class="org.hisp.dhis.trackedentity.scheduling.SendScheduledMessageTask">
-		<property name="programStageInstanceService"
-			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
-		<property name="outboundSmsService"
-			ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
-		<property name="smsSender" ref="org.hisp.dhis.sms.SmsSender" />
-		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
-		<property name="notifier" ref="notifier" />
-		<property name="jdbcTemplate" ref="jdbcTemplate" />
-	</bean>
-
-	<bean id="sendMessageScheduled"
-		class="org.hisp.dhis.trackedentity.scheduling.SendScheduledMessageTask"
-		parent="abstractScheduledMessageTask">
-		<property name="sendingMessage" value="true" />
-	</bean>
-
-	<bean id="scheduleMessage"
-		class="org.hisp.dhis.trackedentity.scheduling.SendScheduledMessageTask"
-		parent="abstractScheduledMessageTask">
-		<property name="sendingMessage" value="false" />
-	</bean>
-
 	<!-- TrackedEntityForm -->
 
 	<bean id="org.hisp.dhis.trackedentity.TrackedEntityFormService"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml	2014-05-14 15:14:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml	2014-05-16 08:12:25 +0000
@@ -963,7 +963,7 @@
 		scope="prototype">
 		<property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
 		<property name="schedulingManager"
-			ref="org.hisp.dhis.trackedentity.scheduling.ProgramSchedulingManager" />
+			ref="org.hisp.dhis.scheduling.ProgramSchedulingManager" />
 	</bean>
 
 	<bean
@@ -972,7 +972,7 @@
 		scope="prototype">
 		<property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
 		<property name="schedulingManager"
-			ref="org.hisp.dhis.trackedentity.scheduling.ProgramSchedulingManager" />
+			ref="org.hisp.dhis.scheduling.ProgramSchedulingManager" />
 		<property name="notifier" ref="notifier" />
 		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 		<property name="sendMessageScheduled" ref="sendMessageScheduled" />