← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11236: SMS, centralized method

 

------------------------------------------------------------
revno: 11236
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-06-19 20:43:51 +0200
message:
  SMS, centralized method
modified:
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.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-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java	2013-06-19 18:28:57 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java	2013-06-19 18:43:51 +0000
@@ -93,7 +93,7 @@
         {
             for ( InboundMessage each : msgList )
             {
-                IncomingSms incomingSms = tranferToIncomingSms( each );
+                IncomingSms incomingSms = convertToIncomingSms( each );
 
                 result.add( incomingSms );
             }
@@ -121,6 +121,7 @@
         {
             e.printStackTrace();
         }
+        
         return msgList;
     }
 
@@ -183,28 +184,18 @@
         return incomingSmsStore.getSmsByStatus( status );
     }
 
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private IncomingSms tranferToIncomingSms( InboundMessage inboundMessage )
+    @Override
+    public IncomingSms convertToIncomingSms( InboundMessage message )
     {
         IncomingSms incomingSms = new IncomingSms();
 
-        incomingSms.setOriginator( inboundMessage.getOriginator() );
-
+        incomingSms.setOriginator( message.getOriginator() );
         incomingSms.setEncoding( SmsMessageEncoding.ENC7BIT );
-
-        incomingSms.setSentDate( inboundMessage.getDate() );
-
-        incomingSms.setReceivedDate( inboundMessage.getDate() );
-
-        incomingSms.setText( inboundMessage.getText() );
-
-        incomingSms.setGatewayId( inboundMessage.getGatewayId() );
-
+        incomingSms.setSentDate( message.getDate() );
+        incomingSms.setReceivedDate( message.getDate() );
+        incomingSms.setText( message.getText() );
+        incomingSms.setGatewayId( message.getGatewayId() );
         incomingSms.setStatus( SmsMessageStatus.PROCESSED );
-
         incomingSms.setStatusMessage( "imported" );
 
         return incomingSms;

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java	2013-05-21 07:01:29 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java	2013-06-19 18:43:51 +0000
@@ -1,11 +1,5 @@
 package org.hisp.dhis.sms.incoming;
 
-import java.util.Collection;
-import java.util.List;
-
-import org.hisp.dhis.sms.queue.MessageQueue;
-import org.smslib.InboundMessage;
-
 /*
  * Copyright (c) 2011, University of Oslo
  * All rights reserved.
@@ -33,6 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+import java.util.List;
+
+import org.hisp.dhis.sms.queue.MessageQueue;
+import org.smslib.InboundMessage;
 
 /**
  * Service providing support for retrieving incoming SMSes.
@@ -67,4 +66,6 @@
     public void setIncomingSmsQueue( MessageQueue incomingSmsQueue );
     
     Collection<IncomingSms> getSmsByStatus( SmsMessageStatus status );
+    
+    IncomingSms convertToIncomingSms( InboundMessage message );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java	2012-11-20 13:34:03 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java	2013-06-19 18:43:51 +0000
@@ -53,5 +53,4 @@
     void delete( IncomingSms incomingSms);
     
     Collection<IncomingSms> getAllUnparsedSmses();
-
 }

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java	2013-06-19 17:22:47 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java	2013-06-19 18:43:51 +0000
@@ -35,34 +35,26 @@
 public class SMPPInboundNotification
     implements IInboundMessageNotification
 {    
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
     private IncomingSmsService incomingSmsService;
 
+    public void setIncomingSmsService( IncomingSmsService incomingSmsService )
+    {
+        this.incomingSmsService = incomingSmsService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation
+    // -------------------------------------------------------------------------
+
     @Override
-    public void process( AGateway gateway, MessageTypes msgType, InboundMessage msg )
+    public void process( AGateway gateway, MessageTypes msgType, InboundMessage message )
     {
-        IncomingSms incomingSms = new IncomingSms();
-
-        incomingSms.setOriginator( msg.getOriginator() );
-
-        incomingSms.setEncoding( SmsMessageEncoding.ENC7BIT );
-
-        incomingSms.setSentDate( msg.getDate() );
-
-        incomingSms.setReceivedDate( msg.getDate() );
-
-        incomingSms.setText( msg.getText() );
-
-        incomingSms.setGatewayId( msg.getGatewayId() );
-
-        incomingSms.setStatus( SmsMessageStatus.PROCESSED );
-
-        incomingSms.setStatusMessage( "imported" );
+        IncomingSms incomingSms = incomingSmsService.convertToIncomingSms( message );
         
         incomingSmsService.save( incomingSms );
     }
-
-    public void setIncomingSmsService( IncomingSmsService incomingSmsService )
-    {
-        this.incomingSmsService = incomingSmsService;
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java	2013-04-22 06:42:29 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java	2013-06-19 18:43:51 +0000
@@ -36,13 +36,13 @@
 import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.Map;
+
 import org.apache.commons.lang.StringUtils;
 import org.smslib.AGateway;
 import org.smslib.GatewayException;
 import org.smslib.OutboundMessage;
 import org.smslib.TimeoutException;
 import org.smslib.helper.Logger;
-import org.springframework.web.client.RestTemplate;
 
 /**
  * Simplistic http gateway sending smses through a get to a url constructed from
@@ -81,8 +81,6 @@
 
     private static final String MESSAGE = "message";
 
-    RestTemplate restTemplate = new RestTemplate();
-
     private Map<String, String> parameters;
 
     private String urlTemplate;
@@ -125,6 +123,7 @@
         requestParameters.put( MESSAGE, msg.getText() );
 
         String sender = msg.getFrom();
+        
         if ( sender != null )
         {
             Logger.getInstance().logDebug( "Adding sender " + sender, null, getGatewayId() );
@@ -133,6 +132,7 @@
         try
         {
             String urlString = urlTemplate;
+            
             for ( String key : requestParameters.keySet() )
             {
                 if ( requestParameters.get( key ) != null )
@@ -141,11 +141,13 @@
                         URLEncoder.encode( requestParameters.get( key ), "UTF-8" ) );
                 }
             }
+            
             Logger.getInstance().logInfo( "RequestURL: " + urlString, null, getGatewayId() );
             URL requestURL = new URL( urlString );
             URLConnection conn = requestURL.openConnection();
             BufferedReader reader = new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
             String line, response = "";
+            
             while ( (line = reader.readLine()) != null )
             {
                 response += line;
@@ -168,7 +170,6 @@
         }
 
         return true;
-
     }
 
     @Override