------------------------------------------------------------ revno: 6231 committer: Hieu <hieu.hispviet...@gmail.com> branch nick: dhis2 timestamp: Fri 2012-03-09 16:40:27 +0700 message: (mobile) Implemented new interface to send SMS message to users. Fixed unit tests and code style. added: dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/MessageSender.java dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageSender.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/HibernateOutboundSmsStore.java dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceImpl.java dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsMessageSender.java dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/AbstractSmsTest.java dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceTest.java dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/SmsMessageSenderTest.java dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/AddGateWayConfigAction.java 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/ShowMobileConfigurationFormAction.java dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.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-api/src/main/java/org/hisp/dhis/message/MessageSender.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageSender.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/MessageSender.java 2012-03-09 09:40:27 +0000 @@ -42,5 +42,5 @@ * @param message the message to send. * @param users the users to send the message to. */ - void sendMessage( String subject, String text, User sender, Set<User> users ); + void sendMessage( String subject, String text, User sender, Set<User> users, String gatewayId ); } === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/MessageSender.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/MessageSender.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/MessageSender.java 2012-03-09 09:40:27 +0000 @@ -0,0 +1,47 @@ +package org.hisp.dhis.sms; + +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Set; + +import org.hisp.dhis.user.User; + +/** + * @author Dang Duy Hieu + */ +public interface MessageSender +{ + /** + * Sends a message. The given message will be sent to the given set of + * phones. + * + * @param message the message to send. + * @param recipients the recipients will receive the sms message. + */ + void sendMessage( String subject, String text, User sender, boolean isPhone, Set<?> recipients, String gatewayId ); +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java 2012-03-01 08:56:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java 2012-03-09 09:40:27 +0000 @@ -46,7 +46,7 @@ * @param sms the message to be sent * @throws SmsServiceException if unable to sent Message */ - public void sendMessage( OutboundSms sms ) + public void sendMessage( OutboundSms sms, String gatewayId ) throws SmsServiceException; } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java 2012-03-01 08:56:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java 2012-03-09 09:40:27 +0000 @@ -26,7 +26,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + /** * Marker interface for {@code OutboundSmsService outbound sms services} * providing actual sms sending. === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2012-03-09 09:40:27 +0000 @@ -101,6 +101,15 @@ Collection<User> getUsersWithoutOrganisationUnit(); /** + * Returns a Collection of the Users which are associated with OrganisationUnits. + * + * @param units a Collection of the organization units. + * + * @return a Collection of Users. + */ + Collection<User> getUsersByOrganisationUnits( Collection<OrganisationUnit> units ); + + /** * Returns a Collection of Users which are having given Phone number. * * @param phoneNumber === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2012-03-09 09:40:27 +0000 @@ -91,6 +91,15 @@ Collection<User> getUsersWithoutOrganisationUnit(); /** + * Returns a Collection of the Users which are associated with OrganisationUnits. + * + * @param orgunits a Collection of the organization units. + * + * @return a Collection of Users. + */ + Collection<User> getUsersByOrganisationUnits( Collection<OrganisationUnit> orgunits ); + + /** * Returns a Collection of Users which are having given Phone number. * * @param phoneNumber === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2012-03-09 09:40:27 +0000 @@ -458,4 +458,9 @@ return map; } + + public Collection<User> getUsersByOrganisationUnits( Collection<OrganisationUnit> units ) + { + return userStore.getUsersByOrganisationUnits( units ); + } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2012-03-09 09:40:27 +0000 @@ -258,7 +258,7 @@ } public Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name, - int first, int max ) + int first, int max ) { return getBlockUser( findByName( toUserCredentials( orgUnit.getUsers() ), name ), first, max ); } @@ -486,4 +486,12 @@ return credentials; } + + @SuppressWarnings("unchecked") + public Collection<User> getUsersByOrganisationUnits( Collection<OrganisationUnit> orgunits ) + { + String hql = "select distinct u from User u join u.organisationUnits o where o.id in (:ids)"; + + return sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", orgunits ).list(); + } } === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/HibernateOutboundSmsStore.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/HibernateOutboundSmsStore.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/HibernateOutboundSmsStore.java 2012-03-09 09:40:27 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.sms.outbound; +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + import java.util.Date; import java.util.List; @@ -11,7 +38,6 @@ public class HibernateOutboundSmsStore implements OutboundSmsStore { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -26,27 +52,30 @@ @Override public int save( OutboundSms sms ) { - checkDate(sms); + checkDate( sms ); return (Integer) sessionFactory.getCurrentSession().save( sms ); } - + private void checkDate( OutboundSms sms ) { - if (sms.getDate() == null) { + if ( sms.getDate() == null ) + { sms.setDate( new Date() ); } - + } @Override - public OutboundSms get( int id) { + public OutboundSms get( int id ) + { Session session = sessionFactory.getCurrentSession(); return (OutboundSms) session.get( OutboundSms.class, id ); } @Override @SuppressWarnings( "unchecked" ) - public List<OutboundSms> getAll() { + public List<OutboundSms> getAll() + { Session session = sessionFactory.getCurrentSession(); return (List<OutboundSms>) session.createCriteria( OutboundSms.class ).list(); } === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceImpl.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceImpl.java 2012-03-01 08:56:47 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceImpl.java 2012-03-09 09:40:27 +0000 @@ -89,7 +89,7 @@ @Override @Transactional - public void sendMessage( OutboundSms sms ) + public void sendMessage( OutboundSms sms, String gatewayId ) throws SmsServiceException { if ( !enabled ) @@ -101,7 +101,7 @@ if ( transportService != null ) { - sendMessageInternal( sms ); + sendMessageInternal( sms, gatewayId ); } } @@ -109,11 +109,11 @@ // Support methods // ------------------------------------------------------------------------- - private void sendMessageInternal( OutboundSms sms ) + private void sendMessageInternal( OutboundSms sms, String id ) { try { - transportService.sendMessage( sms ); + transportService.sendMessage( sms, id ); sms.setStatus( OutboundSmsStatus.SENT ); } catch ( SmsServiceException e ) === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsMessageSender.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsMessageSender.java 2012-03-01 08:56:47 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsMessageSender.java 2012-03-09 09:40:27 +0000 @@ -36,7 +36,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hisp.dhis.message.MessageSender; +import org.hisp.dhis.sms.MessageSender; import org.hisp.dhis.sms.SmsServiceException; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserService; @@ -68,8 +68,9 @@ // MessageSender implementation // ------------------------------------------------------------------------- - @Override - public void sendMessage( String subject, String text, User sender, Set<User> users ) + @SuppressWarnings("unchecked") + public void sendMessage( String subject, String text, User sender, boolean isPhone, Set<?> recipients, + String gatewayId ) { if ( outboundSmsService == null || !outboundSmsService.isEnabled() ) { @@ -78,11 +79,20 @@ text = createMessage( subject, text, sender ); - Set<String> recipients = getRecipients( users ); + Set<String> phones = null; + + if ( isPhone ) + { + phones = (Set<String>) recipients; + } + else + { + phones = getRecipients( (Set<User>) recipients ); + } if ( !recipients.isEmpty() ) { - sendMessage( text, recipients ); + sendMessage( text, phones, gatewayId ); } else if ( log.isDebugEnabled() ) { @@ -134,7 +144,7 @@ return (length > 160) ? text.substring( 0, 157 ) + "..." : text; } - private void sendMessage( String text, Set<String> recipients ) + private void sendMessage( String text, Set<String> recipients, String id ) { OutboundSms sms = new OutboundSms(); sms.setMessage( text ); @@ -142,7 +152,7 @@ try { - outboundSmsService.sendMessage( sms ); + outboundSmsService.sendMessage( sms, id ); if ( log.isDebugEnabled() ) { === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java 2012-02-02 13:08:43 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java 2012-03-09 09:40:27 +0000 @@ -17,13 +17,12 @@ public class TestOutboundSmsService implements OutboundSmsTransportService { - private static final Log log = LogFactory.getLog( TestOutboundSmsService.class ); private boolean enabled = true; @Override - public void sendMessage( OutboundSms sms ) + public void sendMessage( OutboundSms sms, String gatewayId ) throws SmsServiceException { if (!enabled) === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java 2012-03-01 08:56:47 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java 2012-03-09 09:40:27 +0000 @@ -61,13 +61,13 @@ } @Override - public void sendMessage( OutboundSms sms ) + public void sendMessage( OutboundSms sms, String gatewayId ) throws SmsServiceException { String recipient; Set<String> recipients = sms.getRecipients(); - + if ( recipients.size() == 0 ) { log.warn( "Trying to send sms without recipients: " + sms ); @@ -96,7 +96,15 @@ try { log.debug( "Sending message " + sms ); - sent = getService().sendMessage( message ); + + if ( gatewayId == null || gatewayId.isEmpty() ) + { + sent = getService().sendMessage( message ); + } + else + { + sent = getService().sendMessage( message, gatewayId ); + } } catch ( SMSLibException e ) { @@ -267,7 +275,6 @@ public void process( AGateway gateway, OutboundMessage msg ) { log.debug( "Sent message through gateway " + gateway.getGatewayId() + ": " + msg ); - } } === modified file 'dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/AbstractSmsTest.java' --- dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/AbstractSmsTest.java 2012-03-01 08:56:47 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/AbstractSmsTest.java 2012-03-09 09:40:27 +0000 @@ -47,6 +47,7 @@ @Transactional public abstract class AbstractSmsTest { + protected String gatewayId; @Autowired protected SessionFactory sessionFactory; === modified file 'dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceTest.java' --- dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceTest.java 2012-03-01 11:12:13 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceTest.java 2012-03-09 09:40:27 +0000 @@ -29,6 +29,8 @@ import static org.junit.Assert.fail; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.same; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -58,14 +60,15 @@ private OutboundSmsStore outboundSmsStore; @Test - @Ignore //FIXME + @Ignore + // FIXME public void testIntegrationEnabledNoTransport() { outboundSmsService.initialize( new SmsConfiguration( true ) ); OutboundSms outboundSms = getOutboundSms(); - outboundSmsService.sendMessage( outboundSms ); + outboundSmsService.sendMessage( outboundSms, gatewayId ); List<OutboundSms> smses = outboundSmsStore.getAll(); assertNotNullSize( smses, 1 ); @@ -81,13 +84,12 @@ OutboundSmsService tmpService = new OutboundSmsServiceImpl(); try { - tmpService.sendMessage( getOutboundSms() ); - fail("Should fail since service is not enabled"); + tmpService.sendMessage( getOutboundSms(), gatewayId ); + fail( "Should fail since service is not enabled" ); } catch ( SmsServiceException e ) { } - } @Test @@ -99,25 +101,28 @@ tmpService.setTransportService( transportService ); OutboundSms outboundSms = getOutboundSms(); - + // Service not enabled try { - tmpService.sendMessage( outboundSms ); - fail("Should fail since service is not enabled"); + tmpService.sendMessage( outboundSms, gatewayId ); + fail( "Should fail since service is not enabled" ); } catch ( SmsServiceException e ) { } // Not sent message to transport service - verify( transportService, never() ).sendMessage( any( OutboundSms.class ) ); + verify( transportService, never() ).sendMessage( same( outboundSms ), anyString() ); // Enable service tmpService.initialize( new SmsConfiguration( true ) ); - tmpService.sendMessage( outboundSms ); - verify( transportService ).sendMessage( outboundSms ); + tmpService.sendMessage( outboundSms, gatewayId ); + + verify( transportService ).sendMessage( same( outboundSms ), anyString() ); + + verify( transportService ).sendMessage( same( outboundSms ), anyString() ); } @Test @@ -133,17 +138,19 @@ OutboundSms outboundSms = getOutboundSms(); - doThrow( new SmsServiceException( "" ) ).when( transportService ).sendMessage( outboundSms ); - - tmpService.sendMessage( outboundSms ); - - verify( transportService ).sendMessage( outboundSms ); + doThrow( new SmsServiceException( "" ) ).when( transportService ) + .sendMessage( same( outboundSms ), anyString() ); + + tmpService.sendMessage( outboundSms, gatewayId ); + + verify( transportService ).sendMessage( any( OutboundSms.class ), anyString() ); ArgumentCaptor<OutboundSms> argument = ArgumentCaptor.forClass( OutboundSms.class ); verify( tmpStore, times( 1 ) ).save( argument.capture() ); // Is the SMS Marked with error status in store? // Can't test this without using hibernate or adding update on store... - //assertEquals( OutboundSmsStatus.ERROR, argument.getValue().getStatus() ); + // assertEquals( OutboundSmsStatus.ERROR, + // argument.getValue().getStatus() ); } } === modified file 'dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/SmsMessageSenderTest.java' --- dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/SmsMessageSenderTest.java 2011-12-20 13:17:11 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/SmsMessageSenderTest.java 2012-03-09 09:40:27 +0000 @@ -21,7 +21,6 @@ @SuppressWarnings( "serial" ) public class SmsMessageSenderTest { - @Test public void testMessageSender() { @@ -38,11 +37,11 @@ smsMessageSender.setOutboundSmsService( outboundSmsService ); smsMessageSender.setUserService( userService ); - smsMessageSender.sendMessage( "Hello", "hello", user, getUserSet( user ) ); + smsMessageSender.sendMessage( "Hello", "hello", user, false, getUserSet( user ), null ); verify( outboundSmsService ).isEnabled(); verify( userService ).getUserSettings( KEY_MESSAGE_SMS_NOTIFICATION, false ); - verify( outboundSmsService ).sendMessage( refEq(getSms()) ); + verify( outboundSmsService ).sendMessage( refEq(getSms()), anyString() ); } private OutboundSms getSms() === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/AddGateWayConfigAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/AddGateWayConfigAction.java 2011-11-14 08:57:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/AddGateWayConfigAction.java 2012-03-09 09:40:27 +0000 @@ -2,11 +2,13 @@ import com.opensymphony.xwork2.Action; -public class AddGateWayConfigAction implements Action { - - @Override - public String execute() throws Exception { - return SUCCESS; - } +public class AddGateWayConfigAction + implements Action +{ + public String execute() + throws Exception + { + return SUCCESS; + } } === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java 2012-03-09 09:40:27 +0000 @@ -0,0 +1,124 @@ +package org.hisp.dhis.mobile.action; + +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.oust.manager.SelectionTreeManager; +import org.hisp.dhis.sms.MessageSender; +import org.hisp.dhis.user.CurrentUserService; +import org.hisp.dhis.user.User; +import org.hisp.dhis.user.UserService; +import org.springframework.beans.factory.annotation.Autowired; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ +public class ProcessingSendSMSAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private SelectionTreeManager selectionTreeManager; + + @Autowired + private UserService userService; + + @Autowired + private CurrentUserService currentUserService; + + @Autowired + private MessageSender messageSender; + + // ------------------------------------------------------------------------- + // Input & Output + // ------------------------------------------------------------------------- + + private String gatewayId; + + public void setGatewayId( String gatewayId ) + { + this.gatewayId = gatewayId; + } + + private String smsSubject; + + public void setSmsSubject( String smsSubject ) + { + this.smsSubject = smsSubject; + } + + private String smsMessage; + + public void setSmsMessage( String smsMessage ) + { + this.smsMessage = smsMessage; + } + + private Set<String> recipients = new HashSet<String>(); + + public void setRecipients( Set<String> recipients ) + { + this.recipients = recipients; + } + + // ------------------------------------------------------------------------- + // Action Implementation + // ------------------------------------------------------------------------- + + public String execute() + { + if ( smsMessage != null && !smsMessage.isEmpty() ) + { + if ( recipients != null && !recipients.isEmpty() ) + { + messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), true, + recipients, gatewayId ); + } + + Collection<OrganisationUnit> units = selectionTreeManager.getSelectedOrganisationUnits(); + + if ( units != null && !units.isEmpty() ) + { + messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), false, + new HashSet<User>( userService.getUsersByOrganisationUnits( units ) ), gatewayId ); + } + } + + return SUCCESS; + } +} === 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 2011-12-20 11:55:34 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/SendSMSAction.java 2012-03-09 09:40:27 +0000 @@ -36,7 +36,6 @@ public class SendSMSAction implements Action { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -49,7 +48,7 @@ } // ------------------------------------------------------------------------- - // Action Implementation + // Input & Output // ------------------------------------------------------------------------- String message = ""; @@ -59,7 +58,6 @@ return message; } - public boolean getSmsServiceStatus() { return outboundSmsService.isEnabled(); @@ -86,6 +84,9 @@ this.send = send; } + // ------------------------------------------------------------------------- + // Action Implementation + // ------------------------------------------------------------------------- @Override public String execute() @@ -95,7 +96,7 @@ { try { - outboundSmsService.sendMessage( new OutboundSms( msg, recipient ) ); + outboundSmsService.sendMessage( new OutboundSms( msg, recipient ), null ); this.message = "Sent message to " + recipient; } catch ( SmsServiceException e ) === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowMobileConfigurationFormAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowMobileConfigurationFormAction.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowMobileConfigurationFormAction.java 2012-03-09 09:40:27 +0000 @@ -33,36 +33,50 @@ import com.opensymphony.xwork2.Action; -public class ShowMobileConfigurationFormAction implements Action { - - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - @Autowired - private SmsConfigurationManager smsConfigurationManager; - - // ------------------------------------------------------------------------- - // Output - // ------------------------------------------------------------------------- - - private SmsConfiguration smsConfig; - - @Override - public String execute() throws Exception { - smsConfig = smsConfigurationManager.getSmsConfiguration(); - return SUCCESS; - } - - public boolean getSmsServiceStatus() { - return this.smsConfig != null && this.smsConfig.isEnabled(); - } - - public SmsConfiguration getSmsConfig() { - return smsConfig; - } - - public void setSmsConfig(SmsConfiguration smsConfig) { - this.smsConfig = smsConfig; - } +/** + * @author + * @version $Id$ + */ + +public class ShowMobileConfigurationFormAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private SmsConfigurationManager smsConfigurationManager; + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private SmsConfiguration smsConfig; + + public SmsConfiguration getSmsConfig() + { + return smsConfig; + } + + public void setSmsConfig( SmsConfiguration smsConfig ) + { + this.smsConfig = smsConfig; + } + + public boolean getSmsServiceStatus() + { + return this.smsConfig != null && this.smsConfig.isEnabled(); + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + smsConfig = smsConfigurationManager.getSmsConfiguration(); + return SUCCESS; + } } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml 2012-02-29 10:11:21 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml 2012-03-09 09:40:27 +0000 @@ -9,9 +9,8 @@ <bean id="org.hisp.dhis.mobile.action.MobileHomePageAction" class="org.hisp.dhis.mobile.action.MobileHomePageAction" scope="prototype" /> - <bean id="org.hisp.dhis.mobile.action.SendSMSAction" class="org.hisp.dhis.mobile.action.SendSMSAction" scope="prototype"> - <property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" /> - </bean> + <bean id="org.hisp.dhis.mobile.action.ProcessingSendSMSAction" class="org.hisp.dhis.mobile.action.ProcessingSendSMSAction" + scope="prototype" /> <!-- Patient Mobile Settings --> @@ -43,9 +42,9 @@ </bean> <!-- SMS Service Configuration --> - <bean id="org.hisp.dhis.mobile.action.ShowMobileConfigurationFormAction" class="org.hisp.dhis.mobile.action.ShowMobileConfigurationFormAction" - scope="prototype"/> - - <bean id="org.hisp.dhis.mobile.action.AddGateWayConfigAction" class="org.hisp.dhis.mobile.action.AddGateWayConfigAction" scope="prototype"/> + <bean id="org.hisp.dhis.mobile.action.ShowMobileConfigurationFormAction" class="org.hisp.dhis.mobile.action.ShowMobileConfigurationFormAction" + scope="prototype"/> + + <bean id="org.hisp.dhis.mobile.action.AddGateWayConfigAction" class="org.hisp.dhis.mobile.action.AddGateWayConfigAction" scope="prototype"/> </beans> === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml 2012-02-29 10:11:21 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml 2012-03-09 09:40:27 +0000 @@ -16,7 +16,7 @@ <param name="menu">/dhis-web-maintenance-mobile/menu.vm</param> </action> - <action name="sendSMS" class="org.hisp.dhis.mobile.action.SendSMSAction"> + <action name="sendSMS" class="org.hisp.dhis.mobile.action.ProcessingSendSMSAction"> <result name="success" type="velocity">/main.vm</result> <param name="page">/dhis-web-maintenance-mobile/sendSMSPage.vm</param> <param name="menu">/dhis-web-maintenance-mobile/menu.vm</param>
_______________________________________________ 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