← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13186: [mobile] fix bug with wrong SMS status

 

------------------------------------------------------------
revno: 13186
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Tue 2013-12-10 15:37:23 +0700
message:
  [mobile] fix bug with wrong SMS status
modified:
  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/DefaultSmsSender.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.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/DatabaseSupportedInternalMemoryMessageQueue.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DatabaseSupportedInternalMemoryMessageQueue.java	2013-11-12 08:46:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DatabaseSupportedInternalMemoryMessageQueue.java	2013-12-10 08:37:23 +0000
@@ -34,7 +34,6 @@
 
 import org.hisp.dhis.sms.incoming.IncomingSms;
 import org.hisp.dhis.sms.incoming.IncomingSmsStore;
-import org.hisp.dhis.sms.incoming.SmsMessageStatus;
 
 public class DatabaseSupportedInternalMemoryMessageQueue
     implements MessageQueue
@@ -71,7 +70,6 @@
     public void remove( IncomingSms message )
     {
         message.setParsed( true );
-        message.setStatus( SmsMessageStatus.PROCESSED );
         smsStore.update( message );
         queue.remove( message );
     }
@@ -90,5 +88,5 @@
     {
         this.smsStore = smsStore;
     }
-    
+
 }

=== 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-11-14 08:56:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DefaultSmsSender.java	2013-12-10 08:37:23 +0000
@@ -70,7 +70,7 @@
     {
         this.userService = userService;
     }
-    
+
     private OutboundSmsService outboundSmsService;
 
     public void setOutboundSmsService( OutboundSmsService outboundSmsService )
@@ -97,7 +97,7 @@
             resultMessage = isWastedSMS( sms );
             if ( resultMessage == null )
             {
-                resultMessage = transportService.sendMessage( sms, gatewayId ); 
+                resultMessage = transportService.sendMessage( sms, gatewayId );
             }
             return resultMessage;
         }
@@ -110,7 +110,7 @@
     public String sendMessage( OutboundSms sms )
         throws SmsServiceException
     {
-        String message = null;
+        // String message = null;
         if ( !transportService.isEnabled() )
         {
             throw new SmsServiceNotEnabledException();
@@ -118,19 +118,14 @@
 
         if ( transportService != null )
         {
-            message = isWastedSMS( sms );
-            if ( message == null )
-            {
-                message = transportService.sendMessage( sms, transportService.getDefaultGateway() );
-            }
-            return message;
+            return transportService.sendMessage( sms, transportService.getDefaultGateway() );
         }
         else
         {
             return "outboundsms_saved";
         }
     }
-    
+
     @Transactional
     @Override
     public String sendMessage( String message, String phoneNumber )
@@ -150,7 +145,7 @@
 
         return "outboundsms_saved";
     }
-    
+
     @Transactional
     @Override
     public String sendMessage( String subject, String text, User sender, List<User> users, boolean forceSend )
@@ -190,7 +185,6 @@
             {
                 toSendList.addAll( users );
             }
-            
 
             Set<String> phoneNumbers = null;
 
@@ -300,7 +294,7 @@
         sms.setRecipients( recipients );
         message = isWastedSMS( sms );
 
-        if( message == null )
+        if ( message == null )
         {
             try
             {
@@ -313,7 +307,7 @@
                 log.warn( "Unable to send message through sms: " + sms, e );
             }
         }
-        
+
         return message;
     }
 
@@ -343,13 +337,14 @@
             return splitLongUnicodeString( secondTempString, result );
         }
     }
-    
+
     public String isWastedSMS( OutboundSms sms )
     {
         List<OutboundSms> listOfRecentOutboundSms = outboundSmsService.getAllOutboundSms( 0, 10 );
-        for( OutboundSms each: listOfRecentOutboundSms )
+        for ( OutboundSms each : listOfRecentOutboundSms )
         {
-            if( each.getRecipients().equals( sms.getRecipients() )&& each.getMessage().equalsIgnoreCase( sms.getMessage() ) )
+            if ( each.getRecipients().equals( sms.getRecipients() )
+                && each.getMessage().equalsIgnoreCase( sms.getMessage() ) )
             {
                 return "system is trying to send out wasted SMS";
             }

=== 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-11-12 08:46:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java	2013-12-10 08:37:23 +0000
@@ -33,6 +33,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.sms.incoming.IncomingSms;
 import org.hisp.dhis.sms.incoming.IncomingSmsListener;
+import org.hisp.dhis.sms.incoming.IncomingSmsService;
+import org.hisp.dhis.sms.incoming.SmsMessageStatus;
 import org.springframework.beans.factory.annotation.Autowired;
 
 public class SmsPublisher
@@ -119,17 +121,19 @@
                         }
                     }
                     smsSender.sendMessage( "No command found", message.getOriginator() );
+                    message.setStatus( SmsMessageStatus.UNHANDLED );
                 }
                 catch ( Exception e )
                 {
-                    e.printStackTrace();
                     log.error( e );
                     smsSender.sendMessage( e.getMessage(), message.getOriginator() );
-                }
-
-                messageQueue.remove( message );
-                message = messageQueue.get();
-                log.info( "Queue Size: " + messageQueue.get() );
+                    message.setStatus( SmsMessageStatus.FAILED );
+                }
+                finally
+                {
+                    messageQueue.remove( message );
+                    message = messageQueue.get();
+                }
             }
         }