------------------------------------------------------------ revno: 12940 committer: Lai <lai.hispviet...@gmail.com> branch nick: dhis2 timestamp: Thu 2013-11-14 15:56:31 +0700 message: prevent wasted SMS sent out accidently 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/resources/META-INF/dhis/beans.xml dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.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-11-08 04:05:21 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DefaultSmsSender.java 2013-11-14 08:56:31 +0000 @@ -38,6 +38,7 @@ import org.apache.commons.logging.LogFactory; import org.hisp.dhis.sms.outbound.DefaultOutboundSmsTransportService; import org.hisp.dhis.sms.outbound.OutboundSms; +import org.hisp.dhis.sms.outbound.OutboundSmsService; import org.hisp.dhis.sms.outbound.OutboundSmsTransportService; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; @@ -69,6 +70,13 @@ { this.userService = userService; } + + private OutboundSmsService outboundSmsService; + + public void setOutboundSmsService( OutboundSmsService outboundSmsService ) + { + this.outboundSmsService = outboundSmsService; + } @Autowired private OutboundSmsTransportService transportService; @@ -78,6 +86,7 @@ public String sendMessage( OutboundSms sms, String gatewayId ) throws SmsServiceException { + String resultMessage = null; if ( !transportService.isEnabled() ) { throw new SmsServiceNotEnabledException(); @@ -85,7 +94,12 @@ if ( transportService != null ) { - return transportService.sendMessage( sms, gatewayId ); + resultMessage = isWastedSMS( sms ); + if ( resultMessage == null ) + { + resultMessage = transportService.sendMessage( sms, gatewayId ); + } + return resultMessage; } return "outboundsms_saved"; @@ -96,6 +110,7 @@ public String sendMessage( OutboundSms sms ) throws SmsServiceException { + String message = null; if ( !transportService.isEnabled() ) { throw new SmsServiceNotEnabledException(); @@ -103,10 +118,17 @@ if ( transportService != null ) { - return transportService.sendMessage( sms, transportService.getDefaultGateway() ); - } - - return "outboundsms_saved"; + message = isWastedSMS( sms ); + if ( message == null ) + { + message = transportService.sendMessage( sms, transportService.getDefaultGateway() ); + } + return message; + } + else + { + return "outboundsms_saved"; + } } @Transactional @@ -122,8 +144,8 @@ if ( transportService != null ) { message = createMessage( null, message, currentUserService.getCurrentUser() ); - String defaultGatewayId = transportService.getDefaultGateway(); - return transportService.sendMessage( new OutboundSms( message, phoneNumber ), defaultGatewayId ); + OutboundSms sms = new OutboundSms( message, phoneNumber ); + return sendMessage( sms ); } return "outboundsms_saved"; @@ -276,17 +298,22 @@ OutboundSms sms = new OutboundSms(); sms.setMessage( text ); sms.setRecipients( recipients ); - - try - { - message = transportService.sendMessage( sms, gateWayId ); - } - catch ( SmsServiceException e ) - { - message = "Unable to send message through sms: " + sms + e.getCause().getMessage(); - - log.warn( "Unable to send message through sms: " + sms, e ); - } + message = isWastedSMS( sms ); + + if( message == null ) + { + try + { + message = transportService.sendMessage( sms, gateWayId ); + } + catch ( SmsServiceException e ) + { + message = "Unable to send message through sms: " + sms + e.getCause().getMessage(); + + log.warn( "Unable to send message through sms: " + sms, e ); + } + } + return message; } @@ -316,6 +343,19 @@ return splitLongUnicodeString( secondTempString, result ); } } + + public String isWastedSMS( OutboundSms sms ) + { + List<OutboundSms> listOfRecentOutboundSms = outboundSmsService.getAllOutboundSms( 0, 10 ); + for( OutboundSms each: listOfRecentOutboundSms ) + { + if( each.getRecipients().equals( sms.getRecipients() )&& each.getMessage().equalsIgnoreCase( sms.getMessage() ) ) + { + return "system is trying to send out wasted SMS"; + } + } + return null; + } public CurrentUserService getCurrentUserService() { === 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-11-12 08:46:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-11-14 08:56:31 +0000 @@ -773,6 +773,7 @@ <bean id="org.hisp.dhis.sms.SmsSender" class="org.hisp.dhis.sms.DefaultSmsSender"> <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" /> <property name="userService" ref="org.hisp.dhis.user.UserService" /> + <property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" /> </bean> <bean id="org.hisp.dhis.sms.DataValueSMSListener" class="org.hisp.dhis.sms.DataValueSMSListener"> === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java 2013-11-14 08:56:31 +0000 @@ -40,10 +40,9 @@ // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- - - + private SmsSender smsSender; - + public SmsSender getSmsSender() { return smsSender; @@ -54,7 +53,6 @@ this.smsSender = smsSender; } - // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -100,7 +98,8 @@ try { smsSender.sendMessage( new OutboundSms( msg, recipient ), null ); -// outboundSmsService.sendMessage( new OutboundSms( msg, recipient ), null ); + // outboundSmsService.sendMessage( new OutboundSms( msg, + // recipient ), null ); this.message = "Sent message to " + recipient; } catch ( SmsServiceException e )
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp