=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsConfigurationManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsConfigurationManager.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsConfigurationManager.java 2012-03-01 08:56:47 +0000 @@ -1,10 +1,36 @@ package org.hisp.dhis.sms; +/* + * Copyright (c) 2004-2011, 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 org.hisp.dhis.sms.config.SmsConfiguration; public interface SmsConfigurationManager { - public SmsConfiguration getSmsConfiguration(); public void updateSmsConfiguration( SmsConfiguration config ); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsServiceException.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsServiceException.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsServiceException.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,7 +33,6 @@ public class SmsServiceException extends RuntimeException { - private static final long serialVersionUID = -7927288362330380301L; public SmsServiceException( String message ) @@ -45,6 +44,4 @@ { super( message, cause ); } - - } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/BulkSmsGatewayConfig.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/BulkSmsGatewayConfig.java 2011-12-15 11:41:17 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/BulkSmsGatewayConfig.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.config; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,7 +30,6 @@ public class BulkSmsGatewayConfig extends SmsGatewayConfig { - private static final long serialVersionUID = 5249703354480948250L; private String username; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/ClickatellGatewayConfig.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/ClickatellGatewayConfig.java 2011-12-15 11:41:17 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/ClickatellGatewayConfig.java 2012-03-01 08:56:47 +0000 @@ -1,8 +1,7 @@ package org.hisp.dhis.sms.config; - /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,13 +30,14 @@ public class ClickatellGatewayConfig extends SmsGatewayConfig { - private static final long serialVersionUID = -4286107769356591957L; private String username; + private String password; + private String apiId; - + public String getUsername() { return username; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfig.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfig.java 2011-12-20 12:46:37 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfig.java 2012-03-01 08:56:47 +0000 @@ -1,13 +1,7 @@ package org.hisp.dhis.sms.config; -import java.util.Map; - -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -import org.hisp.dhis.common.adapter.ParametersMapXmlAdapter; - /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,10 +27,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.Map; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import org.hisp.dhis.common.adapter.ParametersMapXmlAdapter; + public class GenericHttpGatewayConfig extends SmsGatewayConfig { - private static final long serialVersionUID = 6340853488475760213L; private String urlTemplate; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/ModemGatewayConfig.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/ModemGatewayConfig.java 2011-12-15 11:41:17 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/ModemGatewayConfig.java 2012-03-01 08:56:47 +0000 @@ -1,8 +1,7 @@ package org.hisp.dhis.sms.config; - /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +30,6 @@ public class ModemGatewayConfig extends SmsGatewayConfig { - private static final long serialVersionUID = 5824899163489665038L; private String port; @@ -44,12 +42,12 @@ private String pin; + private String simMemLocation; + private boolean inbound; private boolean outbound; - private String simMemLocation; - public String getPort() { return port; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurable.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurable.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurable.java 2012-03-01 08:56:47 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.sms.config; +/* + * Copyright (c) 2004-2011, 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 org.hisp.dhis.sms.SmsServiceException; /** @@ -7,7 +34,6 @@ */ public interface SmsConfigurable { - /** * Initialize the service with the provided configuration. *

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java 2011-12-20 12:46:37 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.config; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,6 @@ public class SmsConfiguration implements Serializable { - private static final long serialVersionUID = 7460688383539123303L; private String longNumber; @@ -84,9 +83,9 @@ @XmlElementWrapper( name = "gateways" ) @XmlElements( { @XmlElement( name = "bulksms", type = BulkSmsGatewayConfig.class ), - @XmlElement( name = "clickatell", type = ClickatellGatewayConfig.class ), - @XmlElement( name = "http", type = GenericHttpGatewayConfig.class ), - @XmlElement( name = "modem", type = ModemGatewayConfig.class ) } ) + @XmlElement( name = "clickatell", type = ClickatellGatewayConfig.class ), + @XmlElement( name = "http", type = GenericHttpGatewayConfig.class ), + @XmlElement( name = "modem", type = ModemGatewayConfig.class ) } ) public List getGateways() { return gateways; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsGatewayConfig.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsGatewayConfig.java 2011-12-15 11:41:17 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsGatewayConfig.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.config; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,9 +33,9 @@ * Super class for gateway configurations */ @SuppressWarnings( "serial" ) -public abstract class SmsGatewayConfig implements Serializable +public abstract class SmsGatewayConfig + implements Serializable { - private String name; public String getName() @@ -51,5 +51,5 @@ public abstract boolean isInbound(); public abstract boolean isOutbound(); - + } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsMessageStatus.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsMessageStatus.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsMessageStatus.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.incoming; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,5 +33,4 @@ public enum SmsMessageStatus { INCOMING, PROCESSING, UNHANDLED, FAILED, PROCESSED; - } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.outbound; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,7 +34,6 @@ public class OutboundSms { - private int id; private Set recipients; @@ -115,7 +114,9 @@ private String getNumbers() { if ( this.recipients == null ) + { return null; + } String numbers = ""; @@ -123,6 +124,7 @@ { numbers += recipient + ", "; } + return numbers.substring( 0, numbers.length() - 2 ); } } === 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 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsService.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.outbound; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,9 +33,9 @@ /** * OutboundSmsService provides support for sending SMSes. */ -public interface OutboundSmsService extends SmsConfigurable +public interface OutboundSmsService + extends SmsConfigurable { - String ID = OutboundSmsService.class.getName(); public boolean isEnabled(); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStatus.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStatus.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStatus.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.outbound; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,7 +29,5 @@ public enum OutboundSmsStatus { - OUTBOUND, SENT, ERROR; - } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStore.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsStore.java 2012-03-01 08:56:47 +0000 @@ -3,7 +3,7 @@ import java.util.List; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,13 +31,10 @@ public interface OutboundSmsStore { - public int save( OutboundSms sms ); public List getAll(); public OutboundSms get( int id ); - - } === 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 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java 2012-03-01 08:56:47 +0000 @@ -1,10 +1,37 @@ package org.hisp.dhis.sms.outbound; - +/* + * Copyright (c) 2004-2011, 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. + */ + /** - * Marker interface for {@code OutboundSmsService outbound sms services} providing actual sms sending. + * Marker interface for {@code OutboundSmsService outbound sms services} + * providing actual sms sending. */ -public interface OutboundSmsTransportService extends OutboundSmsService +public interface OutboundSmsTransportService + extends OutboundSmsService { - } === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/SmsConfigurationManagerImpl.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/SmsConfigurationManagerImpl.java 2012-02-02 20:01:36 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/SmsConfigurationManagerImpl.java 2012-03-01 08:56:47 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.sms; +/* + * Copyright (c) 2004-2011, 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.List; import javax.annotation.PostConstruct; @@ -19,9 +46,9 @@ * context, initializing them on startup and on any sms configuration changes. * */ -public class SmsConfigurationManagerImpl implements SmsConfigurationManager +public class SmsConfigurationManagerImpl + implements SmsConfigurationManager { - private static final Log log = LogFactory.getLog( SmsConfigurationManagerImpl.class ); @Autowired @@ -44,14 +71,13 @@ { return; } - + for ( SmsConfigurable smsConfigurable : smsConfigurables ) { - try { smsConfigurable.initialize( smsConfiguration ); - log.debug( "Initialized " + smsConfigurable); + log.debug( "Initialized " + smsConfigurable ); } catch ( Throwable t ) { @@ -60,7 +86,6 @@ + "with configuration " + smsConfiguration, t ); } } - } @Override === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/HibernateIncomingSmsStore.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/HibernateIncomingSmsStore.java 2011-12-15 08:46:42 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/HibernateIncomingSmsStore.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.incoming; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,6 @@ public class HibernateIncomingSmsStore implements IncomingSmsStore { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- === 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-02-02 13:08:43 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceImpl.java 2012-03-01 08:56:47 +0000 @@ -1,15 +1,37 @@ package org.hisp.dhis.sms.outbound; +/* + * Copyright (c) 2004-2011, 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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hisp.dhis.sms.SmsServiceException; import org.hisp.dhis.sms.SmsServiceNotEnabledException; import org.hisp.dhis.sms.config.SmsConfiguration; -import org.hisp.dhis.sms.outbound.OutboundSms; -import org.hisp.dhis.sms.outbound.OutboundSmsService; -import org.hisp.dhis.sms.outbound.OutboundSmsStatus; -import org.hisp.dhis.sms.outbound.OutboundSmsStore; -import org.hisp.dhis.sms.outbound.OutboundSmsTransportService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -21,29 +43,34 @@ public class OutboundSmsServiceImpl implements OutboundSmsService { - private static final Log log = LogFactory.getLog( OutboundSmsServiceImpl.class ); + private boolean enabled; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + private OutboundSmsStore outboundSmsStore; - private OutboundSmsTransportService transportService; - - private boolean enabled; - - @Autowired public void setOutboundSmsStore( OutboundSmsStore outboundSmsStore ) { this.outboundSmsStore = outboundSmsStore; } + private OutboundSmsTransportService transportService; + @Autowired( required = false ) protected void setTransportService( OutboundSmsTransportService transportService ) { this.transportService = transportService; log.debug( "Got OutboundSmsTransportService: " + transportService.getClass().getSimpleName() ); - } + // ------------------------------------------------------------------------- + // Implementation + // ------------------------------------------------------------------------- + @Override public void initialize( SmsConfiguration smsConfiguration ) throws SmsServiceException @@ -78,6 +105,10 @@ } } + // ------------------------------------------------------------------------- + // Support methods + // ------------------------------------------------------------------------- + private void sendMessageInternal( OutboundSms sms ) { try === 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 2011-12-20 12:46:37 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsMessageSender.java 2012-03-01 08:56:47 +0000 @@ -1,7 +1,7 @@ package org.hisp.dhis.sms.outbound; /* - * Copyright (c) 2011, University of Oslo + * Copyright (c) 2004-2012, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -52,13 +52,13 @@ private UserService userService; - private OutboundSmsService outboundSmsService; - public void setUserService( UserService userService ) { this.userService = userService; } + private OutboundSmsService outboundSmsService; + public void setOutboundSmsService( OutboundSmsService outboundSmsService ) { this.outboundSmsService = outboundSmsService; @@ -71,7 +71,6 @@ @Override public void sendMessage( String subject, String text, User sender, Set users ) { - if ( outboundSmsService == null || !outboundSmsService.isEnabled() ) { return; @@ -84,7 +83,6 @@ if ( !recipients.isEmpty() ) { sendMessage( text, recipients ); - } else if ( log.isDebugEnabled() ) { @@ -104,30 +102,36 @@ boolean smsNotification = settings.get( user ) != null && (Boolean) settings.get( user ); String phoneNumber = user.getPhoneNumber(); + if ( smsNotification && phoneNumber != null && !phoneNumber.trim().isEmpty() ) { recipients.add( phoneNumber ); if ( log.isDebugEnabled() ) + { log.debug( "Adding user as sms recipient: " + user + " with phone number: " + phoneNumber ); + } } } + return recipients; } private String createMessage( String subject, String text, User sender ) { String name = "unknown"; + if ( sender != null ) + { name = sender.getUsername(); + } text = "From " + name + " - " + subject + ": " + text; // Simplistic cutoff 160 characters.. int length = text.length(); - if ( length > 160 ) - text = text.substring( 0, 157 ) + "..."; - return text; + + return (length > 160) ? text.substring( 0, 157 ) + "..." : text; } private void sendMessage( String text, Set recipients ) === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/GateWayFactory.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/GateWayFactory.java 2011-12-20 12:46:37 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/GateWayFactory.java 2012-03-01 08:56:47 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.sms.smslib; +/* + * Copyright (c) 2004-2011, 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 org.hisp.dhis.sms.SmsServiceException; import org.hisp.dhis.sms.config.BulkSmsGatewayConfig; import org.hisp.dhis.sms.config.ClickatellGatewayConfig; @@ -14,17 +41,24 @@ public class GateWayFactory { - public AGateway create( SmsGatewayConfig config ) { if ( config instanceof BulkSmsGatewayConfig ) + { return createBulkSmsGateway( (BulkSmsGatewayConfig) config ); + } else if ( config instanceof GenericHttpGatewayConfig ) + { return createSimplisticHttpGetGateway( (GenericHttpGatewayConfig) config ); + } else if ( config instanceof ClickatellGatewayConfig ) + { return createClickatellGateway( (ClickatellGatewayConfig) config ); + } else if ( config instanceof ModemGatewayConfig ) + { return createModemGateway( (ModemGatewayConfig) config ); + } throw new SmsServiceException( "Gateway config of unknown type: " + config.getClass().getName() ); @@ -32,8 +66,8 @@ public AGateway createBulkSmsGateway( BulkSmsGatewayConfig config ) { - BulkSmsHTTPGateway gateway = new BulkSmsHTTPGateway( "bulksms.http.1", config.getUsername(), - config.getPassword() ); + BulkSmsHTTPGateway gateway = new BulkSmsHTTPGateway( "bulksms.http.1", config.getUsername(), config + .getPassword() ); gateway.setOutbound( true ); gateway.setInbound( false ); return gateway; @@ -41,10 +75,9 @@ public AGateway createModemGateway( ModemGatewayConfig c ) { - // TODO: DETECT MODEM CLASS AND INSTANTIATE - SerialModemGateway gateway = new SerialModemGateway( c.getName(), c.getPort(), c.getBaudRate(), - c.getManufacturer(), c.getModel() ); + SerialModemGateway gateway = new SerialModemGateway( c.getName(), c.getPort(), c.getBaudRate(), c + .getManufacturer(), c.getModel() ); if ( c.getSimMemLocation() != null ) { @@ -65,8 +98,8 @@ public AGateway createClickatellGateway( ClickatellGatewayConfig c ) { - ClickatellHTTPGateway gateway = new ClickatellHTTPGateway( c.getName(), c.getApiId(), c.getUsername(), - c.getPassword() ); + ClickatellHTTPGateway gateway = new ClickatellHTTPGateway( c.getName(), c.getApiId(), c.getUsername(), c + .getPassword() ); gateway.setOutbound( true ); gateway.setInbound( false ); return gateway; @@ -74,10 +107,10 @@ public AGateway createSimplisticHttpGetGateway( GenericHttpGatewayConfig c ) { - SimplisticHttpGetGateWay gateway = new SimplisticHttpGetGateWay( c.getName(), c.getUrlTemplate(), c.getParameters() ); + SimplisticHttpGetGateWay gateway = new SimplisticHttpGetGateWay( c.getName(), c.getUrlTemplate(), c + .getParameters() ); gateway.setOutbound( true ); gateway.setInbound( false ); return gateway; } - } === 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 2012-02-02 13:08:43 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SimplisticHttpGetGateWay.java 2012-03-01 08:56:47 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.sms.smslib; +/* + * Copyright (c) 2004-2011, 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.io.IOException; import java.util.HashMap; import java.util.Map; @@ -15,12 +42,15 @@ import org.springframework.web.client.RestTemplate; /** - * Simplistic http gateway sending smses through a get to a url constructed from the provided - * urlTemplate and map of static parameters. - *

This gateway is simplistic in that it can't evaluate the response from the provider, being most suitable as an - * example gateway. For production use a more robust gateway should be used implemented for the specific provider. + * Simplistic http gateway sending smses through a get to a url constructed from + * the provided urlTemplate and map of static parameters. + *

+ * This gateway is simplistic in that it can't evaluate the response from the + * provider, being most suitable as an example gateway. For production use a + * more robust gateway should be used implemented for the specific provider. * - *

The gateway adds the following keys to the parameters: + *

+ * The gateway adds the following keys to the parameters: *