------------------------------------------------------------ revno: 20573 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Wed 2015-10-07 16:40:33 +0200 message: SMS services, code style removed: dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/package-info.java modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsTransportProviderNotFoundException.java 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/ClickatellGatewayConfig.java 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/SMPPGatewayConfig.java 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/SmsConfiguration.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurationManager.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSms.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsListener.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsMessageEncoding.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java 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 dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/command/SMSSpecialCharacter.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/AdvanceHttpPostGateWay.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultSmsConfigurationManager.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/GateWayFactory.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/SimplisticHttpGetGateWay.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateIncomingSmsStore.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DHISMessageAlertListener.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DataValueSMSListener.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/J2MEDataValueSMSListener.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/TrackedEntityRegistrationSMSListener.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/UnregisteredSMSListener.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.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-api/src/main/java/org/hisp/dhis/sms/SmsTransportProviderNotFoundException.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsTransportProviderNotFoundException.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsTransportProviderNotFoundException.java 2015-10-07 14:40:33 +0000 @@ -29,7 +29,7 @@ */ /** - * SmsServiceException signalling no transport provider available to sms service + * SmsServiceException signaling no transport provider available to SMS service */ public class SmsTransportProviderNotFoundException extends SmsServiceException === 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/BulkSmsGatewayConfig.java 2015-10-07 14:40:33 +0000 @@ -80,5 +80,4 @@ { return true; } - } === 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/ClickatellGatewayConfig.java 2015-10-07 14:40:33 +0000 @@ -80,5 +80,4 @@ { return true; } - } === 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfig.java 2015-10-07 14:40:33 +0000 @@ -85,5 +85,4 @@ { return true; } - } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SMPPGatewayConfig.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SMPPGatewayConfig.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SMPPGatewayConfig.java 2015-10-07 14:40:33 +0000 @@ -92,5 +92,4 @@ { this.address = address; } - } === 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurable.java 2015-10-07 14:40:33 +0000 @@ -36,10 +36,9 @@ public interface SmsConfigurable { /** - * Initialize the service with the provided configuration. - * <p> - * Services implementing this interface are also expected to be able to - * reinitialize based on these setting in a safe way when running. + * Initialize the service with the provided configuration. Services + * implementing this interface are also expected to be able to reinitialize + * based on these setting in a safe way when running. * * @param smsConfiguration The SMS configuration * @throws SmsServiceException if the service cannot be initialized with the @@ -47,5 +46,4 @@ */ String initialize( SmsConfiguration smsConfiguration ) throws SmsServiceException; - } === 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java 2015-10-07 14:40:33 +0000 @@ -127,6 +127,7 @@ return gw; } } + return null; } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurationManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurationManager.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfigurationManager.java 2015-10-07 14:40:33 +0000 @@ -28,7 +28,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - public interface SmsConfigurationManager { SmsConfiguration getSmsConfiguration(); === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/package-info.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/package-info.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/package-info.java 1970-01-01 00:00:00 +0000 @@ -1,45 +0,0 @@ -/** - * @author bobj - */ - -@XmlSchema( - namespace = "http://dhis2.org/schema/dxf/2.0", - xmlns = { - @XmlNs(namespaceURI = "http://dhis2.org/schema/dxf/2.0", prefix = "d") - }, - elementFormDefault = XmlNsForm.QUALIFIED) - -package org.hisp.dhis.sms.config; - -/* - * Copyright (c) 2004-2015, 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 javax.xml.bind.annotation.XmlSchema; -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlNsForm; - === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSms.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSms.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSms.java 2015-10-07 14:40:33 +0000 @@ -191,5 +191,4 @@ { this.parsed = parsed; } - } \ No newline at end of file === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsListener.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsListener.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsListener.java 2015-10-07 14:40:33 +0000 @@ -1,7 +1,5 @@ package org.hisp.dhis.sms.incoming; -import org.springframework.transaction.annotation.Transactional; - /* * Copyright (c) 2004-2015, University of Oslo * All rights reserved. @@ -30,6 +28,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.springframework.transaction.annotation.Transactional; + public interface IncomingSmsListener { @Transactional === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java 2015-09-16 14:49:50 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java 2015-10-07 14:40:33 +0000 @@ -70,5 +70,4 @@ List<IncomingSms> getSmsByStatus( SmsMessageStatus status, String keyword, Integer min, Integer max ); IncomingSms convertToIncomingSms( InboundMessage message ); - } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsMessageEncoding.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsMessageEncoding.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsMessageEncoding.java 2015-10-07 14:40:33 +0000 @@ -33,20 +33,20 @@ */ public enum SmsMessageEncoding { - /** - * 7 bit encoding - standard GSM alphabet. - */ - ENC7BIT, - /** - * 8 bit encoding. - */ - ENC8BIT, - /** - * UCS2 (Unicode) encoding. - */ - ENCUCS2, - /** - * Custom encoding. Currently just defaults to 7-bit. - */ - ENCCUSTOM + /** + * 7 bit encoding - standard GSM alphabet. + */ + ENC7BIT, + /** + * 8 bit encoding. + */ + ENC8BIT, + /** + * UCS2 (Unicode) encoding. + */ + ENCUCS2, + /** + * Custom encoding. Currently just defaults to 7-bit. + */ + ENCCUSTOM } \ No newline at end of file === 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 2015-10-05 17:45:17 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSms.java 2015-10-07 14:40:33 +0000 @@ -35,7 +35,8 @@ import org.hisp.dhis.common.BaseIdentifiableObject; -public class OutboundSms extends BaseIdentifiableObject +public class OutboundSms + extends BaseIdentifiableObject { public static final String DHIS_SYSTEM_SENDER = "DHIS-System"; === 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 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DatabaseSupportedInternalMemoryMessageQueue.java 2015-10-07 14:40:33 +0000 @@ -63,6 +63,7 @@ { return queue.get( 0 ); } + return null; } @@ -78,6 +79,7 @@ public void initialize() { Collection<IncomingSms> messages = smsStore.getAllUnparsedSmses(); + if ( messages != null ) { queue.addAll( messages ); @@ -88,5 +90,4 @@ { 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 2015-09-13 17:45:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DefaultSmsSender.java 2015-10-07 14:40:33 +0000 @@ -128,7 +128,7 @@ { String message = null; - if ( transportService == null || DefaultOutboundSmsTransportService.gatewayMap == null ) + if ( transportService == null || DefaultOutboundSmsTransportService.GATEWAY_MAP == null ) { message = "No gateway"; return message; @@ -172,10 +172,9 @@ text = createMessage( subject, text, sender ); - // Bulk is limited in sending long SMS, need to cut into small - // pieces - if ( DefaultOutboundSmsTransportService.gatewayMap.get( "bulk_gw" ) != null - && DefaultOutboundSmsTransportService.gatewayMap.get( "bulk_gw" ).equals( gatewayId ) ) + // Bulk is limited in sending long SMS, need to cut into small pieces + if ( DefaultOutboundSmsTransportService.GATEWAY_MAP.get( "bulk_gw" ) != null + && DefaultOutboundSmsTransportService.GATEWAY_MAP.get( "bulk_gw" ).equals( gatewayId ) ) { // Check if text contain any specific unicode character for ( char each : text.toCharArray() ) @@ -271,10 +270,6 @@ sms.setMessage( text ); sms.setRecipients( recipients ); - // Disable wasted messsage check due to incorrect detection - // message = isWastedSMS( sms ); - // if ( message == null ) - try { message = transportService.sendMessage( sms, gateWayId ); @@ -318,6 +313,7 @@ public String isWastedSMS( OutboundSms sms ) { List<OutboundSms> listOfRecentOutboundSms = outboundSmsService.getAllOutboundSms( 0, 10 ); + for ( OutboundSms each : listOfRecentOutboundSms ) { if ( each.getRecipients().equals( sms.getRecipients() ) @@ -326,6 +322,7 @@ return "system is trying to send out wasted SMS"; } } + return null; } === 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 2015-09-13 17:00:06 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java 2015-10-07 14:40:33 +0000 @@ -107,6 +107,7 @@ private void fetchAndParseSMS() { IncomingSms message = messageQueue.get(); + while ( message != null ) { log.info( "Received SMS: " + message.getText() ); @@ -121,6 +122,7 @@ return; } } + smsSender.sendMessage( "No command found", message.getOriginator() ); message.setStatus( SmsMessageStatus.UNHANDLED ); } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/command/SMSSpecialCharacter.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/command/SMSSpecialCharacter.java 2015-06-23 15:59:19 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/command/SMSSpecialCharacter.java 2015-10-07 14:40:33 +0000 @@ -43,7 +43,6 @@ public SMSSpecialCharacter() { - } public SMSSpecialCharacter( String name, String value ) === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/AdvanceHttpPostGateWay.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/AdvanceHttpPostGateWay.java 2015-02-22 20:02:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/AdvanceHttpPostGateWay.java 2015-10-07 14:40:33 +0000 @@ -81,6 +81,7 @@ requestParameters.put( MESSAGE, outboundMessage.getText() ); String sender = outboundMessage.getFrom(); + if ( sender != null ) { log.debug( "Adding sender " + sender + " " + getGatewayId() ); @@ -133,8 +134,8 @@ } return 1; - } + return super.sendMessages( outboundMessages ); } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultSmsConfigurationManager.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultSmsConfigurationManager.java 2015-10-06 18:24:42 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/DefaultSmsConfigurationManager.java 2015-10-07 14:40:33 +0000 @@ -42,8 +42,7 @@ * Manages the {@link SmsConfiguration} for the DHIS instance. * <p> * The manager looks up all beans implementing {@link SmsConfigurable} in the - * context, initializing them on startup and on any sms configuration changes. - * + * context, initializing them on startup and on any SMS configuration changes. */ public class DefaultSmsConfigurationManager implements SmsConfigurationManager === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/GateWayFactory.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/GateWayFactory.java 2015-09-10 16:35:55 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/GateWayFactory.java 2015-10-07 14:40:33 +0000 @@ -115,7 +115,7 @@ public AGateway createModemGateway( ModemGatewayConfig c ) { - // TODO: DETECT MODEM CLASS AND INSTANTIATE + // TODO Detect modem class and instantiate SerialModemGateway gateway = new SerialModemGateway( c.getName(), c.getPort(), c.getBaudRate(), c.getManufacturer(), c.getModel() ); @@ -147,8 +147,8 @@ 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-core/src/main/java/org/hisp/dhis/sms/config/SimplisticHttpGetGateWay.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/SimplisticHttpGetGateWay.java 2015-02-22 20:02:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/config/SimplisticHttpGetGateWay.java 2015-10-07 14:40:33 +0000 @@ -71,7 +71,6 @@ * <li>username * <li>password * </ul> - * */ public class SimplisticHttpGetGateWay extends AGateway @@ -161,6 +160,7 @@ } HttpURLConnection httpConnection = (HttpURLConnection) conn; + if ( httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK ) { log.warn( "Couldn't send message, got response " + response + " " + getGatewayId() ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateIncomingSmsStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateIncomingSmsStore.java 2015-06-16 05:11:29 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/hibernate/HibernateIncomingSmsStore.java 2015-10-07 14:40:33 +0000 @@ -141,6 +141,7 @@ { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria( IncomingSms.class ).addOrder( Order.desc( "sentDate" ) ); + if ( status != null ) { criteria.add( Restrictions.eq( "status", status ) ); @@ -151,6 +152,7 @@ { criteria.setFirstResult( min ).setMaxResults( max ); } + return criteria.list(); } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DHISMessageAlertListener.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DHISMessageAlertListener.java 2015-06-23 15:59:19 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DHISMessageAlertListener.java 2015-10-07 14:40:33 +0000 @@ -54,22 +54,37 @@ { private SMSCommandService smsCommandService; + public void setSmsCommandService( SMSCommandService smsCommandService ) + { + this.smsCommandService = smsCommandService; + } + private UserService userService; + public void setUserService( UserService userService ) + { + this.userService = userService; + } + private MessageService messageService; + public void setMessageService( MessageService messageService ) + { + this.messageService = messageService; + } + private SmsMessageSender smsMessageSender; + public void setSmsMessageSender( SmsMessageSender smsMessageSender ) + { + this.smsMessageSender = smsMessageSender; + } + private IncomingSmsService incomingSmsService; - public SMSCommandService getSmsCommandService() - { - return smsCommandService; - } - - public void setSmsCommandService( SMSCommandService smsCommandService ) - { - this.smsCommandService = smsCommandService; + public void setIncomingSmsService( IncomingSmsService incomingSmsService ) + { + this.incomingSmsService = incomingSmsService; } @Transactional @@ -170,44 +185,4 @@ } } } - - public UserService getUserService() - { - return userService; - } - - public void setUserService( UserService userService ) - { - this.userService = userService; - } - - public MessageService getMessageService() - { - return messageService; - } - - public void setMessageService( MessageService messageService ) - { - this.messageService = messageService; - } - - public SmsMessageSender getSmsMessageSender() - { - return smsMessageSender; - } - - public void setSmsMessageSender( SmsMessageSender smsMessageSender ) - { - this.smsMessageSender = smsMessageSender; - } - - public IncomingSmsService getIncomingSmsService() - { - return incomingSmsService; - } - - public void setIncomingSmsService( IncomingSmsService incomingSmsService ) - { - this.incomingSmsService = incomingSmsService; - } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DataValueSMSListener.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DataValueSMSListener.java 2015-09-13 17:45:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/DataValueSMSListener.java 2015-10-07 14:40:33 +0000 @@ -81,67 +81,71 @@ private CompleteDataSetRegistrationService registrationService; + public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) + { + this.registrationService = registrationService; + } + private DataValueService dataValueService; + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + private SmsSender smsSender; + public void setSmsSender( SmsSender smsSender ) + { + this.smsSender = smsSender; + } + private DataElementCategoryService dataElementCategoryService; + public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) + { + this.dataElementCategoryService = dataElementCategoryService; + } + private SMSCommandService smsCommandService; - private UserService userService; - - private DataSetService dataSetService; - - private IncomingSmsService incomingSmsService; - - private DataElementService dataElementService; - - public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) - { - this.registrationService = registrationService; - } - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - public void setSmsCommandService( SMSCommandService smsCommandService ) { this.smsCommandService = smsCommandService; } + private UserService userService; + public void setUserService( UserService userService ) { this.userService = userService; } + private DataSetService dataSetService; + public void setDataSetService( DataSetService dataSetService ) { this.dataSetService = dataSetService; } - public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) - { - this.dataElementCategoryService = dataElementCategoryService; - } - - public void setSmsSender( SmsSender smsSender ) - { - this.smsSender = smsSender; - } + private IncomingSmsService incomingSmsService; public void setIncomingSmsService( IncomingSmsService incomingSmsService ) { this.incomingSmsService = incomingSmsService; } + private DataElementService dataElementService; + public void setDataElementService( DataElementService dataElementService ) { this.dataElementService = dataElementService; } + // ------------------------------------------------------------------------- + // IncomingSmsListener implementation + // ------------------------------------------------------------------------- + @Transactional @Override public boolean accept( IncomingSms sms ) @@ -152,6 +156,7 @@ for ( int i = 0; i < message.length(); i++ ) { String c = String.valueOf( message.charAt( i ) ); + if ( c.matches( "\\W" ) ) { commandString = message.substring( 0, i ); @@ -297,6 +302,7 @@ cal.setTime( date ); int year = Calendar.getInstance().get( Calendar.YEAR ); int month = Calendar.getInstance().get( Calendar.MONTH ); + if ( cal.get( Calendar.MONTH ) < month ) { cal.set( Calendar.YEAR, year ); @@ -305,6 +311,7 @@ { cal.set( Calendar.YEAR, year - 1 ); } + date = cal.getTime(); } catch ( Exception e ) @@ -415,7 +422,6 @@ Set<SMSSpecialCharacter> specialCharacters = command.getSpecialCharacters(); - // Check for special character cases for ( SMSSpecialCharacter each : specialCharacters ) { if ( each.getName().equalsIgnoreCase( value ) ) @@ -428,6 +434,7 @@ if ( !StringUtils.isEmpty( value ) ) { boolean newDataValue = false; + if ( dv == null ) { dv = new DataValue(); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/J2MEDataValueSMSListener.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/J2MEDataValueSMSListener.java 2015-09-13 17:45:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/J2MEDataValueSMSListener.java 2015-10-07 14:40:33 +0000 @@ -75,16 +75,50 @@ { private DataValueService dataValueService; + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + private DataElementCategoryService dataElementCategoryService; + public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) + { + this.dataElementCategoryService = dataElementCategoryService; + } + private SMSCommandService smsCommandService; + public void setSmsCommandService( SMSCommandService smsCommandService ) + { + this.smsCommandService = smsCommandService; + } + private UserService userService; + public void setUserService( UserService userService ) + { + this.userService = userService; + } + private CompleteDataSetRegistrationService registrationService; + public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) + { + this.registrationService = registrationService; + } + private SmsSender smsSender; + public void setSmsSender( SmsSender smsSender ) + { + this.smsSender = smsSender; + } + + // ------------------------------------------------------------------------- + // IncomingSmsListener implementation + // ------------------------------------------------------------------------- + @Transactional @Override public boolean accept( IncomingSms sms ) @@ -493,6 +527,7 @@ Calendar cal = Calendar.getInstance(); int month = 0; + if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Jan" ) ) { month = 1; @@ -519,69 +554,8 @@ { return periodType.createPeriod( cal.getTime() ); } - } throw new IllegalArgumentException( "Couldn't make a period of type " + periodType.getName() + " and name " + periodName ); } - - public DataValueService getDataValueService() - { - return dataValueService; - } - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - public SMSCommandService getSmsCommandService() - { - return smsCommandService; - } - - public void setSmsCommandService( SMSCommandService smsCommandService ) - { - this.smsCommandService = smsCommandService; - } - - public UserService getUserService() - { - return userService; - } - - public void setUserService( UserService userService ) - { - this.userService = userService; - } - - public CompleteDataSetRegistrationService getRegistrationService() - { - return registrationService; - } - - public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) - { - this.registrationService = registrationService; - } - - public DataElementCategoryService getDataElementCategoryService() - { - return dataElementCategoryService; - } - - public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) - { - this.dataElementCategoryService = dataElementCategoryService; - } - - public SmsSender getSmsSender() - { - return smsSender; - } - - public void setSmsSender( SmsSender smsSender ) - { - this.smsSender = smsSender; - } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/TrackedEntityRegistrationSMSListener.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/TrackedEntityRegistrationSMSListener.java 2015-09-13 17:45:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/TrackedEntityRegistrationSMSListener.java 2015-10-07 14:40:33 +0000 @@ -67,15 +67,49 @@ private SMSCommandService smsCommandService; + public void setSmsCommandService( SMSCommandService smsCommandService ) + { + this.smsCommandService = smsCommandService; + } + private UserService userService; + public void setUserService( UserService userService ) + { + this.userService = userService; + } + private TrackedEntityService trackedEntityService; + public void setTrackedEntityService( TrackedEntityService trackedEntityService ) + { + this.trackedEntityService = trackedEntityService; + } + private TrackedEntityInstanceService trackedEntityInstanceService; - + + public void setTrackedEntityInstanceService( TrackedEntityInstanceService trackedEntityInstanceService ) + { + this.trackedEntityInstanceService = trackedEntityInstanceService; + } + private ProgramInstanceService programInstanceService; - + + public void setProgramInstanceService( ProgramInstanceService programInstanceService ) + { + this.programInstanceService = programInstanceService; + } + private SmsSender smsSender; + + public void setSmsSender( SmsSender smsSender ) + { + this.smsSender = smsSender; + } + + // ------------------------------------------------------------------------- + // IncomingSmsListener implementation + // ------------------------------------------------------------------------- @Override public boolean accept( IncomingSms sms ) @@ -199,6 +233,7 @@ if ( orgUnit == null && orgUnits.size() > 1 ) { String messageListingOrgUnits = smsCommand.getMoreThanOneOrgUnitMessage(); + for ( Iterator<OrganisationUnit> i = orgUnits.iterator(); i.hasNext(); ) { OrganisationUnit o = i.next(); @@ -208,6 +243,7 @@ messageListingOrgUnits += ","; } } + throw new SMSParserException( messageListingOrgUnits ); } @@ -247,6 +283,7 @@ cal.setTime( date ); int year = Calendar.getInstance().get( Calendar.YEAR ); int month = Calendar.getInstance().get( Calendar.MONTH ); + if ( cal.get( Calendar.MONTH ) < month ) { cal.set( Calendar.YEAR, year ); @@ -255,6 +292,7 @@ { cal.set( Calendar.YEAR, year - 1 ); } + date = cal.getTime(); } catch ( Exception e ) @@ -269,13 +307,16 @@ { HashMap<String, String> output = new HashMap<>(); Pattern pattern = Pattern.compile( defaultPattern ); + if ( !StringUtils.isBlank( smsCommand.getSeparator() ) ) { String x = "(\\w+)\\s*\\" + smsCommand.getSeparator().trim() + "\\s*([\\w ]+)\\s*(\\" + smsCommand.getSeparator().trim() + "|$)*\\s*"; pattern = Pattern.compile( x ); } + Matcher matcher = pattern.matcher( message ); + while ( matcher.find() ) { String key = matcher.group( 1 ); @@ -289,64 +330,4 @@ return output; } - - public SMSCommandService getSmsCommandService() - { - return smsCommandService; - } - - public void setSmsCommandService( SMSCommandService smsCommandService ) - { - this.smsCommandService = smsCommandService; - } - - public UserService getUserService() - { - return userService; - } - - public void setUserService( UserService userService ) - { - this.userService = userService; - } - - public TrackedEntityService getTrackedEntityService() - { - return trackedEntityService; - } - - public void setTrackedEntityService( TrackedEntityService trackedEntityService ) - { - this.trackedEntityService = trackedEntityService; - } - - public TrackedEntityInstanceService getTrackedEntityInstanceService() - { - return trackedEntityInstanceService; - } - - public void setTrackedEntityInstanceService( TrackedEntityInstanceService trackedEntityInstanceService ) - { - this.trackedEntityInstanceService = trackedEntityInstanceService; - } - - public ProgramInstanceService getProgramInstanceService() - { - return programInstanceService; - } - - public void setProgramInstanceService( ProgramInstanceService programInstanceService ) - { - this.programInstanceService = programInstanceService; - } - - public SmsSender getSmsSender() - { - return smsSender; - } - - public void setSmsSender( SmsSender smsSender ) - { - this.smsSender = smsSender; - } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/UnregisteredSMSListener.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/UnregisteredSMSListener.java 2015-10-05 07:55:19 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/UnregisteredSMSListener.java 2015-10-07 14:40:33 +0000 @@ -55,16 +55,45 @@ { private SMSCommandService smsCommandService; + public void setSmsCommandService( SMSCommandService smsCommandService ) + { + this.smsCommandService = smsCommandService; + } + private UserService userService; + public void setUserService( UserService userService ) + { + this.userService = userService; + } + private MessageService messageService; + public void setMessageService( MessageService messageService ) + { + this.messageService = messageService; + } + private SmsMessageSender smsMessageSender; + public void setSmsMessageSender( SmsMessageSender smsMessageSender ) + { + this.smsMessageSender = smsMessageSender; + } + private IncomingSmsService incomingSmsService; + public void setIncomingSmsService( IncomingSmsService incomingSmsService ) + { + this.incomingSmsService = incomingSmsService; + } + public static final String USER_NAME = "anonymous"; + // ------------------------------------------------------------------------- + // IncomingSmsListener implementation + // ------------------------------------------------------------------------- + @Transactional @Override public boolean accept( IncomingSms sms ) @@ -122,11 +151,13 @@ { User user = iterator.next(); messageError += user.getName(); + if ( iterator.hasNext() ) { messageError += ", "; } } + throw new SMSParserException( messageError ); } else @@ -169,29 +200,4 @@ } } } - - public void setSmsCommandService( SMSCommandService smsCommandService ) - { - this.smsCommandService = smsCommandService; - } - - public void setUserService( UserService userService ) - { - this.userService = userService; - } - - public void setMessageService( MessageService messageService ) - { - this.messageService = messageService; - } - - public void setSmsMessageSender( SmsMessageSender smsMessageSender ) - { - this.smsMessageSender = smsMessageSender; - } - - public void setIncomingSmsService( IncomingSmsService incomingSmsService ) - { - this.incomingSmsService = incomingSmsService; - } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsService.java 2015-10-07 14:40:33 +0000 @@ -37,7 +37,6 @@ * forwards the request to a {@link OutboundSmsTransportService sms transport * service} for sending. */ - @Transactional public class DefaultOutboundSmsService implements OutboundSmsService === 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 2015-09-13 17:45:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java 2015-10-07 14:40:33 +0000 @@ -65,7 +65,7 @@ private static final String MODEM_GATEWAY = "modem_gw"; private static final String SMPP_GATEWAY = "smpp_gw"; - public static final Map<String, String> gatewayMap = new HashMap<>(); //TODO fix, poor solution + public static final Map<String, String> GATEWAY_MAP = new HashMap<>(); //TODO fix, poor solution private SmsConfiguration config; @@ -77,19 +77,38 @@ private IInboundMessageNotification smppInboundMessageNotification; + public void setSmppInboundMessageNotification( IInboundMessageNotification smppInboundMessageNotification ) + { + this.smppInboundMessageNotification = smppInboundMessageNotification; + } + private OutboundSmsService outboundSmsService; + public void setOutboundSmsService( OutboundSmsService outboundSmsService ) + { + this.outboundSmsService = outboundSmsService; + } + private SmsPublisher smsPublisher; + public void setSmsPublisher( SmsPublisher smsPublisher ) + { + this.smsPublisher = smsPublisher; + } + + // ------------------------------------------------------------------------- + // OutboundSmsTransportService implementation + // ------------------------------------------------------------------------- + @Override public Map<String, String> getGatewayMap() { - if ( gatewayMap == null || gatewayMap.isEmpty() ) + if ( GATEWAY_MAP == null || GATEWAY_MAP.isEmpty() ) { reloadConfig(); } - return gatewayMap; + return GATEWAY_MAP; } @Override @@ -117,7 +136,6 @@ message = "Unable to stop smsLib service" + e.getCause().getMessage(); log.warn( "Unable to stop smsLib service", e ); } - } @Override @@ -130,7 +148,7 @@ try { getService().startService(); - if ( gatewayMap.containsKey( SMPP_GATEWAY ) ) + if ( GATEWAY_MAP.containsKey( SMPP_GATEWAY ) ) { getService().setInboundMessageNotification( smppInboundMessageNotification ); } @@ -206,25 +224,23 @@ if ( gatewayConfig instanceof BulkSmsGatewayConfig ) { - gatewayMap.put( BULK_GATEWAY, gateway.getGatewayId() ); + GATEWAY_MAP.put( BULK_GATEWAY, gateway.getGatewayId() ); } else if ( gatewayConfig instanceof ClickatellGatewayConfig ) { - gatewayMap.put( CLICKATELL_GATEWAY, gateway.getGatewayId() ); + GATEWAY_MAP.put( CLICKATELL_GATEWAY, gateway.getGatewayId() ); } else if ( gatewayConfig instanceof GenericHttpGatewayConfig ) { - gatewayMap.put( HTTP_GATEWAY, gateway.getGatewayId() ); + GATEWAY_MAP.put( HTTP_GATEWAY, gateway.getGatewayId() ); } else if ( gatewayConfig instanceof SMPPGatewayConfig ) { - gatewayMap.put( SMPP_GATEWAY, gateway.getGatewayId() ); - // Service.getInstance().setInboundMessageNotification( - // new InboundNotification() ); + GATEWAY_MAP.put( SMPP_GATEWAY, gateway.getGatewayId() ); } else { - gatewayMap.put( MODEM_GATEWAY, gateway.getGatewayId() ); + GATEWAY_MAP.put( MODEM_GATEWAY, gateway.getGatewayId() ); } log.debug( "Added gateway " + gatewayConfig.getName() ); @@ -292,23 +308,23 @@ if ( gatewayConfig instanceof BulkSmsGatewayConfig ) { - gatewayId = gatewayMap.get( BULK_GATEWAY ); + gatewayId = GATEWAY_MAP.get( BULK_GATEWAY ); } else if ( gatewayConfig instanceof ClickatellGatewayConfig ) { - gatewayId = gatewayMap.get( CLICKATELL_GATEWAY ); + gatewayId = GATEWAY_MAP.get( CLICKATELL_GATEWAY ); } else if ( gatewayConfig instanceof GenericHttpGatewayConfig ) { - gatewayId = gatewayMap.get( HTTP_GATEWAY ); + gatewayId = GATEWAY_MAP.get( HTTP_GATEWAY ); } else if ( gatewayConfig instanceof SMPPGatewayConfig ) { - gatewayId = gatewayMap.get( SMPP_GATEWAY ); + gatewayId = GATEWAY_MAP.get( SMPP_GATEWAY ); } else { - gatewayId = gatewayMap.get( MODEM_GATEWAY ); + gatewayId = GATEWAY_MAP.get( MODEM_GATEWAY ); } return gatewayId; @@ -393,6 +409,7 @@ OutboundMessage outboundMessage = new OutboundMessage( recipient, sms.getMessage() ); // Check if text contain any specific unicode character + for ( char each : sms.getMessage().toCharArray() ) { if ( !Character.UnicodeBlock.of( each ).equals( UnicodeBlock.BASIC_LATIN ) ) @@ -517,34 +534,4 @@ { getService().removeGroup( groupName ); } - - public IInboundMessageNotification getSmppInboundMessageNotification() - { - return smppInboundMessageNotification; - } - - public void setSmppInboundMessageNotification( IInboundMessageNotification smppInboundMessageNotification ) - { - this.smppInboundMessageNotification = smppInboundMessageNotification; - } - - public OutboundSmsService getOutboundSmsService() - { - return outboundSmsService; - } - - public void setOutboundSmsService( OutboundSmsService outboundSmsService ) - { - this.outboundSmsService = outboundSmsService; - } - - public SmsPublisher getSmsPublisher() - { - return smsPublisher; - } - - public void setSmsPublisher( SmsPublisher smsPublisher ) - { - this.smsPublisher = smsPublisher; - } }
_______________________________________________ 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