← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13835: Fixed wrong logic in DefaultSmsSender

 

------------------------------------------------------------
revno: 13835
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-01-24 00:32:51 +0200
message:
  Fixed wrong logic in DefaultSmsSender
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DefaultSmsSender.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.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-core/src/main/java/org/hisp/dhis/sms/DefaultSmsSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DefaultSmsSender.java	2013-12-13 08:26:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DefaultSmsSender.java	2014-01-23 22:32:51 +0000
@@ -86,24 +86,12 @@
     public String sendMessage( OutboundSms sms, String gatewayId )
         throws SmsServiceException
     {
-        String resultMessage = null;
-        if ( !transportService.isEnabled() )
+        if ( transportService == null || !transportService.isEnabled() )
         {
             throw new SmsServiceNotEnabledException();
         }
 
-        if ( transportService != null )
-        {
-            // Disable wasted messsage check due to incorrect detection
-            // resultMessage = isWastedSMS( sms );
-            // if ( resultMessage == null )
-
-            resultMessage = transportService.sendMessage( sms, gatewayId );
-
-            return resultMessage;
-        }
-
-        return "outboundsms_saved";
+        return transportService.sendMessage( sms, gatewayId );
     }
 
     @Transactional
@@ -111,20 +99,12 @@
     public String sendMessage( OutboundSms sms )
         throws SmsServiceException
     {
-        // String message = null;
-        if ( !transportService.isEnabled() )
+        if ( transportService == null || !transportService.isEnabled() )
         {
             throw new SmsServiceNotEnabledException();
         }
 
-        if ( transportService != null )
-        {
-            return transportService.sendMessage( sms, transportService.getDefaultGateway() );
-        }
-        else
-        {
-            return "outboundsms_saved";
-        }
+        return transportService.sendMessage( sms, transportService.getDefaultGateway() );
     }
 
     @Transactional
@@ -132,19 +112,14 @@
     public String sendMessage( String message, String phoneNumber )
         throws SmsServiceException
     {
-        if ( !transportService.isEnabled() )
+        if ( transportService == null || !transportService.isEnabled() )
         {
             throw new SmsServiceNotEnabledException();
         }
 
-        if ( transportService != null )
-        {
-            message = createMessage( null, message, currentUserService.getCurrentUser() );
-            OutboundSms sms = new OutboundSms( message, phoneNumber );
-            return sendMessage( sms );
-        }
-
-        return "outboundsms_saved";
+        message = createMessage( null, message, currentUserService.getCurrentUser() );
+        OutboundSms sms = new OutboundSms( message, phoneNumber );
+        return sendMessage( sms );
     }
 
     @Transactional
@@ -189,7 +164,7 @@
 
             Set<String> phoneNumbers = null;
 
-            if ( transportService != null || transportService.isEnabled() )
+            if ( transportService != null && transportService.isEnabled() )
             {
                 phoneNumbers = getRecipientsPhoneNumber( toSendList );
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java	2013-11-14 09:51:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsMessageSender.java	2014-01-23 22:32:51 +0000
@@ -130,43 +130,33 @@
 
             Set<String> phoneNumbers = null;
 
-            if ( outboundSmsTransportService != null || outboundSmsTransportService.isEnabled() )
+            phoneNumbers = getRecipientsPhoneNumber( toSendList );
+
+            text = createMessage( subject, text, sender );
+
+            // Bulk is limited in sending long SMS, need to cut into small
+            // pieces
+            if ( outboundSmsTransportService.getGatewayMap().get( "bulk_gw" ) != null
+                && outboundSmsTransportService.getGatewayMap().get( "bulk_gw" ).equals( gatewayId ) )
             {
-                phoneNumbers = getRecipientsPhoneNumber( toSendList );
-
-                text = createMessage( subject, text, sender );
-
-                // Bulk is limited in sending long SMS, need to cut into small
-                // pieces
-                if ( outboundSmsTransportService.getGatewayMap().get( "bulk_gw" ) != null
-                    && outboundSmsTransportService.getGatewayMap().get( "bulk_gw" ).equals( gatewayId ) )
-                {
-                    // Check if text contain any specific unicode character
-                    for ( char each : text.toCharArray() )
-                    {
-                        if ( !Character.UnicodeBlock.of( each ).equals( UnicodeBlock.BASIC_LATIN ) )
-                        {
-                            MAX_CHAR = 40;
-                            break;
-                        }
-                    }
-                    if ( text.length() > MAX_CHAR )
-                    {
-                        List<String> splitTextList = new ArrayList<String>();
-                        splitTextList = splitLongUnicodeString( text, splitTextList );
-                        for ( String each : splitTextList )
-                        {
-                            if ( !phoneNumbers.isEmpty() && phoneNumbers.size() > 0 )
-                            {
-                                message = sendMessage( each, phoneNumbers, gatewayId );
-                            }
-                        }
-                    }
-                    else
+                // Check if text contain any specific unicode character
+                for ( char each : text.toCharArray() )
+                {
+                    if ( !Character.UnicodeBlock.of( each ).equals( UnicodeBlock.BASIC_LATIN ) )
+                    {
+                        MAX_CHAR = 40;
+                        break;
+                    }
+                }
+                if ( text.length() > MAX_CHAR )
+                {
+                    List<String> splitTextList = new ArrayList<String>();
+                    splitTextList = splitLongUnicodeString( text, splitTextList );
+                    for ( String each : splitTextList )
                     {
                         if ( !phoneNumbers.isEmpty() && phoneNumbers.size() > 0 )
                         {
-                            message = sendMessage( text, phoneNumbers, gatewayId );
+                            message = sendMessage( each, phoneNumbers, gatewayId );
                         }
                     }
                 }
@@ -178,6 +168,13 @@
                     }
                 }
             }
+            else
+            {
+                if ( !phoneNumbers.isEmpty() && phoneNumbers.size() > 0 )
+                {
+                    message = sendMessage( text, phoneNumbers, gatewayId );
+                }
+            }
         }
 
         return message;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java	2014-01-23 22:32:51 +0000
@@ -70,7 +70,7 @@
 
     private final String SMPP_GATEWAY = "smpp_gw";
 
-    public static Map<String, String> gatewayMap = new HashMap<String, String>();
+    public Map<String, String> gatewayMap = new HashMap<String, String>();
 
     private GateWayFactory gatewayFactory = new GateWayFactory();