=== 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 2012-03-12 20:25:54 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSms.java 2012-11-20 13:34:03 +0000 @@ -60,6 +60,8 @@ private SmsMessageStatus status = SmsMessageStatus.INCOMING; private String statusMessage; + + private boolean parsed = false; /** * Incoming smses are one of two types, text or binary. @@ -179,4 +181,14 @@ this.statusMessage = statusMessage; } + public boolean isParsed() + { + return parsed; + } + + public void setParsed( boolean parsed ) + { + this.parsed = parsed; + } + } \ No newline at end of file === removed 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 2012-07-30 16:38:32 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java 1970-01-01 00:00:00 +0000 @@ -1,64 +0,0 @@ -package org.hisp.dhis.sms.incoming; - -import java.util.List; - -import org.smslib.InboundMessage; - -/* - * Copyright (c) 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. - */ - - -/** - * Service providing support for retrieving incoming SMSes. - */ -public interface IncomingSmsService -{ - String ID = IncomingSmsService.class.getName(); - - /** - * Get the next sms incoming for processing, if any. - * - * @return the oldest sms in the INCOMING state. - */ - IncomingSms getNextUnprocessed(); - - void update( IncomingSms sms ); - - IncomingSms findBy ( Integer id ); - - List listAllMessage(); - - List listAllMessageFromModem(); - - void deleteAllFromModem(); - - void deleteById( Integer id ); - - List getMsgList(); - - void save ( IncomingSms sms ); -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java 2012-06-06 07:48:54 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java 1970-01-01 00:00:00 +0000 @@ -1,60 +0,0 @@ -package org.hisp.dhis.sms.incoming; - -/* - * Copyright (c) 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.Collection; - -/** - * Store for incoming SMS messages. - */ -public interface IncomingSmsStore -{ - static final String ID = IncomingSmsStore.class.getName(); - - int save( IncomingSms incomingSms ); - - void update ( IncomingSms incomingSms ); - - IncomingSms get( int id ); - - Collection getSmsByStatus( SmsMessageStatus status ); - - Collection getSmsByOriginator( String originator ); - - long getSmsCount(); - - Collection getAllSmses(); - - void delete( IncomingSms incomingSms); - -// public Collection getSms( String originator, Date startDate, Date endDate); -// -// public Collection getSmsByDate( Date startDate, Date endDate ); -// - -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java 2012-08-30 12:47:05 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java 1970-01-01 00:00:00 +0000 @@ -1,47 +0,0 @@ -package org.hisp.dhis.sms.incoming; - -import org.smslib.AGateway; -import org.smslib.IInboundMessageNotification; -import org.smslib.InboundMessage; -import org.smslib.Message.MessageTypes; - -public class SMPPInboundNotification - implements IInboundMessageNotification -{ - - private IncomingSmsService incomingSmsService; - - @Override - public void process( AGateway gateway, MessageTypes msgType, InboundMessage msg ) - { - - System.out.println( msg ); - - IncomingSms incomingSms = new IncomingSms(); - - incomingSms.setOriginator( msg.getOriginator() ); - - incomingSms.setEncoding( SmsMessageEncoding.ENC7BIT ); - - incomingSms.setSentDate( msg.getDate() ); - - incomingSms.setReceivedDate( msg.getDate() ); - - incomingSms.setText( msg.getText() ); - - incomingSms.setGatewayId( msg.getGatewayId() ); - - incomingSms.setStatus( SmsMessageStatus.PROCESSED ); - - incomingSms.setStatusMessage( "imported" ); - - incomingSmsService.save( incomingSms ); - - } - - public void setIncomingSmsService( IncomingSmsService incomingSmsService ) - { - this.incomingSmsService = incomingSmsService; - } - -} === modified file 'dhis-2/dhis-services/dhis-service-sms/pom.xml' --- dhis-2/dhis-services/dhis-service-sms/pom.xml 2012-11-15 08:44:31 +0000 +++ dhis-2/dhis-services/dhis-service-sms/pom.xml 2012-11-20 13:34:03 +0000 @@ -32,12 +32,6 @@ - org.apache.activemq - activemq-core - 5.7.0 - - - org.smslib smslib === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java 2012-08-30 12:47:05 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/DefaultInboundSmsService.java 2012-11-20 13:34:03 +0000 @@ -34,6 +34,7 @@ import org.hisp.dhis.sms.incoming.IncomingSmsStore; import org.hisp.dhis.sms.incoming.SmsMessageEncoding; import org.hisp.dhis.sms.incoming.SmsMessageStatus; +import org.hisp.dhis.sms.queue.MessageQueue; import org.smslib.InboundMessage; import org.smslib.Service; @@ -45,6 +46,13 @@ // ------------------------------------------------------------------------- private IncomingSmsStore incomingSmsStore; + + private MessageQueue incomingSmsQueue; + + public void setIncomingSmsQueue( MessageQueue incomingSmsQueue ) + { + this.incomingSmsQueue = incomingSmsQueue; + } public void setIncomingSmsStore( IncomingSmsStore incomingSmsStore ) { @@ -119,8 +127,7 @@ public void save( IncomingSms incomingSms ) { incomingSmsStore.save( incomingSms ); - - //TODO: run parser ? + incomingSmsQueue.put( incomingSms ); } @Override === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/HibernateIncomingSmsStore.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/HibernateIncomingSmsStore.java 2012-11-15 08:44:31 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/inbound/HibernateIncomingSmsStore.java 2012-11-20 13:34:03 +0000 @@ -29,8 +29,6 @@ import java.util.Collection; -import javax.jms.JMSException; - import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -40,7 +38,6 @@ import org.hisp.dhis.sms.incoming.IncomingSms; import org.hisp.dhis.sms.incoming.IncomingSmsStore; import org.hisp.dhis.sms.incoming.SmsMessageStatus; -import org.hisp.dhis.sms.parse.SMSPublisher; import org.springframework.transaction.annotation.Transactional; @Transactional @@ -53,7 +50,6 @@ private SessionFactory sessionFactory; - private SMSPublisher smsPublisher; public void setSessionFactory( SessionFactory sessionFactory ) { @@ -67,14 +63,6 @@ @Override public int save( IncomingSms sms ) { - try - { - smsPublisher.putObject( sms ); - } - catch ( JMSException e ) - { - e.printStackTrace(); - } return (Integer) sessionFactory.getCurrentSession().save( sms ); } @@ -134,33 +122,13 @@ sessionFactory.getCurrentSession().update( incomingSms ); } - // @Override - // public Collection getSms( String originator, Date startDate, - // Date endDate ) - // { - // Criteria crit = sessionFactory.getCurrentSession().createCriteria( - // IncomingSms.class ); - // if ( originator != null && !originator.equals( "" ) ) - // { - // crit.add( Restrictions.eq( "originator", originator ) ); - // } - // if ( startDate != null && endDate != null ) - // { - // crit.add( Restrictions.between( "receiveDate", startDate, endDate ) ); - // } - // return crit.list(); - // } - // - // @Override - // public Collection getSmsByDate( Date startDate, Date endDate - // ) - // { - // return getSms( null, startDate, endDate ); - // } - - public void setSmsPublisher( SMSPublisher smsPublisher ) + @SuppressWarnings( "unchecked" ) + @Override + public Collection getAllUnparsedSmses() { - this.smsPublisher = smsPublisher; + Criteria criteria = sessionFactory.getCurrentSession().createCriteria( IncomingSms.class ); + criteria.add( Restrictions.eq( "parsed", false ) ); + return criteria.list(); } } === added directory 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming' === added file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsService.java 2012-11-20 13:34:03 +0000 @@ -0,0 +1,67 @@ +package org.hisp.dhis.sms.incoming; + +import java.util.List; + +import org.hisp.dhis.sms.queue.MessageQueue; +import org.smslib.InboundMessage; + +/* + * Copyright (c) 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. + */ + + +/** + * Service providing support for retrieving incoming SMSes. + */ +public interface IncomingSmsService +{ + String ID = IncomingSmsService.class.getName(); + + /** + * Get the next sms incoming for processing, if any. + * + * @return the oldest sms in the INCOMING state. + */ + IncomingSms getNextUnprocessed(); + + void update( IncomingSms sms ); + + IncomingSms findBy ( Integer id ); + + List listAllMessage(); + + List listAllMessageFromModem(); + + void deleteAllFromModem(); + + void deleteById( Integer id ); + + List getMsgList(); + + void save ( IncomingSms sms ); + + public void setIncomingSmsQueue( MessageQueue incomingSmsQueue ); +} === added file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/IncomingSmsStore.java 2012-11-20 13:34:03 +0000 @@ -0,0 +1,57 @@ +package org.hisp.dhis.sms.incoming; + +/* + * Copyright (c) 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.Collection; + +/** + * Store for incoming SMS messages. + */ +public interface IncomingSmsStore +{ + static final String ID = IncomingSmsStore.class.getName(); + + int save( IncomingSms incomingSms ); + + void update ( IncomingSms incomingSms ); + + IncomingSms get( int id ); + + Collection getSmsByStatus( SmsMessageStatus status ); + + Collection getSmsByOriginator( String originator ); + + long getSmsCount(); + + Collection getAllSmses(); + + void delete( IncomingSms incomingSms); + + Collection getAllUnparsedSmses(); + +} === added file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/incoming/SMPPInboundNotification.java 2012-11-20 13:34:03 +0000 @@ -0,0 +1,47 @@ +package org.hisp.dhis.sms.incoming; + +import org.smslib.AGateway; +import org.smslib.IInboundMessageNotification; +import org.smslib.InboundMessage; +import org.smslib.Message.MessageTypes; + +public class SMPPInboundNotification + implements IInboundMessageNotification +{ + + private IncomingSmsService incomingSmsService; + + @Override + public void process( AGateway gateway, MessageTypes msgType, InboundMessage msg ) + { + + System.out.println( msg ); + + IncomingSms incomingSms = new IncomingSms(); + + incomingSms.setOriginator( msg.getOriginator() ); + + incomingSms.setEncoding( SmsMessageEncoding.ENC7BIT ); + + incomingSms.setSentDate( msg.getDate() ); + + incomingSms.setReceivedDate( msg.getDate() ); + + incomingSms.setText( msg.getText() ); + + incomingSms.setGatewayId( msg.getGatewayId() ); + + incomingSms.setStatus( SmsMessageStatus.PROCESSED ); + + incomingSms.setStatusMessage( "imported" ); + + incomingSmsService.save( incomingSms ); + + } + + public void setIncomingSmsService( IncomingSmsService incomingSmsService ) + { + this.incomingSmsService = incomingSmsService; + } + +} === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java 2012-11-15 08:44:31 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSConsumer.java 2012-11-20 13:34:03 +0000 @@ -1,122 +1,85 @@ package org.hisp.dhis.sms.parse; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.activemq.broker.BrokerService; import org.hisp.dhis.sms.incoming.IncomingSms; -import org.springframework.beans.factory.InitializingBean; +import org.hisp.dhis.sms.queue.MessageQueue; // IEatSMS -public class SMSConsumer implements InitializingBean { +public class SMSConsumer +{ private ParserManager parserManager; - private ConnectionFactory factory; - - private String brokerURL; - - private String queue; + private MessageQueue messageQueue; + + public void setMessageQueue( MessageQueue messageQueue ) + { + this.messageQueue = messageQueue; + } SMSConsumerThread thread; - public void start() { - if (thread == null) { + public void start() + { + messageQueue.initialize(); + if ( thread == null ) + { thread = new SMSConsumerThread(); thread.start(); } } - public void setBrokerURL(String brokerURL) { - this.brokerURL = brokerURL; - } - - public void setQueue(String queue) { - this.queue = queue; - } - - public void setFactory(ConnectionFactory factory) { - this.factory = factory; - } - - public void setParserManager(ParserManager parserManager) { + public void setParserManager( ParserManager parserManager ) + { this.parserManager = parserManager; } - public void stop() { + public void stop() + { thread.stopFetching(); thread = null; } - @Override - public void afterPropertiesSet() throws Exception { - BrokerService broker = new BrokerService(); - broker.setPersistent(true); - broker.addConnector(brokerURL); - broker.start(); - } - - private class SMSConsumerThread extends Thread { + private class SMSConsumerThread + extends Thread + { private boolean stop; - public void run() { - while (!stop) { - try{ + public void run() + { + while ( !stop ) + { + try + { fetchAndParseSMS(); - }catch(Exception e){ - // ignore - } - try { - // Maybe we should speed up on successful receive? - Thread.sleep(3000); - } catch (InterruptedException e) { + } + catch ( Exception e ) + { + // ignore + } + try + { + Thread.sleep( 3000 ); + } + catch ( InterruptedException e ) + { e.printStackTrace(); } } } - /* Returns true when a message is found */ - private void fetchAndParseSMS() { - - try { - Connection connection = factory.createConnection(); - connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue destination = session.createQueue(queue); - MessageConsumer c = session.createConsumer(destination); - - // Wait the maximum time of one second - Message m = c.receive(1000); - while (m != null) { - if (m instanceof ObjectMessage) { - ObjectMessage objMessage = (ObjectMessage) m; - if (objMessage.getObject() instanceof IncomingSms) { - IncomingSms sms = (IncomingSms) objMessage.getObject(); - parserManager.parse(sms); - } - } - m = c.receive(1000); - } - - connection.close(); - session.close(); - - - } catch (JMSException e) { - e.printStackTrace(); - + private void fetchAndParseSMS() + { + IncomingSms message = messageQueue.get(); + while ( message != null ) + { + parserManager.parse( message ); + messageQueue.remove( message ); + message = messageQueue.get(); } } - public void stopFetching() { + public void stopFetching() + { this.stop = true; } === removed file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSPublisher.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSPublisher.java 2012-11-15 08:44:31 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/parse/SMSPublisher.java 1970-01-01 00:00:00 +0000 @@ -1,44 +0,0 @@ -package org.hisp.dhis.sms.parse; - -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.hisp.dhis.sms.incoming.IncomingSms; - -public class SMSPublisher { - private ConnectionFactory factory; - - private String queue; - - public void putObject(IncomingSms sms) throws JMSException { - Connection connection = factory.createConnection(); - connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - ObjectMessage objMessage = session.createObjectMessage(); - objMessage.setObject(sms); - - Queue destination = session.createQueue(queue); - MessageProducer producer = session.createProducer(destination); - - producer.send(objMessage); - - session.close(); - connection.close(); - } - - public void setFactory(ConnectionFactory factory) { - this.factory = factory; - } - - public void setQueue(String queue) { - this.queue = queue; - } - -} === added directory 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/queue' === added file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/queue/DatabaseSupportedInternalMemoryMessageQueue.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/queue/DatabaseSupportedInternalMemoryMessageQueue.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/queue/DatabaseSupportedInternalMemoryMessageQueue.java 2012-11-20 13:34:03 +0000 @@ -0,0 +1,53 @@ +package org.hisp.dhis.sms.queue; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.hisp.dhis.sms.incoming.IncomingSms; +import org.hisp.dhis.sms.incoming.IncomingSmsStore; + +public class DatabaseSupportedInternalMemoryMessageQueue + implements MessageQueue +{ + + List queue = new ArrayList(); + + private IncomingSmsStore smsStore; + + @Override + public void put( IncomingSms message ) + { + queue.add( message ); + } + + @Override + public IncomingSms get() + { + return queue.get( 0 ); + } + + @Override + public void remove( IncomingSms message ) + { + message.setParsed( true ); + smsStore.update( message ); + queue.remove( message ); + } + + @Override + public void initialize() + { + Collection messages = smsStore.getAllUnparsedSmses(); + if ( messages != null ) + { + queue.addAll( messages ); + } + } + + public void setSmsStore( IncomingSmsStore smsStore ) + { + this.smsStore = smsStore; + } + +} === added file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/queue/MessageQueue.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/queue/MessageQueue.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/queue/MessageQueue.java 2012-11-20 13:34:03 +0000 @@ -0,0 +1,16 @@ +package org.hisp.dhis.sms.queue; + +import org.hisp.dhis.sms.incoming.IncomingSms; + +public interface MessageQueue +{ + + public void put( IncomingSms message ); + + public IncomingSms get(); + + public void remove( IncomingSms message ); + + public void initialize(); + +} === 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-11-15 08:44:31 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java 2012-11-20 13:34:03 +0000 @@ -47,7 +47,6 @@ import org.hisp.dhis.sms.outbound.OutboundSmsStore; import org.hisp.dhis.sms.outbound.OutboundSmsTransportService; import org.hisp.dhis.sms.parse.SMSConsumer; -import org.hisp.dhis.sms.parse.SMSPublisher; import org.smslib.AGateway; import org.smslib.GatewayException; import org.smslib.IInboundMessageNotification; @@ -344,7 +343,7 @@ } try - { + { smsConsumer.start(); } catch ( Exception e1 ) @@ -510,8 +509,8 @@ public void deleteById( Integer outboundSmsId ) { OutboundSms sms = outboundSmsStore.get( outboundSmsId ); - - outboundSmsStore.delete( sms ); + + outboundSmsStore.delete( sms ); } } === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2012-11-15 08:44:31 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2012-11-20 13:34:03 +0000 @@ -5,46 +5,15 @@ - - - - - - + + + - - - - - - - - - vm://localhost:61616 - - - + + + @@ -78,11 +47,11 @@ - + + + === modified file 'dhis-2/dhis-services/pom.xml' --- dhis-2/dhis-services/pom.xml 2012-11-19 08:19:02 +0000 +++ dhis-2/dhis-services/pom.xml 2012-11-20 13:34:03 +0000 @@ -26,6 +26,7 @@ dhis-service-patient dhis-service-mobile dhis-service-integration + dhis-service-sms === modified file 'dhis-2/dhis-web/dhis-web-portal/pom.xml' --- dhis-2/dhis-web/dhis-web-portal/pom.xml 2012-11-16 14:01:45 +0000 +++ dhis-2/dhis-web/dhis-web-portal/pom.xml 2012-11-20 13:34:03 +0000 @@ -41,14 +41,12 @@ - org.hisp.dhis dhis-web-maintenance-datadictionary === modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/input/SMSInput.java' --- dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/input/SMSInput.java 2012-11-15 08:44:31 +0000 +++ dhis-2/dhis-web/dhis-web-sms/src/main/java/org/hisp/dhis/sms/input/SMSInput.java 2012-11-20 13:34:03 +0000 @@ -1,14 +1,9 @@ package org.hisp.dhis.sms.input; -import java.text.ParseException; - -import org.exolab.castor.types.Date; import org.hisp.dhis.sms.incoming.IncomingSms; -import org.hisp.dhis.sms.incoming.IncomingSmsStore; +import org.hisp.dhis.sms.incoming.IncomingSmsService; import org.hisp.dhis.sms.incoming.SmsMessageEncoding; import org.hisp.dhis.sms.incoming.SmsMessageStatus; -import org.hisp.dhis.sms.outbound.OutboundSmsService; -import org.hisp.dhis.sms.parse.ParserManager; import com.opensymphony.xwork2.Action; @@ -20,102 +15,39 @@ implements Action { - private String msisdn, sender, message, dca, reffering_batch, network_id, concat_reference, concat_num_segments, - concat_seq_num, received_time; - - private String source_id; // Probably like message id and should be an int - - private int msg_id; // unique for each sms - - private IncomingSms sms; - - private IncomingSmsStore smsStore; - - public SMSInput() - { - } + private String sender, message; + private IncomingSmsService incomingSmsService; @Override public String execute() throws Exception { + if(sender == null || message == null ){ + return ERROR; + } + System.out.println( "Sender: " + sender + ", Message: " + message ); IncomingSms sms = new IncomingSms(); sms.setText( message ); sms.setOriginator( sender ); - java.util.Date rec = null; - try - { - Date received = Date.parseDate( received_time ); - rec = received.toDate(); - } - catch ( ParseException pe ) - { - System.out.println( "ERROR: No received_time input" ); - return ERROR; - } + java.util.Date rec = new java.util.Date(); sms.setReceivedDate( rec ); - sms.setSentDate( rec ); // This should probably be removed from incoming - // SMS entirely. Though other gateways may use - // it? + sms.setSentDate( rec ); + sms.setEncoding( SmsMessageEncoding.ENC7BIT ); sms.setStatus( SmsMessageStatus.INCOMING ); - sms.setId( msg_id ); sms.setGatewayId( "HARDCODEDTESTGATEWAY" ); - smsStore.save( sms ); + incomingSmsService.save( sms ); + sender = null; + message = null; + return SUCCESS; } - public void setSmsStore( IncomingSmsStore smsStore ) - { - System.out.println( "Setting SMSStore: " + smsStore ); - this.smsStore = smsStore; - } - - public String getConcat_num_segments() - { - return concat_num_segments; - } - - public void setConcat_num_segments( String concat_num_segments ) - { - this.concat_num_segments = concat_num_segments; - } - - public String getConcat_reference() - { - return concat_reference; - } - - public void setConcat_reference( String concat_reference ) - { - this.concat_reference = concat_reference; - } - - public String getConcat_seq_num() - { - return concat_seq_num; - } - - public void setConcat_seq_num( String concat_seq_num ) - { - this.concat_seq_num = concat_seq_num; - } - - public String getDca() - { - return dca; - } - - public void setDca( String dca ) - { - this.dca = dca; - } - public String getMessage() { return message; @@ -126,56 +58,6 @@ this.message = message; } - public int getMsg_id() - { - return msg_id; - } - - public void setMsg_id( int msg_id ) - { - this.msg_id = msg_id; - } - - public String getMsisdn() - { - return msisdn; - } - - public void setMsisdn( String msisdn ) - { - this.msisdn = msisdn; - } - - public String getNetwork_id() - { - return network_id; - } - - public void setNetwork_id( String network_id ) - { - this.network_id = network_id; - } - - public String getReceived_time() - { - return received_time; - } - - public void setReceived_time( String received_time ) - { - this.received_time = received_time; - } - - public String getReffering_batch() - { - return reffering_batch; - } - - public void setReffering_batch( String reffering_batch ) - { - this.reffering_batch = reffering_batch; - } - public String getSender() { return sender; @@ -186,25 +68,8 @@ this.sender = sender; } - public IncomingSms getSms() - { - return sms; - } - - public void setSms( IncomingSms sms ) - { - this.sms = sms; - } - - public String getSource_id() - { - return source_id; - } - - public void setSource_id( String source_id ) - { - this.source_id = source_id; - } - - + public void setIncomingSmsService( IncomingSmsService incomingSmsService ) + { + this.incomingSmsService = incomingSmsService; + } } === modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-sms/src/main/resources/META-INF/dhis/beans.xml 2012-11-15 08:44:31 +0000 +++ dhis-2/dhis-web/dhis-web-sms/src/main/resources/META-INF/dhis/beans.xml 2012-11-20 13:34:03 +0000 @@ -5,7 +5,7 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> - + === modified file 'dhis-2/dhis-web/pom.xml' --- dhis-2/dhis-web/pom.xml 2012-11-16 14:01:45 +0000 +++ dhis-2/dhis-web/pom.xml 2012-11-20 13:34:03 +0000 @@ -27,7 +27,8 @@ dhis-web-api-mobile dhis-web-light dhis-web-mobile - dhis-web-portal + dhis-web-portal + dhis-web-sms