dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11272
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3192: Switch to Polling from Callbacks for reading SMS. Saving incoming SMS into database
------------------------------------------------------------
revno: 3192
committer: Saptarshi <sunbiz@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-03-28 18:36:44 +0200
message:
Switch to Polling from Callbacks for reading SMS. Saving incoming SMS into database
removed:
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportSchedule.java
added:
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInbound.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java
dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms/
dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms/hibernate/
dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms/hibernate/Sms.hbm.xml
dhis-mobile/dhis-service-mobile/src/test/java/org/
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/CompressorTest.java
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/
dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java
dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/
dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties
modified:
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportJob.java
dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java
dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml
dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml
dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/SendSMS.hbm.xml
dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.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-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportJob.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportJob.java 2010-10-21 06:32:42 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportJob.java 2011-03-28 16:36:44 +0000
@@ -13,7 +13,6 @@
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
-
private MobileImportService mobileImportService;
public void setMobileImportService( MobileImportService mobileImportService )
@@ -29,12 +28,12 @@
}
// -------------------------------------------------------------------------
- // implementation
+ // Implementation
// -------------------------------------------------------------------------
-
+ @Override
protected void executeInternal( JobExecutionContext context ) throws JobExecutionException
{
- System.out.println("SMSImport Job Started at : "+new Date() );
+ System.out.println("SMSImport Job Started at : " + new Date() );
if( smsService == null && mobileImportService == null )
{
@@ -50,10 +49,9 @@
}
smsService.processPendingMessages();
-
mobileImportService.importPendingFiles();
- System.out.println("SMSImport Job Ended at : "+new Date() );
+ System.out.println("SMSImport Job Ended at : " + new Date() );
}
}
=== removed file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportSchedule.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportSchedule.java 2010-10-19 15:07:12 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/SMSImportSchedule.java 1970-01-01 00:00:00 +0000
@@ -1,77 +0,0 @@
-package org.hisp.dhis.mobile;
-
-import org.hisp.dhis.system.startup.AbstractStartupRoutine;
-
-public class SMSImportSchedule extends AbstractStartupRoutine
-{
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
-
- @Override
- public void execute() throws Exception
- {
- System.out.println("*************Inside SMSImportShedule execute method");
- //specify your sceduler task details
- /*JobDetail job = new JobDetail();
- job.setName("SMSImport");
- job.setJobClass(SMSImportJob.class);
-
-
- //configure the scheduler time
- SimpleTrigger trigger = new SimpleTrigger();
- trigger.setName("SMSImportScheduler");
- trigger.setStartTime(new Date(System.currentTimeMillis() + 1000));
- trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
- trigger.setRepeatInterval(30000);
-
- //schedule it
- Scheduler scheduler = new StdSchedulerFactory().getScheduler();
-
- scheduler.start();
-
- scheduler.scheduleJob(job, trigger);*/
-
-
-
- }
-
- //public SMSImportSchedule()throws Exception
- //{
- /*
- //specify your sceduler task details
- JobDetail job = new JobDetail();
- job.setName("SMSImport");
- job.setJobClass(SMSImportJob.class);
-
- //configure the scheduler time
- SimpleTrigger trigger = new SimpleTrigger();
- trigger.setName("SMSImportScheduler");
- trigger.setStartTime(new Date(System.currentTimeMillis() + 1000));
- trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
- trigger.setRepeatInterval(30000);
-
- //schedule it
- Scheduler scheduler = new StdSchedulerFactory().getScheduler();
- scheduler.start();
-
- scheduler.scheduleJob(job, trigger);
- */
-
- /*
- SchedulerFactory sf = new StdSchedulerFactory();
- Scheduler sched = sf.getScheduler();
-
- JobDetail jd = new JobDetail("SMSImportJob","SMSImportGroup",SMSImportJob.class);
-
- CronTrigger ct=new CronTrigger("SMSImportTrigger","SMSImportTringerGroup","0 0 13 * * ?");
- sched.scheduleJob(jd,ct);
- //CronTrigger ct = new CronTrigger("SMSImportTrigger","SMSImportGroup", "SMSImportJob", "SMSImportGroup", "0 0 12 * * ?");
- //sched.addJob(jd, true);
-
- sched.start();
- */
-
- //}
-}
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java 2010-12-30 05:17:07 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/api/ReceiveSMS.java 2011-03-28 16:36:44 +0000
@@ -5,7 +5,6 @@
public class ReceiveSMS implements Serializable
{
-
/**
* Sender Phone Number with time of Received, Unique and Required.
*/
=== added directory 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms'
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStore.java 2011-03-28 16:36:44 +0000
@@ -0,0 +1,111 @@
+package org.hisp.dhis.mobile.sms;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.mobile.sms.api.SmsInbound;
+import org.hisp.dhis.mobile.sms.api.SmsInboundStore;
+
+/**
+ *
+ * @author Saptarshi
+ */
+public class HibernateSmsInboundStore implements SmsInboundStore
+{
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+ private SessionFactory sessionFactory;
+
+ public void setSessionFactory( SessionFactory sessionFactory )
+ {
+ this.sessionFactory = sessionFactory;
+ }
+
+ // -------------------------------------------------------------------------
+ // Implementation
+ // -------------------------------------------------------------------------
+ @Override
+ public void saveSms( SmsInbound sms )
+ {
+ sessionFactory.getCurrentSession().save( sms );
+ }
+
+ @Override
+ public Collection<SmsInbound> getSmsByDate( Date startDate, Date endDate )
+ {
+ return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class )
+ .add( Restrictions.between("receiveDate", startDate, endDate) )
+ .list();
+ }
+
+ @Override
+ public Collection<SmsInbound> getSmsByOriginator( String originator )
+ {
+ return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class )
+ .add(Restrictions.eq("originator", originator))
+ .list();
+ }
+
+ @Override
+ public Collection<SmsInbound> getSmsByProcess( int process )
+ {
+ return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class )
+ .add(Restrictions.eq("process", process))
+ .list();
+ }
+
+ @Override
+ public Collection<SmsInbound> getAllReceiveSMS()
+ {
+ return sessionFactory.getCurrentSession().createCriteria( SmsInbound.class ).list();
+ }
+
+ @Override
+ public void updateSms( SmsInbound sms )
+ {
+ sessionFactory.getCurrentSession().update( sms );
+ }
+
+ @Override
+ public long getSmsCount()
+ {
+ Session session = sessionFactory.getCurrentSession();
+ Criteria criteria = session.createCriteria( SmsInbound.class );
+ criteria.setProjection( Projections.rowCount() );
+ Long count = (Long) criteria.uniqueResult();
+ return count != null ? count.longValue() : (long) 0;
+ }
+}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/SmsService.java 2011-03-28 16:36:44 +0000
@@ -0,0 +1,568 @@
+package org.hisp.dhis.mobile.sms;
+
+/*
+ * Copyright (c) 2004-2010, 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.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import org.hisp.dhis.mobile.sms.api.SmsInbound;
+import org.smslib.AGateway;
+import org.smslib.AGateway.Protocols;
+import org.smslib.GatewayException;
+import org.smslib.ICallNotification;
+import org.smslib.IInboundMessageNotification;
+import org.smslib.IOrphanedMessageNotification;
+import org.smslib.IOutboundMessageNotification;
+import org.smslib.IQueueSendingNotification;
+import org.smslib.InboundMessage;
+import org.smslib.Message.MessageEncodings;
+import org.smslib.Message.MessageTypes;
+import org.smslib.OutboundMessage;
+import org.smslib.OutboundWapSIMessage;
+import org.smslib.OutboundWapSIMessage.WapSISignals;
+import org.smslib.Service;
+import org.smslib.TimeoutException;
+import org.smslib.helper.Logger;
+import org.smslib.modem.SerialModemGateway;
+
+/*
+ * This class provides services for communicating over Sms
+ * @author Saptarshi Purkayastha
+ */
+public class SmsService
+{
+
+ /*------------------------------------------------------------------
+ * Dependencies
+ ------------------------------------------------------------------*/
+ HibernateSmsInboundStore hibernateSmsInboundStore;
+
+ public void setHibernateSmsStore( HibernateSmsInboundStore hibernateSmsInboundStore )
+ {
+ this.hibernateSmsInboundStore = hibernateSmsInboundStore;
+ }
+
+ /*------------------------------------------------------------------
+ * Implementation
+ ------------------------------------------------------------------*/
+ private Properties props;
+
+ private InboundNotification inboundNotification;
+
+ private OutboundNotification outboundNotification;
+
+ private CallNotification callNotification;
+
+ private QueueSendingNotification queueSendingNotification;
+
+ private OrphanedMessageNotification orphanedMessageNotification;
+
+ /*
+ * Constructor called when SmsService is loaded
+ */
+ public SmsService()
+ {
+ Service.getInstance().setInboundMessageNotification( inboundNotification );
+ Service.getInstance().setOutboundMessageNotification( outboundNotification );
+ Service.getInstance().setCallNotification( callNotification );
+ Service.getInstance().setOrphanedMessageNotification( orphanedMessageNotification );
+ Service.getInstance().setQueueSendingNotification( queueSendingNotification );
+ }
+
+ /*------------------------------------------------------------------
+ * Service methods
+ ------------------------------------------------------------------*/
+ /**
+ * Method to start the service, if it is stopped
+ * @return The message to be displayed on UI after attempt to start the service
+ */
+ //<editor-fold defaultstate="collapsed" desc="startSmsService()">
+ public String startSmsService()
+ {
+ if ( Service.getInstance().getServiceStatus() == Service.ServiceStatus.STOPPED )
+ {
+ try
+ {
+ String result = loadConfiguration();
+ if ( !result.contains( "ERROR" ) )
+ {
+ Service.getInstance().startService();
+ }
+ return result;
+ } catch ( Exception ex )
+ {
+ return "ERROR";
+ }
+ } else
+ {
+ return "CANNOT START: SERVICE ALREADY STARTING/STARTED/STOPPING";
+ }
+ }
+ //</editor-fold>
+
+ /**
+ * Method to stop the service, if it is started
+ * @return The message to be displayed on UI after attempt to stop the service
+ */
+ //<editor-fold defaultstate="collapsed" desc="stopSmsService()">
+ public String stopSmsService()
+ {
+ if ( Service.getInstance().getServiceStatus() == Service.ServiceStatus.STARTED )
+ {
+ try
+ {
+ Service.getInstance().stopService();
+ return "SERVICE STOPPED";
+ } catch ( Exception ex )
+ {
+ return "ERROR";
+ }
+ } else
+ {
+ return "SERVICE ALREADY STOPPED";
+ }
+ }
+ //</editor-fold>
+
+ /**
+ * To check if SmsService is running or not
+ * @return true is service is started
+ */
+ //<editor-fold defaultstate="collapsed" desc="isServiceRunning()">
+ public boolean isServiceRunning()
+ {
+ if ( Service.getInstance().getServiceStatus() == Service.ServiceStatus.STARTED )
+ {
+ return true;
+ } else
+ {
+ return false;
+ }
+ }
+ //</editor-fold>
+
+ /**
+ * Sends the OTA (Over-the-Air) message required to download settings, application or multimedia messages
+ * @param recipient The phone number of the recipient
+ * @param url The download URL
+ * @param prompt The message to be displayed to the recipient
+ * @return The message to be displayed on UI after attempt to send OTA message
+ */
+ //<editor-fold defaultstate="collapsed" desc="sendOtaMessages">
+ public String sendOtaMessage( String recipient, String url, String prompt )
+ {
+ String status = new String();
+ try
+ {
+ OutboundWapSIMessage wapMsg = new OutboundWapSIMessage( recipient, new URL( url ), prompt );
+ wapMsg.setSignal( WapSISignals.HIGH );
+ if ( isServiceRunning() )
+ {
+ Service.getInstance().sendMessage( wapMsg );
+ status = "WAP MESSAGE SENT";
+ } else
+ {
+ status = "SERVICE IS NOT RUNNING";
+ }
+ } catch ( Exception e )
+ {
+ status = "ERROR SENDING WAP MSG";
+ }
+ Logger.getInstance().logInfo( status, null, null );
+ return status;
+ }
+ //</editor-fold>
+
+ /**
+ * Sends an SMS to group of users that is a list of phone numbers of recipients
+ * @param groupName The name of the group of users
+ * @param recepients A List of phone numbers
+ * @param msg The message to be sent to the group
+ * @return The message to be displayed on UI after attempt to send SMS to a group of users
+ */
+ //<editor-fold defaultstate="collapsed" desc="sendMessageToGroup">
+ public String sendMessageToGroup( String groupName, List<String> recipients, String msg )
+ {
+ if ( isServiceRunning() )
+ {
+ Service.getInstance().createGroup( groupName );
+ for ( String recepient : recipients )
+ {
+ Service.getInstance().addToGroup( groupName, recepient );
+ }
+ OutboundMessage message = new OutboundMessage( groupName, msg );
+
+ try
+ {
+ Service.getInstance().sendMessage( message );
+ Logger.getInstance().logInfo( "Message Sent to Group: " + groupName, null, null );
+ return "SUCCESS";
+ } catch ( TimeoutException ex )
+ {
+ Logger.getInstance().logError( "Timeout error in sending message", ex, null );
+ return "ERROR";
+ } catch ( GatewayException ex )
+ {
+ Logger.getInstance().logError( "Gateway Exception in sending message", ex, null );
+ return "ERROR";
+ } catch ( IOException ex )
+ {
+ Logger.getInstance().logError( "IO Exception in sending message", ex, null );
+ return "ERROR";
+ } catch ( InterruptedException ex )
+ {
+ Logger.getInstance().logError( "Interrupted Exception in sending message", ex, null );
+ return "ERROR";
+ } finally
+ {
+ Service.getInstance().removeGroup( groupName );
+ }
+ } else
+ {
+ Logger.getInstance().logError( "Service not running", null, null );
+ return "SERVICE NOT RUNNING";
+ }
+ }
+ //</editor-fold>
+
+ /*------------------------------------------------------------------
+ * SMSLIB CALLBACKS NOT IMPLEMENTED - ONLY USED FOR LOGGING
+ ------------------------------------------------------------------*/
+ //<editor-fold defaultstate="collapsed" desc="smslib callbacks">
+ class InboundNotification implements IInboundMessageNotification
+ {
+
+ @Override
+ public void process( org.smslib.AGateway gateway, MessageTypes msgType, InboundMessage msg )
+ {
+ Logger.getInstance().logInfo( "Received new message from: " + msg.getOriginator(), null, null );
+ }
+ }
+
+ class OutboundNotification implements IOutboundMessageNotification
+ {
+
+ @Override
+ public void process( org.smslib.AGateway gateway, org.smslib.OutboundMessage msg )
+ {
+ Logger.getInstance().logInfo( "Attempting or failed to send message from queue to: " + msg.getRecipient(), null, null );
+ }
+ }
+
+ class CallNotification implements ICallNotification
+ {
+
+ @Override
+ public void process( org.smslib.AGateway gateway, String callerId )
+ {
+ Logger.getInstance().logInfo( "Receiving call from: " + callerId, null, null );
+ }
+ }
+
+ class QueueSendingNotification implements IQueueSendingNotification
+ {
+
+ @Override
+ public void process( org.smslib.AGateway gateway, OutboundMessage msg )
+ {
+ Logger.getInstance().logInfo( "**** >>>> Now Sending: " + msg.getRecipient(), null, gateway.getGatewayId() );
+ }
+ }
+
+ class OrphanedMessageNotification implements IOrphanedMessageNotification
+ {
+
+ @Override
+ public boolean process( org.smslib.AGateway gateway, InboundMessage msg )
+ {
+ System.out.println( "&&&&&&&&&&&&&&&&& ORPHANED INFO &&&&&&&&&&&&&&&&&" );
+ System.out.println( msg );
+ System.out.println( "&&&&&&&&&&&&&&&&& ORPHANED INFO &&&&&&&&&&&&&&&&&" );
+ Logger.getInstance().logInfo( "Leaving orphaned message in queue ", null, gateway.getGatewayId() );
+ // Return FALSE to leave orphaned parts in memory.
+ return false;
+ }
+ }
+ //</editor-fold>
+
+ /*------------------------------------------------------------------
+ * Helper Methods
+ ------------------------------------------------------------------*/
+ public Properties getProperties()
+ {
+ return props;
+ }
+
+ //<editor-fold defaultstate="collapsed" desc="readMessages()">
+ /**
+ * Read the messages from the memory location and save it in the sms_inbound
+ */
+ void readMessages()
+ {
+ List<InboundMessage> msgList = new ArrayList<InboundMessage>();
+ try
+ {
+ // Read the messages from SIM memory location, which are Inbound messages
+ Service.getInstance().readMessages( msgList, InboundMessage.MessageClasses.ALL );
+ if ( msgList.size() > 0 )
+ {
+ for ( InboundMessage msg : msgList )
+ {
+ //Creating sms to store in database
+ SmsInbound sms = new SmsInbound();
+
+ //Set sms encoding
+ if(msg.getEncoding() == MessageEncodings.ENC7BIT)
+ sms.setEncoding( '7' );
+ else if(msg.getEncoding() == MessageEncodings.ENC8BIT)
+ sms.setEncoding( '8' );
+ else if(msg.getEncoding() == MessageEncodings.ENCUCS2)
+ sms.setEncoding( 'U' );
+
+ sms.setGatewayId( msg.getGatewayId());
+ sms.setMessageDate( msg.getDate() );
+ sms.setOriginalReceiveDate( msg.getDate() );
+ sms.setOriginalRefNo( String.valueOf( msg.getMpRefNo() ) );
+ sms.setOriginator( msg.getOriginator() );
+ sms.setProcess( 0 );
+ sms.setReceiveDate( msg.getDate());
+ sms.setText( msg.getText() );
+ sms.setType( 'I' );
+
+ //saving sms into database
+ hibernateSmsInboundStore.saveSms( sms );
+
+ //Delete message based on configuration
+ if ( getProperties().getProperty( "settings.delete_after_processing", "no" ).equalsIgnoreCase( "yes" ) )
+ {
+ Service.getInstance().deleteMessage( msg );
+ }
+ }
+ }
+ } catch ( Exception e )
+ {
+ Logger.getInstance().logError( "SMSServer: reading messages exception!", e, null );
+ }
+ }
+ //</editor-fold>
+
+ /*void sendMessages()
+ {
+ boolean foundOutboundGateway = false;
+ for ( org.smslib.AGateway gtw : Service.getInstance().getGateways() )
+ {
+ if ( gtw.isOutbound() )
+ {
+ foundOutboundGateway = true;
+ break;
+ }
+ }
+ if ( foundOutboundGateway )
+ {
+ List<OutboundMessage> msgList = new ArrayList<OutboundMessage>();
+ try
+ {
+ for ( Interface<? extends Object> inf : getInfList() )
+ {
+ if ( inf.isOutbound() )
+ {
+ msgList.addAll( inf.getMessagesToSend() );
+ }
+ }
+ } catch ( Exception e )
+ {
+ Logger.getInstance().logError( "SMSServer: sending messages exception!", e, null );
+ }
+ if ( getProperties().getProperty( "settings.send_mode", "sync" ).equalsIgnoreCase( ( "sync" ) ) )
+ {
+ Logger.getInstance().logInfo( "SMSServer: sending synchronously...", null, null );
+ for ( OutboundMessage msg : msgList )
+ {
+ try
+ {
+ Service.getInstance().sendMessage( msg );
+ for ( Interface<? extends Object> inf : getInfList() )
+ {
+ if ( inf.isOutbound() )
+ {
+ inf.markMessage( msg );
+ }
+ }
+ } catch ( Exception e )
+ {
+ Logger.getInstance().logError( "SMSServer: sending messages exception!", e, null );
+ try
+ {
+ for ( Interface<? extends Object> inf : getInfList() )
+ {
+ if ( inf.isOutbound() )
+ {
+ inf.markMessage( msg );
+ }
+ }
+ } catch ( Exception e1 )
+ {
+ Logger.getInstance().logError( "SMSServer: sending messages exception!", e1, null );
+ }
+ }
+ }
+ } else
+ {
+ Logger.getInstance().logInfo( "SMSServer: sending asynchronously... [" + msgList.size() + "]", null, null );
+ for ( OutboundMessage msg : msgList )
+ {
+ if ( !Service.getInstance().queueMessage( msg ) )
+ {
+ try
+ {
+ for ( Interface<? extends Object> inf : getInfList() )
+ {
+ if ( inf.isOutbound() )
+ {
+ inf.markMessage( msg );
+ }
+ }
+ } catch ( Exception e )
+ {
+ Logger.getInstance().logError( "SMSServer: sending messages exception!", e, null );
+ }
+ }
+ }
+ }
+ }
+ }*/
+
+ /**
+ * Loads the configuration settings from SMSServer.conf, which should be located in the DHIS2_HOME directory
+ * @return The message to be displayed on UI after loading of configuration from file is complete
+ * @throws Exception
+ */
+ //<editor-fold defaultstate="collapsed" desc=" Load Configuration from DHIS2 HOME ">
+ private String loadConfiguration() throws Exception
+ {
+ String configFile = System.getenv( "DHIS2_HOME" ) + File.separator + "SMSServer.conf";
+
+ if ( new File( configFile ).exists() )
+ {
+ //Remove all existing gateways
+ Collection<AGateway> gateways = Service.getInstance().getGateways();
+ for ( AGateway gateway : gateways )
+ {
+ Service.getInstance().removeGateway( gateway );
+ }
+
+ //Load properties from configuration file
+ FileInputStream f = new FileInputStream( configFile );
+ this.props = new Properties();
+ getProperties().load( f );
+ f.close();
+
+ //Add gateway to service based on configuration file
+ //<editor-fold defaultstate="collapsed" desc=" Get Gateway & Configuration ">
+ for ( int i = 0; i < Integer.MAX_VALUE; i++ )
+ {
+ try
+ {
+ String propName = "gateway." + i;
+ String propValue = getProperties().getProperty( propName, "" ).trim();
+ if ( propValue.length() == 0 )
+ {
+ break;
+ }
+ String modemName = propValue.split( "\\," )[0].trim();
+ String port = getProperties().getProperty( modemName + ".port" );
+ int baudRate = Integer.parseInt( getProperties().getProperty( modemName + ".baudrate" ) );
+ String manufacturer = getProperties().getProperty( modemName + ".manufacturer" );
+ String model = getProperties().getProperty( modemName + ".model" );
+ String protocol = getProperties().getProperty( modemName + ".protocol" );
+ String pin = getProperties().getProperty( modemName + ".pin" );
+ String inbound = getProperties().getProperty( modemName + ".inbound" );
+ String outbound = getProperties().getProperty( modemName + ".outbound" );
+ String simMemLocation = getProperties().getProperty( modemName + ".simMemLocation" );
+
+ // TODO: DETECT MODEM CLASS AND INSTANTIATE
+ SerialModemGateway gateway = new SerialModemGateway( modemName, port, baudRate, manufacturer, model );
+
+ if ( simMemLocation != null && !simMemLocation.equals( "-" ) )
+ {
+ gateway.getATHandler().setStorageLocations( simMemLocation );
+ }
+
+ if ( protocol != null && protocol.equalsIgnoreCase( "PDU" ) )
+ {
+ gateway.setProtocol( Protocols.PDU );
+ } else
+ {
+ if ( protocol != null && protocol.equalsIgnoreCase( "TEXT" ) )
+ {
+ gateway.setProtocol( Protocols.TEXT );
+
+ } else
+ {
+ gateway.setProtocol( Protocols.PDU );
+ }
+ }
+ if ( pin != null )
+ {
+ gateway.setSimPin( pin );
+ }
+
+ if ( inbound.equalsIgnoreCase( "yes" ) )
+ {
+ gateway.setInbound( true );
+ } else
+ {
+ gateway.setInbound( false );
+ }
+ if ( outbound.equalsIgnoreCase( "yes" ) )
+ {
+ gateway.setOutbound( true );
+ } else
+ {
+ gateway.setOutbound( false );
+ }
+ Logger.getInstance().logInfo( "SMSServer: added gateway " + i + " / ", null, null );
+ } catch ( Exception e )
+ {
+ Logger.getInstance().logError( "SMSServer: Unknown Gateway in configuration file!, " + e.getMessage(), null, null );
+ }
+ }
+ //</editor-fold>
+ return "SUCCESSFULLY STARTED SERVICE";
+ } else
+ {
+ return "ERROR LOADING CONFIGURATION FILE";
+ }
+ }
+ //</editor-fold>
+}
=== added directory 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api'
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInbound.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInbound.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInbound.java 2011-03-28 16:36:44 +0000
@@ -0,0 +1,248 @@
+package org.hisp.dhis.mobile.sms.api;
+
+/*
+ * Copyright (c) 2004-2007, 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.Serializable;
+import java.util.Date;
+import org.hisp.dhis.mobile.api.ReceiveSMS;
+
+/**
+ *
+ * @author Saptarshi
+ */
+public class SmsInbound implements Serializable
+{
+ // -------------------------------------------------------------------------
+ // Properties
+ // -------------------------------------------------------------------------
+ //<editor-fold defaultstate="collapsed" desc="Properties">
+ /*
+ * The table's primary key.
+ */
+ private Integer id;
+
+ /*
+ * When new rows (i.e. messages) are created, sets this field to 0.
+ * When datavalues successfully saved (completed), sets this field to 1.
+ * When datavalues cannot be saved (bounced), sets this field to 2.
+ */
+ private Integer process;
+
+ /*
+ * The originator of the received message.
+ */
+ private String originator;
+
+ /*
+ * "I" for inbound message, "S" for status report message.
+ */
+ private Character type;
+
+ /*
+ * "7" for 7bit, "8" for 8bit and "U" for Unicode/UCS2.
+ */
+ private Character encoding;
+
+ /*
+ * The message date (retrieved by the message headers).
+ */
+ private Date messageDate;
+
+ /*
+ * The datetime when message was received.
+ */
+ private Date receiveDate;
+
+ /*
+ * The body of the message.
+ */
+ private String text;
+
+ /*
+ * Available only for status report messages: refers to the RefNo of the original outbound message.
+ */
+ private String originalRefNo;
+
+ /*
+ * Available only for status report messages: refers to the receive date of the original outbound message.
+ */
+ private Date originalReceiveDate;
+
+ /*
+ * The ID of the gateway from which the message was received.
+ */
+ private String gatewayId;
+ //</editor-fold>
+
+ // -------------------------------------------------------------------------
+ // Getter-Setters
+ // -------------------------------------------------------------------------
+ //<editor-fold defaultstate="collapsed" desc="Getter-Setters">
+ public Character getEncoding()
+ {
+ return encoding;
+ }
+
+ public void setEncoding( Character encoding )
+ {
+ this.encoding = encoding;
+ }
+
+ public String getGatewayId()
+ {
+ return gatewayId;
+ }
+
+ public void setGatewayId( String gatewayId )
+ {
+ this.gatewayId = gatewayId;
+ }
+
+ public Integer getId()
+ {
+ return id;
+ }
+
+ public void setId( Integer id )
+ {
+ this.id = id;
+ }
+
+ public Date getMessageDate()
+ {
+ return messageDate;
+ }
+
+ public void setMessageDate( Date messageDate )
+ {
+ this.messageDate = messageDate;
+ }
+
+ public Date getOriginalReceiveDate()
+ {
+ return originalReceiveDate;
+ }
+
+ public void setOriginalReceiveDate( Date originalReceiveDate )
+ {
+ this.originalReceiveDate = originalReceiveDate;
+ }
+
+ public String getOriginalRefNo()
+ {
+ return originalRefNo;
+ }
+
+ public void setOriginalRefNo( String originalRefNo )
+ {
+ this.originalRefNo = originalRefNo;
+ }
+
+ public String getOriginator()
+ {
+ return originator;
+ }
+
+ public void setOriginator( String originator )
+ {
+ this.originator = originator;
+ }
+
+ public Integer getProcess()
+ {
+ return process;
+ }
+
+ public void setProcess( Integer process )
+ {
+ this.process = process;
+ }
+
+ public Date getReceiveDate()
+ {
+ return receiveDate;
+ }
+
+ public void setReceiveDate( Date receiveDate )
+ {
+ this.receiveDate = receiveDate;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public void setText( String text )
+ {
+ this.text = text;
+ }
+
+ public Character getType()
+ {
+ return type;
+ }
+
+ public void setType( Character type )
+ {
+ this.type = type;
+ }
+ //</editor-fold>
+
+ // -------------------------------------------------------------------------
+ // hashCode and equals
+ // -------------------------------------------------------------------------
+ //<editor-fold defaultstate="collapsed" desc="hashCode and equals">
+ @Override
+ public int hashCode()
+ {
+ return this.hashCode();
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+
+ if ( o == null )
+ {
+ return false;
+ }
+
+ if ( !(o instanceof ReceiveSMS) )
+ {
+ return false;
+ }
+ final SmsInbound other = (SmsInbound) o;
+ return o.equals( other );
+ }
+ //</editor-fold>
+}
=== added file 'dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java'
--- dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/sms/api/SmsInboundStore.java 2011-03-28 16:36:44 +0000
@@ -0,0 +1,55 @@
+package org.hisp.dhis.mobile.sms.api;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * The API for CRUD into the sms_incoming table
+ * @author Saptarshi
+ */
+public interface SmsInboundStore
+{
+
+ String ID = SmsInboundStore.class.getName();
+
+ void saveSms( SmsInbound sms );
+
+ Collection<SmsInbound> getSmsByDate( Date startDate, Date endDate);
+
+ Collection<SmsInbound> getSmsByOriginator (String originator);
+
+ Collection<SmsInbound> getSmsByProcess (int process);
+
+ Collection<SmsInbound> getAllReceiveSMS();
+
+ void updateSms (SmsInbound sms);
+
+ long getSmsCount();
+}
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2011-01-12 03:36:50 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/META-INF/dhis/beans.xml 2011-03-28 16:36:44 +0000
@@ -4,6 +4,13 @@
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+ <!--Version 2 Beans-->
+ <bean id="org.hisp.dhis.mobile.sms.api.SmsInboundStore"
+ class="org.hisp.dhis.mobile.sms.HibernateSmsInboundStore">
+ <property name="sessionFactory" ref="sessionFactory"/>
+ </bean>
+
+ <!-- ========================================================================================== -->
<!-- Service definitions -->
<bean id="org.hisp.dhis.mobile.SmsService"
class="org.hisp.dhis.mobile.SmsService">
@@ -57,7 +64,6 @@
</bean>
<!-- Send ACK Job -->
-
<bean id="org.hisp.dhis.mobile.SendSMSJob"
class="org.hisp.dhis.mobile.SendSMSJob">
<property name="smsService" ref="org.hisp.dhis.mobile.SmsService"/>
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml 2010-12-30 05:17:07 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/ReceiveSMS.hbm.xml 2011-03-28 16:36:44 +0000
@@ -1,15 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping>
- <class name="org.hisp.dhis.mobile.api.ReceiveSMS" table="receivesms">
-
- <id name="receiverInfo" column="receiverInfo" length="230" />
-
- <property name="receiveingMessage" column="smscontent" not-null="true" length="230"/>
-
- </class>
-</hibernate-mapping>
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+ <class name="org.hisp.dhis.mobile.api.ReceiveSMS" table="receivesms">
+ <id column="receiverInfo" length="230" name="receiverInfo"/>
+ <property column="smscontent" length="230" name="receiveingMessage" not-null="true"/>
+ </class>
+</hibernate-mapping>
=== modified file 'dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/SendSMS.hbm.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/SendSMS.hbm.xml 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/hibernate/SendSMS.hbm.xml 2011-03-28 16:36:44 +0000
@@ -1,14 +1,8 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.hisp.dhis.mobile.api.SendSMS" table="sendsms">
-
- <id name="senderInfo" column="senderinfo" length="230" />
-
- <property name="sendingMessage" column="smscontent" not-null="true" length="230"/>
-
+ <id column="senderinfo" length="230" name="senderInfo"/>
+ <property column="smscontent" length="230" name="sendingMessage" not-null="true"/>
</class>
</hibernate-mapping>
=== added directory 'dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms'
=== added directory 'dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms/hibernate'
=== added file 'dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms/hibernate/Sms.hbm.xml'
--- dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms/hibernate/Sms.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/main/resources/org/hisp/dhis/mobile/sms/hibernate/Sms.hbm.xml 2011-03-28 16:36:44 +0000
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+ <class name="org.hisp.dhis.mobile.sms.api.SmsInbound" table="sms_inbound">
+ <id column="id" name="id">
+ <generator class="native"/>
+ </id>
+ <property name="process">
+ <column default="0" name="process" not-null="true"/>
+ </property>
+ <property name="originator">
+ <column index="originator_index" name="originator" not-null="true"/>
+ </property>
+ <property name="type">
+ <column name="type" not-null="true"/>
+ </property>
+ <property name="encoding">
+ <column name="encoding" not-null="true"/>
+ </property>
+ <property name="messageDate">
+ <column name="message_date" not-null="true"/>
+ </property>
+ <property name="receiveDate">
+ <column name="receive_date" not-null="true"/>
+ </property>
+ <property column="text" name="text"/>
+ <property column="original_ref_no" name="originalRefNo"/>
+ <property column="original_receive_date" name="originalReceiveDate"/>
+ <property name="gatewayId">
+ <column name="gateway_id" not-null="true"/>
+ </property>
+ </class>
+</hibernate-mapping>
=== added directory 'dhis-mobile/dhis-service-mobile/src/test/java/org'
=== added directory 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp'
=== added directory 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis'
=== added directory 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile'
=== added file 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/CompressorTest.java'
--- dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/CompressorTest.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/CompressorTest.java 2011-03-28 16:36:44 +0000
@@ -0,0 +1,60 @@
+package org.hisp.dhis.mobile;
+
+/*
+ * Copyright (c) 2004-2010, 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.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Saptarshi
+ */
+public class CompressorTest
+{
+
+ public CompressorTest()
+ {
+ }
+
+ /**
+ * Test of compress method, of class Compressor.
+ */
+ @Test
+ public void testCompressDecompress()
+ {
+ System.out.println( "Compress-Decompress String test" );
+ String testStr = "2#48*1?2010-11-08$1|2|3|4|5|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0";
+ byte[] compressed = Compressor.compress( testStr.getBytes() );
+ double diff = testStr.getBytes().length-compressed.length;
+ System.out.println( "Compression Ratio = " + ((diff/testStr.getBytes().length)*100.0D)+"%" );
+ byte[] in = testStr.getBytes();
+ byte[] expResult = testStr.getBytes();
+ byte[] result = Compressor.decompress( Compressor.compress( in ) );
+ assertArrayEquals( expResult, result );
+ }
+}
=== added directory 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms'
=== added file 'dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java'
--- dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-service-mobile/src/test/java/org/hisp/dhis/mobile/sms/HibernateSmsInboundStoreTest.java 2011-03-28 16:36:44 +0000
@@ -0,0 +1,139 @@
+package org.hisp.dhis.mobile.sms;
+
+
+import java.util.Calendar;
+import org.hisp.dhis.DhisSpringTest;
+import java.util.Collection;
+import java.util.Date;
+import org.hisp.dhis.mobile.sms.api.SmsInbound;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Saptarshi
+ */
+public class HibernateSmsInboundStoreTest extends DhisSpringTest
+{
+
+ private HibernateSmsInboundStore hibernateSmsInboundStore;
+
+ private SmsInbound testSms;
+
+ // -------------------------------------------------------------------------
+ // Fixture
+ // -------------------------------------------------------------------------
+ @Override
+ public void setUpTest()
+ throws Exception
+ {
+ hibernateSmsInboundStore = (HibernateSmsInboundStore) getBean( HibernateSmsInboundStore.ID );
+ testSms = new SmsInbound();
+ testSms.setEncoding( 'U' );
+ testSms.setGatewayId( "modem1" );
+ testSms.setMessageDate( new Date() );
+ testSms.setOriginalReceiveDate( new Date() );
+ testSms.setOriginalRefNo( "1" );
+ testSms.setProcess( 0 );
+ testSms.setReceiveDate( new Date() );
+ testSms.setText( "I AM A DISCO DANCER" );
+ testSms.setType( 'I' );
+ testSms.setOriginator( "+919867192752" );
+ }
+
+ /**
+ * Test of saveSms method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testSaveSms()
+ {
+ System.out.println( "testSaveSms" );
+ hibernateSmsInboundStore.saveSms( testSms );
+
+ for ( SmsInbound savedSms : hibernateSmsInboundStore.getAllReceiveSMS() )
+ {
+ assertEquals( testSms, savedSms );
+ }
+ }
+
+ /**
+ * Test of getSmsByDate method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testGetSmsByDate() throws Exception
+ {
+ System.out.println( "testSaveSms" );
+ Calendar today = Calendar.getInstance();
+ Calendar prevDay = ( (Calendar) today.clone() );
+ prevDay.add( Calendar.DAY_OF_YEAR, -1 );
+ Calendar nextDay = ( (Calendar) today.clone() );
+ nextDay.add( Calendar.DAY_OF_YEAR, 1 );
+ System.out.println( "testGetSmsByDate" );
+ Date startDate = prevDay.getTime();
+ Date endDate = nextDay.getTime();
+ hibernateSmsInboundStore.saveSms( testSms );
+ Collection<SmsInbound> smsByDate = hibernateSmsInboundStore.getSmsByDate( startDate, endDate );
+ for ( SmsInbound sms : smsByDate )
+ {
+ assertEquals( sms, testSms );
+ }
+ }
+
+ /**
+ * Test of getSmsByRecipient method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testGetSmsByRecipient()
+ {
+ System.out.println( "testGetSmsByRecipient" );
+ String originator = "+919867192752";
+ hibernateSmsInboundStore.saveSms( testSms );
+ Collection<SmsInbound> result = hibernateSmsInboundStore.getSmsByOriginator( originator );
+ for ( SmsInbound sms : result )
+ {
+ assertEquals( sms, testSms );
+ }
+ }
+
+ /**
+ * Test of getSmsByProcess method, of class HibernateSmsInboundStore.
+ */
+ @Test
+ public void testGetSmsByProcess()
+ {
+ System.out.println( "testGetSmsByProcess" );
+ hibernateSmsInboundStore.saveSms( testSms );
+ Collection<SmsInbound> result = hibernateSmsInboundStore.getSmsByProcess( 0 );
+ for ( SmsInbound sms : result )
+ {
+ assertEquals( sms, testSms );
+ }
+ }
+
+ /**
+ * Test of getAllReceiveSMS method, of class HibernateSmsInboundStore.
+ */
+ public void testGetAllReceiveSMS()
+ {
+ // TODO review the generated test code and remove the default call to fail.
+ fail( "The test case is a prototype." );
+ }
+
+ /**
+ * Test of updateSms method, of class HibernateSmsInboundStore.
+ */
+ public void testUpdateSms()
+ {
+ // TODO review the generated test code and remove the default call to fail.
+ fail( "The test case is a prototype." );
+ }
+
+ /**
+ * Test of getSmsCount method, of class HibernateSmsInboundStore.
+ */
+ public void testGetSmsCount()
+ {
+ // TODO review the generated test code and remove the default call to fail.
+ fail( "The test case is a prototype." );
+ }
+}
=== modified file 'dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.java'
--- dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.java 2010-10-14 10:44:34 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.java 2011-03-28 16:36:44 +0000
@@ -233,7 +233,7 @@
props.setProperty( "settings.delete_after_processing", delete_after_processing );
}
- private String simMemLocation = "";
+ private String simMemLocation = "-";
public void setSimMemLocation(String simMemLocation)
{
=== added directory 'dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes'
=== added file 'dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties'
--- dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties 1970-01-01 00:00:00 +0000
+++ dhis-mobile/dhis-web-mobile/src/main/webapp/WEB-INF/classes/log4j.properties 2011-03-28 16:36:44 +0000
@@ -0,0 +1,8 @@
+
+# Configuration file for log4j
+
+#Smslib logging
+log4j.logger.smslib=INFO, smslib
+log4j.appender.smslib=org.apache.log4j.ConsoleAppender
+log4j.appender.smslib.layout=org.apache.log4j.PatternLayout
+log4j.appender.smslib.layout.ConversionPattern=%d %-5p::%x- %m%n