← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8107: Auto-send SMS (WIP).

 

------------------------------------------------------------
revno: 8107
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-09-17 10:32:13 +0700
message:
  Auto-send SMS (WIP).
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ExecuteSendMessageAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/DefaultProgramSchedulingManager.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml
  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/updateProgramStageForm.vm


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

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java	2012-09-12 04:14:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java	2012-09-17 03:32:13 +0000
@@ -34,6 +34,8 @@
 
 public class OutboundSms
 {
+    public static final String DHIS_SYSTEM_SENDER = "DHIS-System";
+
     private int id;
 
     private String sender;

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/DefaultProgramSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/DefaultProgramSchedulingManager.java	2012-09-10 10:28:33 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/DefaultProgramSchedulingManager.java	2012-09-17 03:32:13 +0000
@@ -43,7 +43,6 @@
  */
 public class DefaultProgramSchedulingManager implements ProgramSchedulingManager
 {
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java	2012-09-14 09:41:13 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java	2012-09-17 03:32:13 +0000
@@ -28,6 +28,7 @@
 package org.hisp.dhis.patient.scheduling;
 
 import static org.hisp.dhis.setting.SystemSettingManager.KEY_SEND_MESSAGE_GATEWAY;
+import static org.hisp.dhis.sms.outbound.OutboundSms.DHIS_SYSTEM_SENDER;
 
 import java.util.Collection;
 import java.util.List;
@@ -48,9 +49,7 @@
  */
 public class SendScheduledMessageTask
     implements Runnable
-{
-    private final String DHIS_SYSTEM_SENDER = "DHIS-System";
-
+{   
     private SystemSettingManager systemSettingManager;
 
     public void setSystemSettingManager( SystemSettingManager systemSettingManager )
@@ -147,7 +146,7 @@
 
                     String sql = "INSERT INTO programstageinstance_outboundsms"
                         + "( programstageinstanceid, outboundsmsid, sort_order) VALUES " + "("
-                        + schedulingProgramObject.getProgramStageInstanceId() + ", " + outboundSms.getId() + ",1) ";
+                        + schedulingProgramObject.getProgramStageInstanceId() + ", " + outboundSms.getId() + "," + ( System.currentTimeMillis() / 1000 ) + ") ";
 
                     jdbcTemplate.execute( sql );
                 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-09-15 09:55:28 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2012-09-17 03:32:13 +0000
@@ -279,7 +279,8 @@
             + " INNER JOIN programstageinstance psi " 
             + "         ON psi.programinstanceid=pi.programinstanceid "
             + " INNER JOIN program pg " 
-            + "         ON pg.programid=pi.programid " + " INNER JOIN programstage ps "
+            + "         ON pg.programid=pi.programid " 
+            + " INNER JOIN programstage ps "
             + "         ON ps.programstageid=psi.programstageid "
             + " INNER JOIN organisationunit org "
             + "         ON org.organisationunitid = p.organisationunitid "

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ExecuteSendMessageAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ExecuteSendMessageAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/schedule/ExecuteSendMessageAction.java	2012-09-17 03:32:13 +0000
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2004-2009, 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.
+ */
+
+package org.hisp.dhis.patient.action.schedule;
+
+import static org.hisp.dhis.setting.SystemSettingManager.KEY_SEND_MESSAGE_GATEWAY;
+import static org.hisp.dhis.sms.outbound.OutboundSms.DHIS_SYSTEM_SENDER;
+
+import java.util.Collection;
+
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.program.SchedulingProgramObject;
+import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.sms.SmsServiceException;
+import org.hisp.dhis.sms.outbound.OutboundSms;
+import org.hisp.dhis.sms.outbound.OutboundSmsService;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version ExecuteSendMessageAction.java 9:14:46 AM Sep 17, 2012 $
+ */
+public class ExecuteSendMessageAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SystemSettingManager systemSettingManager;
+
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
+    }
+
+    private ProgramStageInstanceService programStageInstanceService;
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+    private OutboundSmsService outboundSmsService;
+
+    public void setOutboundSmsService( OutboundSmsService outboundSmsService )
+    {
+        this.outboundSmsService = outboundSmsService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+    {
+        String gatewayId = (String) systemSettingManager.getSystemSetting( KEY_SEND_MESSAGE_GATEWAY );
+
+        if ( gatewayId != null )
+        {
+            Collection<SchedulingProgramObject> schedulingProgramObjects = programStageInstanceService
+                .getSendMesssageEvents();
+
+            for ( SchedulingProgramObject schedulingProgramObject : schedulingProgramObjects )
+            {
+                String message = schedulingProgramObject.getMessage();
+
+                String phoneNumber = schedulingProgramObject.getPhoneNumber();
+
+                if ( phoneNumber != null && !phoneNumber.isEmpty() )
+                {
+                    try
+                    {
+                        OutboundSms outboundSms = new OutboundSms( message, phoneNumber );
+                        outboundSms.setSender( DHIS_SYSTEM_SENDER );
+                        outboundSmsService.sendMessage( outboundSms, gatewayId );
+
+                        String sql = "INSERT INTO programstageinstance_outboundsms"
+                            + "( programstageinstanceid, outboundsmsid, sort_order) VALUES " + "("
+                            + schedulingProgramObject.getProgramStageInstanceId() + ", " + outboundSms.getId() + "," + ( System.currentTimeMillis() / 1000 ) + ") ";
+
+                        jdbcTemplate.execute( sql );
+                    }
+                    catch ( SmsServiceException e )
+                    {
+                        message = e.getMessage();
+                    }
+                }
+            }
+        }
+        
+        return SUCCESS;
+    }
+    
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2012-09-11 01:58:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2012-09-17 03:32:13 +0000
@@ -894,5 +894,14 @@
  		 <property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
  		 <property name="schedulingManager" ref="org.hisp.dhis.patient.scheduling.ProgramSchedulingManager" />
  	</bean>
+ 	
+ 	<bean id="org.hisp.dhis.patient.action.schedule.ExecuteSendMessageAction"
+		class="org.hisp.dhis.patient.action.schedule.ExecuteSendMessageAction"
+		scope="prototype">
+		<property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
+		<property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+		<property name="jdbcTemplate" ref="jdbcTemplate" />
+		<property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
+	</bean>
 
 </beans>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2012-09-10 10:28:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2012-09-17 03:32:13 +0000
@@ -943,6 +943,12 @@
 				/dhis-web-maintenance-patient/jsonResponseScheduleTasks.vm</result>
 	      <param name="requiredAuthorities">F_SCHEDULING_SEND_MESSAGE</param>
 	    </action>
+	    
+	    <action name="executeSendMessage" class="org.hisp.dhis.patient.action.schedule.ExecuteSendMessageAction">
+	      <result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+	      <param name="requiredAuthorities">F_SCHEDULING_SEND_MESSAGE</param>
+	    </action>
 		
 	</package>
 </struts>

=== 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-09-11 03:54:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/scheduling.js	2012-09-17 03:32:13 +0000
@@ -18,10 +18,12 @@
 
 function executeTasks()
 {
-	$.post( 'scheduleTasks.action',{
+	$.post( 'executeSendMessage.action',{
 		execute:true,
 		schedule: false,
 		gateWayId: getFieldValue("gatewayId"),
 		timeSendingMessage: getFieldValue("timeSendingMessage")
+	}, function( json ){
+		setMessage(i18n_scheduling_is + " " + json.scheduleTasks.status);
 	});
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm	2012-09-11 03:54:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm	2012-09-17 03:32:13 +0000
@@ -57,7 +57,7 @@
 				<td><i>($i18n.getString("negative_numbers") = $i18n.getString( "days_before_due_date" ))</i></td>
 			</tr>
 		
-		<tr><td>&nbsp;</td></tr>
+			<tr><td>&nbsp;</td></tr>
 		
 			<tr>
 				<td>$i18n.getString( "params" )</td>