← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12923: run sending sms in Task to prevent time-out issue

 

------------------------------------------------------------
revno: 12923
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Tue 2013-11-12 15:46:01 +0700
message:
  run sending sms in Task to prevent time-out issue
added:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/task/
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/task/SendSmsTask.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DatabaseSupportedInternalMemoryMessageQueue.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/ProcessingSendSMSAction.java
  dhis-2/dhis-web/dhis-web-sms/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-sms/src/main/webapp/dhis-web-sms/javascript/sendSMS.js


--
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/scheduling/TaskCategory.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java	2013-10-23 22:03:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskCategory.java	2013-11-12 08:46:01 +0000
@@ -42,5 +42,6 @@
     METADATA_IMPORT,
     METADATA_EXPORT,
     AGGREGATE_QUERY_BUILDER,
-    SENDING_REMINDER_MESSAGE
+    SENDING_REMINDER_MESSAGE,
+    SENDING_SMS
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java	2013-10-29 10:27:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java	2013-11-12 08:46:01 +0000
@@ -69,7 +69,7 @@
 
 public class DataValueSMSListener
     implements IncomingSmsListener
-{    
+{
     private static final String defaultPattern = "([a-zA-Z]+)\\s*(\\d+)";
 
     private CompleteDataSetRegistrationService registrationService;
@@ -123,7 +123,7 @@
         }
         SMSCommand smsCommand = smsCommandService.getSMSCommand( commandString, ParserType.KEY_VALUE_PARSER );
         Map<String, String> parsedMessage = this.parse( message, smsCommand );
-        
+
         Date date = lookForDate( message );
         String senderPhoneNumber = StringUtils.replace( sms.getOriginator(), "+", "" );
         Collection<OrganisationUnit> orgUnits = getOrganisationUnitsByPhoneNumber( senderPhoneNumber );
@@ -143,7 +143,7 @@
         }
 
         boolean valueStored = false;
-        
+
         for ( SMSCode code : smsCommand.getCodes() )
         {
             if ( parsedMessage.containsKey( code.getCode().toUpperCase() ) )
@@ -234,7 +234,7 @@
         {
             // no date found
         }
-        
+
         return date;
     }
 
@@ -285,7 +285,7 @@
             }
             throw new SMSParserException( messageListingOrgUnits );
         }
-        
+
         return orgUnit;
     }
 
@@ -294,7 +294,7 @@
         Period period;
         period = command.getDataset().getPeriodType().createPeriod();
         CalendarPeriodType cpt = (CalendarPeriodType) period.getPeriodType();
-        
+
         if ( command.isCurrentPeriodUsedForReporting() )
         {
             period = cpt.createPeriod( new Date() );
@@ -390,8 +390,8 @@
     {
         OrganisationUnit orgunit = null;
         User user = null;
-        
-        //-------------------------> Need to be edit 
+
+        // -------------------------> Need to be edit
         for ( User u : userService.getUsersByPhoneNumber( sender ) )
         {
             OrganisationUnit ou = u.getOrganisationUnit();
@@ -416,12 +416,11 @@
             user = u;
         }
         // <-------------------------------------
-        if ( user == null)
+        if ( user == null )
         {
-            throw new SMSParserException(
-            "User is not associated with any orgunit. Please contact your supervisor." );
+            throw new SMSParserException( "User is not associated with any orgunit. Please contact your supervisor." );
         }
-        
+
         return user;
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DatabaseSupportedInternalMemoryMessageQueue.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DatabaseSupportedInternalMemoryMessageQueue.java	2013-09-19 09:51:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DatabaseSupportedInternalMemoryMessageQueue.java	2013-11-12 08:46:01 +0000
@@ -90,4 +90,5 @@
     {
         this.smsStore = smsStore;
     }
+    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java	2013-10-29 10:27:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java	2013-11-12 08:46:01 +0000
@@ -64,7 +64,7 @@
         {
             thread.stopFetching();
         }
-        
+
         thread = null;
     }
 
@@ -104,7 +104,6 @@
         private void fetchAndParseSMS()
         {
             IncomingSms message = messageQueue.get();
-
             while ( message != null )
             {
                 log.info( "Received SMS: " + message.getText() );
@@ -119,7 +118,6 @@
                             return;
                         }
                     }
-                    
                     smsSender.sendMessage( "No command found", message.getOriginator() );
                 }
                 catch ( Exception e )

=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/task'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/task/SendSmsTask.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/task/SendSmsTask.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/task/SendSmsTask.java	2013-11-12 08:46:01 +0000
@@ -0,0 +1,121 @@
+package org.hisp.dhis.sms.task;
+
+import java.util.List;
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.sms.SmsSender;
+import org.hisp.dhis.system.notification.Notifier;
+import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class SendSmsTask
+    implements Runnable
+{
+    @Autowired
+    private SmsSender smsSender;
+
+    @Autowired
+    private Notifier notifier;
+
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private String smsSubject;
+
+    private String text;
+
+    private User currentUser;
+
+    private List<User> recipientsList;
+
+    private String message = "success";
+
+    private TaskId taskId;
+
+    // -------------------------------------------------------------------------
+    // I18n
+    // -------------------------------------------------------------------------
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    @Override
+    public void run()
+    {
+        notifier.notify( taskId, "Sending SMS" );
+        message = smsSender.sendMessage( smsSubject, text, currentUser, recipientsList, false );
+        notifier.notify( taskId, "All Message Sent" );
+    }
+
+    public String getSmsSubject()
+    {
+        return smsSubject;
+    }
+
+    public void setSmsSubject( String smsSubject )
+    {
+        this.smsSubject = smsSubject;
+    }
+
+    public String getText()
+    {
+        return text;
+    }
+
+    public void setText( String text )
+    {
+        this.text = text;
+    }
+
+    public User getCurrentUser()
+    {
+        return currentUser;
+    }
+
+    public void setCurrentUser( User currentUser )
+    {
+        this.currentUser = currentUser;
+    }
+
+    public List<User> getRecipientsList()
+    {
+        return recipientsList;
+    }
+
+    public void setRecipientsList( List<User> recipientsList )
+    {
+        this.recipientsList = recipientsList;
+    }
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public void setMessage( String message )
+    {
+        this.message = message;
+    }
+
+    public TaskId getTaskId()
+    {
+        return taskId;
+    }
+
+    public void setTaskId( TaskId taskId )
+    {
+        this.taskId = taskId;
+    }
+
+    public I18n getI18n()
+    {
+        return i18n;
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-10-31 11:04:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-11-12 08:46:01 +0000
@@ -814,6 +814,8 @@
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
     <property name="userService" ref="org.hisp.dhis.user.UserService" />
   </bean>
+  
+   <bean id="org.hisp.dhis.sms.task.SendSmsTask" class="org.hisp.dhis.sms.task.SendSmsTask"/>
 
   <!-- I18nService -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/ProcessingSendSMSAction.java'
--- dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/ProcessingSendSMSAction.java	2013-10-08 17:16:47 +0000
+++ dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/outcoming/ProcessingSendSMSAction.java	2013-11-12 08:46:01 +0000
@@ -37,8 +37,12 @@
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
-import org.hisp.dhis.sms.SmsSender;
+import org.hisp.dhis.scheduling.TaskCategory;
+import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
+import org.hisp.dhis.sms.task.SendSmsTask;
+import org.hisp.dhis.system.notification.Notifier;
+import org.hisp.dhis.system.scheduling.Scheduler;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserGroup;
@@ -72,13 +76,15 @@
 
     @Autowired
     private OutboundSmsTransportService transportService;
-
-    private SmsSender smsSender;
-
-    public void setSmsSender( SmsSender smsSender )
-    {
-        this.smsSender = smsSender;
-    }
+    
+    @Autowired
+    private Scheduler scheduler;
+
+    @Autowired
+    private Notifier notifier;
+
+    @Autowired
+    private SendSmsTask sendSmsTask;
 
     // -------------------------------------------------------------------------
     // Input & Output
@@ -194,7 +200,6 @@
             }
             // message = messageSender.sendMessage( smsSubject, smsMessage,
             // currentUser, true, recipients, gatewayId );
-            message = smsSender.sendMessage( smsSubject, text, currentUser, recipientsList, false );
         }
         else if ( sendTarget.equals( "userGroup" ) )
         {
@@ -213,12 +218,8 @@
 
                 return ERROR;
             }
-            
-            // message = messageSender.sendMessage( smsSubject, smsMessage,
-            // currentUser, false, group.getMembers(), gatewayId );
-            
-            message = smsSender.sendMessage( smsSubject, text, currentUser, new ArrayList<User>( group.getMembers() ),
-                false );
+
+            recipientsList = new ArrayList<User>( group.getMembers());
         }
         else if ( sendTarget.equals( "user" ) )
         {
@@ -240,8 +241,6 @@
 
                 // message = messageSender.sendMessage( smsSubject, smsMessage,
                 // currentUser, false, users, gatewayId );
-                
-                message = smsSender.sendMessage( smsSubject, text, currentUser, recipientsList, false );
             }
         }
         else if ( sendTarget.equals( "unit" ) )
@@ -262,9 +261,18 @@
 
                 return ERROR;
             }
-
-            message = smsSender.sendMessage( smsSubject, text, currentUser, recipientsList, false );
         }
+        
+        TaskId taskId = new TaskId( TaskCategory.SENDING_SMS, currentUser );
+        notifier.clear( taskId );
+
+        sendSmsTask.setTaskId( taskId );
+        sendSmsTask.setCurrentUser( currentUser );
+        sendSmsTask.setRecipientsList( recipientsList );
+        sendSmsTask.setSmsSubject( smsSubject );
+        sendSmsTask.setText( text );
+        
+        scheduler.executeTask( sendSmsTask );
 
         if ( message != null && !message.equals( "success" ) )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-sms/src/main/resources/META-INF/dhis/beans.xml	2013-09-05 06:05:43 +0000
+++ dhis-2/dhis-web/dhis-web-sms/src/main/resources/META-INF/dhis/beans.xml	2013-11-12 08:46:01 +0000
@@ -16,9 +16,7 @@
     scope="prototype" />
 
   <bean id="org.hisp.dhis.sms.outcoming.ProcessingSendSMSAction"
-    class="org.hisp.dhis.sms.outcoming.ProcessingSendSMSAction" scope="prototype">
-    <property name="smsSender" ref="org.hisp.dhis.sms.SmsSender" />
-  </bean>
+    class="org.hisp.dhis.sms.outcoming.ProcessingSendSMSAction" scope="prototype"/>
 
   <bean id="org.hisp.dhis.sms.outcoming.SearchPatientAction" class="org.hisp.dhis.sms.outcoming.SearchPatientAction"
     scope="prototype" />

=== modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/webapp/dhis-web-sms/javascript/sendSMS.js'
--- dhis-2/dhis-web/dhis-web-sms/src/main/webapp/dhis-web-sms/javascript/sendSMS.js	2013-08-22 08:03:53 +0000
+++ dhis-2/dhis-web/dhis-web-sms/src/main/webapp/dhis-web-sms/javascript/sendSMS.js	2013-11-12 08:46:01 +0000
@@ -80,14 +80,7 @@
 			return;
 		}
 	}
-	else if ( _target == "user" || _target == "unit" )
-	{
-		if ( !isOrgunitSelected )
-		{
-			setHeaderDelayMessage( i18n_please_select_orgunit );
-			return;
-		}
-	}
+	
 	else
 	{
 		if ( hasElements( 'recipients' ) )