← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11629: apply MessageService to send message

 

------------------------------------------------------------
revno: 11629
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Mon 2013-08-12 14:30:03 +0700
message:
  apply MessageService to send message
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java
  dhis-2/dhis-services/dhis-service-core/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
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java	2013-08-12 03:29:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DHISMessageAlertListener.java	2013-08-12 07:30:03 +0000
@@ -33,11 +33,7 @@
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
-import org.hisp.dhis.message.Message;
-import org.hisp.dhis.message.MessageConversation;
-import org.hisp.dhis.message.MessageConversationStore;
-import org.hisp.dhis.message.MessageSender;
-import org.hisp.dhis.message.UserMessage;
+import org.hisp.dhis.message.MessageService;
 import org.hisp.dhis.sms.incoming.IncomingSms;
 import org.hisp.dhis.sms.incoming.IncomingSmsListener;
 import org.hisp.dhis.sms.parse.ParserType;
@@ -52,16 +48,15 @@
 public class DHISMessageAlertListener
     implements IncomingSmsListener
 {
-    private SmsSender smsSender;
-
-    private MessageSender emailMessageSender;
-
-    private MessageConversationStore messageConversationStore;
 
     private SMSCommandService smsCommandService;
 
     private UserService userService;
 
+    private MessageService messageService;
+
+    private SmsMessageSender smsMessageSender;
+
     public SMSCommandService getSmsCommandService()
     {
         return smsCommandService;
@@ -71,7 +66,7 @@
     {
         this.smsCommandService = smsCommandService;
     }
-    
+
     @Transactional
     @Override
     public boolean accept( IncomingSms sms )
@@ -90,7 +85,7 @@
 
         return smsCommandService.getSMSCommand( commandString, ParserType.ALERT_PARSER ) != null;
     }
-    
+
     @Transactional
     @Override
     public void receive( IncomingSms sms )
@@ -136,32 +131,12 @@
                 Set<User> receivers = new HashSet<User>( userGroup.getMembers() );
 
                 // forward to user group by SMS
-                smsSender.sendMessage( smsCommand.getName(), message, sender, receivers, true );
-
-                // forward to user group by E-mail
-                emailMessageSender.sendMessage( smsCommand.getName(), message, sender, receivers, false );
-
-                // forward to user group by dhis message
-                if ( sender != null )
-                {
-                    receivers.add( sender );
-                }
-
-                MessageConversation conversation = new MessageConversation( smsCommand.getName(), sender );
-
-                conversation.addMessage( new Message( message, null, sender ) );
-
-                for ( User receiver : receivers )
-                {
-                    boolean read = receiver != null && receiver.equals( sender );
-
-                    conversation.addUserMessage( new UserMessage( receiver, read ) );
-                }
-                messageConversationStore.save( conversation );
+                messageService.sendMessage( smsCommand.getName(), message, null, receivers, sender, false, false );
+
                 // confirm SMS was received and forwarded completely
                 Set<User> feedbackList = new HashSet<User>();
                 feedbackList.add( sender );
-                smsSender.sendMessage( smsCommand.getName(), smsCommand.getReceivedMessage(), null,
+                smsMessageSender.sendMessage( smsCommand.getName(), smsCommand.getReceivedMessage(), null,
                     feedbackList, true );
             }
             else if ( users == null || users.size() == 0 )
@@ -173,36 +148,6 @@
         }
     }
 
-    public SmsSender getSmsSender()
-    {
-        return smsSender;
-    }
-
-    public void setSmsSender( SmsSender smsSender )
-    {
-        this.smsSender = smsSender;
-    }
-
-    public MessageSender getEmailMessageSender()
-    {
-        return emailMessageSender;
-    }
-
-    public void setEmailMessageSender( MessageSender emailMessageSender )
-    {
-        this.emailMessageSender = emailMessageSender;
-    }
-
-    public MessageConversationStore getMessageConversationStore()
-    {
-        return messageConversationStore;
-    }
-
-    public void setMessageConversationStore( MessageConversationStore messageConversationStore )
-    {
-        this.messageConversationStore = messageConversationStore;
-    }
-
     public UserService getUserService()
     {
         return userService;
@@ -212,4 +157,24 @@
     {
         this.userService = userService;
     }
+
+    public MessageService getMessageService()
+    {
+        return messageService;
+    }
+
+    public void setMessageService( MessageService messageService )
+    {
+        this.messageService = messageService;
+    }
+
+    public SmsMessageSender getSmsMessageSender()
+    {
+        return smsMessageSender;
+    }
+
+    public void setSmsMessageSender( SmsMessageSender smsMessageSender )
+    {
+        this.smsMessageSender = smsMessageSender;
+    }
 }

=== 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-08-12 03:29:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-08-12 07:30:03 +0000
@@ -771,8 +771,8 @@
   
   <bean id="org.hisp.dhis.sms.DHISMessageAlertListener" class="org.hisp.dhis.sms.DHISMessageAlertListener">
     <property name="smsCommandService" ref="smsCommandService" />
-    <property name="smsSender" ref="org.hisp.dhis.sms.SmsSender" />
-    <property name="messageConversationStore" ref="org.hisp.dhis.message.MessageConversationStore" />
+    <property name="messageService" ref="org.hisp.dhis.message.MessageService" />
+    <property name="smsMessageSender" ref="org.hisp.dhis.sms.SmsMessageSender" />
     <property name="userService" ref="org.hisp.dhis.user.UserService" />
   </bean>