← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6363: (mobile) SMS Configuration GUI is done. And fixed unit test.

 

------------------------------------------------------------
revno: 6363
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-03-23 11:01:16 +0700
message:
  (mobile) SMS Configuration GUI is done. And fixed unit test.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java
modified:
  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/outbound/OutboundSmsTransportService.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfigTest.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java
  dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/GetSmsConfigurationAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smsServiceConfiguration.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/updateGateway.vm


--
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/config/SmsConfiguration.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java	2012-03-23 04:01:16 +0000
@@ -31,6 +31,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlElements;
 import javax.xml.bind.annotation.XmlRootElement;
 
 /**
@@ -81,13 +84,11 @@
         this.longNumber = longNumber;
     }
 
-    /*
-     * @XmlElementWrapper( name = "gateways" ) @XmlElements( { @XmlElement( name =
-     * "bulksms", type = BulkSmsGatewayConfig.class ), @XmlElement( name =
-     * "clickatell", type = ClickatellGatewayConfig.class ), @XmlElement( name =
-     * "http", type = GenericHttpGatewayConfig.class ), @XmlElement( name =
-     * "modem", type = ModemGatewayConfig.class ) } )
-     */
+    @XmlElementWrapper( name = "gateways" )
+    @XmlElements( { @XmlElement( name = "bulksms", type = BulkSmsGatewayConfig.class ),
+        @XmlElement( name = "clickatell", type = ClickatellGatewayConfig.class ),
+        @XmlElement( name = "http", type = GenericHttpGatewayConfig.class ),
+        @XmlElement( name = "modem", type = ModemGatewayConfig.class ) } )
     public List<SmsGatewayConfig> getGateways()
     {
         return gateways;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/outbound/OutboundSmsTransportService.java	2012-03-23 04:01:16 +0000
@@ -2,6 +2,8 @@
 
 import java.util.Map;
 
+import org.hisp.dhis.sms.SmsServiceException;
+
 /*
  * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
@@ -38,5 +40,14 @@
 {
     Map<String, String> getGatewayMap();
 
-    String stopService();
+    void stopService();
+
+    void startService();
+
+    void reloadConfig()
+        throws SmsServiceException;
+
+    String getServiceStatus();
+
+    String getMessageStatus();
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfigTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfigTest.java	2012-03-21 12:37:00 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/sms/config/GenericHttpGatewayConfigTest.java	2012-03-23 04:01:16 +0000
@@ -19,9 +19,7 @@
 import javax.xml.bind.Unmarshaller;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
-import org.junit.Ignore;
 
 /*
  * Copyright (c) 2011, University of Oslo
@@ -52,7 +50,6 @@
 
 public class GenericHttpGatewayConfigTest
 {
-
     private String urlTemplate = "http://bulksms.vsms.net:5567/eapi/submission/send_sms/2/2.0?username={username}&password={password}&source_id={sender}&message={message}&msisdn={recipient}";;
 
     private String bulk = "<bulksms><name>bulk</name><username>username</username><password>password</password></bulksms>";
@@ -75,11 +72,9 @@
     }
 
     @Test
-    @Ignore
     public void testMarshalling()
         throws IOException, JAXBException
     {
-
         Writer writer = new StringWriter();
         Map<String, String> parameters = new HashMap<String, String>();
         parameters.put( "username", "u1" );
@@ -99,7 +94,6 @@
     }
 
     @Test
-	@Ignore
     public void testUntmarshalling()
         throws JAXBException
     {

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java	2012-03-21 04:15:03 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/TestOutboundSmsService.java	2012-03-23 04:01:16 +0000
@@ -60,9 +60,35 @@
     }
 
     @Override
-    public String stopService()
+    public void stopService()
     {
         log.debug( "stopService()" );
+    }
+
+    @Override
+    public void startService()
+    {
+        log.debug( "startService()" );
+    }
+
+    @Override
+    public String getServiceStatus()
+    {
+        log.debug( "getServiceStatus()" );
+        return "STARTED";
+    }
+
+    @Override
+    public void reloadConfig()
+        throws SmsServiceException
+    {
+        log.debug( "reloadConfig()" );
+    }
+
+    @Override
+    public String getMessageStatus()
+    {
+        log.debug( "getMessageStatus()" );
         return null;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java	2012-03-23 04:01:16 +0000
@@ -61,6 +61,8 @@
 
     private SmsConfiguration config;
 
+    private String message = "success";
+
     private final String BULK_GATEWAY = "bulk_gw";
 
     private final String CLICKATELL_GATEWAY = "clickatell_gw";
@@ -94,12 +96,23 @@
     public void sendMessage( OutboundSms sms, String gatewayId )
         throws SmsServiceException
     {
+        message = getServiceStatus();
+
+        if ( message != null && (message.equals( "service_stopped" ) || message.equals( "service_stopping" )) )
+        {
+            message = "service_stopped_cannot_send_sms";
+
+            return;
+        }
+
         String recipient;
 
         Set<String> recipients = sms.getRecipients();
 
         if ( recipients.size() == 0 )
         {
+            message = "there_is_no_recipient_cannot_send_sms";
+
             log.warn( "Trying to send sms without recipients: " + sms );
             return;
         }
@@ -112,13 +125,13 @@
             recipient = createTmpGroup( recipients );
         }
 
-        OutboundMessage message = new OutboundMessage( recipient, sms.getMessage() );
+        OutboundMessage outboundMessage = new OutboundMessage( recipient, sms.getMessage() );
 
         String longNumber = config.getLongNumber();
 
         if ( longNumber != null && !longNumber.isEmpty() )
         {
-            message.setFrom( longNumber );
+            outboundMessage.setFrom( longNumber );
         }
 
         boolean sent = false;
@@ -129,25 +142,31 @@
 
             if ( gatewayId == null || gatewayId.isEmpty() )
             {
-                sent = getService().sendMessage( message );
+                sent = getService().sendMessage( outboundMessage );
             }
             else
             {
-                sent = getService().sendMessage( message, gatewayId );
+                sent = getService().sendMessage( outboundMessage, gatewayId );
             }
         }
         catch ( SMSLibException e )
         {
+            message = "Unable to send message: " + sms + " " + e.getCause().getMessage();
+
             log.warn( "Unable to send message: " + sms, e );
             throw new SmsServiceException( "Unable to send message: " + sms, e );
         }
         catch ( IOException e )
         {
+            message = "Unable to send message: " + sms + " " + e.getCause().getMessage();
+
             log.warn( "Unable to send message: " + sms, e );
             throw new SmsServiceException( "Unable to send message: " + sms, e );
         }
         catch ( InterruptedException e )
         {
+            message = "Unable to send message: " + sms + " " + e.getCause().getMessage();
+
             log.warn( "Unable to send message: " + sms, e );
             throw new SmsServiceException( "Unable to send message: " + sms, e );
         }
@@ -160,8 +179,13 @@
             }
         }
 
-        if ( !sent )
-        {
+        if ( sent )
+        {
+            message = "success";
+        }
+        else
+        {
+            message = "message_not_sent";
             log.warn( "Message not sent" );
         }
     }
@@ -189,104 +213,14 @@
         }
 
         log.debug( "Loading configuration" );
-
-        if ( config.isEnabled() && reloadConfig() )
-        {
-            log.debug( "Starting SmsLib" );
-            startService();
-        }
-        else
-        {
-            log.debug( "Sms not enabled or there is no any gateway, won't start service" );
-        }
-    }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private String createTmpGroup( Set<String> recipients )
-    {
-        String groupName = Thread.currentThread().getName();
-
-        getService().createGroup( groupName );
-
-        for ( String recepient : recipients )
-        {
-            getService().addToGroup( groupName, recepient );
-        }
-
-        return groupName;
-    }
-
-    private void removeGroup( String groupName )
-    {
-        getService().removeGroup( groupName );
-    }
-
-    private void startService()
-    {
-        try
-        {
-            getService().startService();
-        }
-        catch ( SMSLibException e )
-        {
-            log.warn( "Unable to start smsLib service", e );
-            throw new SmsServiceException( "Unable to start smsLib service", e );
-        }
-        catch ( IOException e )
-        {
-            log.warn( "Unable to start smsLib service", e );
-            throw new SmsServiceException( "Unable to start smsLib service", e );
-        }
-        catch ( InterruptedException e )
-        {
-            log.warn( "Unable to start smsLib service", e );
-            throw new SmsServiceException( "Unable to start smsLib service", e );
-        }
+        reloadConfig();
+
+        log.debug( "Starting SmsLib" );
+        startService();
     }
 
     @Override
-    public String stopService()
-    {
-        String status = "success";
-
-        try
-        {
-            getService().stopService();
-        }
-        catch ( SMSLibException e )
-        {
-            status = "Unable to stop smsLib service" + e.getCause().getMessage();
-
-            log.warn( "Unable to stop smsLib service", e );
-            throw new SmsServiceException( "Unable to stop smsLib service", e );
-        }
-        catch ( IOException e )
-        {
-            status = "Unable to stop smsLib service" + e.getCause().getMessage();
-
-            log.warn( "Unable to stop smsLib service", e );
-            throw new SmsServiceException( "Unable to stop smsLib service", e );
-        }
-        catch ( InterruptedException e )
-        {
-            status = "Unable to stop smsLib service" + e.getCause().getMessage();
-
-            log.warn( "Unable to stop smsLib service", e );
-            throw new SmsServiceException( "Unable to stop smsLib service", e );
-        }
-
-        return status;
-    }
-
-    private Service getService()
-    {
-        return Service.getInstance();
-    }
-
-    private boolean reloadConfig()
+    public void reloadConfig()
         throws SmsServiceException
     {
         Service service = Service.getInstance();
@@ -297,9 +231,12 @@
 
         AGateway gateway = null;
 
-        boolean reloaded = false;
-
         // Add gateways
+        if ( config.getGateways() == null || config.getGateways().isEmpty() )
+        {
+            message = "unable_load_configuration_cause_of_there_is_no_gateway";
+        }
+
         for ( SmsGatewayConfig gatewayConfig : config.getGateways() )
         {
             try
@@ -325,20 +262,146 @@
                     gatewayMap.put( MODEM_GATEWAY, gateway.getGatewayId() );
                 }
 
-                reloaded = true;
+                message = "success";
 
                 log.debug( "Added gateway " + gatewayConfig.getName() );
             }
             catch ( GatewayException e )
             {
-                reloaded = false;
+                message = "Unable to load gateway " + gatewayConfig.getName() + e.getCause().getMessage();
 
                 log.warn( "Unable to load gateway " + gatewayConfig.getName(), e );
                 throw new SmsServiceException( "Unable to load gateway" + gatewayConfig.getName(), e );
             }
         }
-
-        return reloaded;
+    }
+
+    @Override
+    public void startService()
+    {
+        if ( config.isEnabled() && (message != null && message.equals( "success" )) )
+        {
+            try
+            {
+                getService().startService();
+            }
+            catch ( SMSLibException e )
+            {
+                message = "Unable to start smsLib service " + e.getCause().getMessage();
+
+                log.warn( "Unable to start smsLib service", e );
+                throw new SmsServiceException( "Unable to start smsLib service", e );
+            }
+            catch ( IOException e )
+            {
+                message = "Unable to start smsLib service" + e.getCause().getMessage();
+
+                log.warn( "Unable to start smsLib service", e );
+                throw new SmsServiceException( "Unable to start smsLib service", e );
+            }
+            catch ( InterruptedException e )
+            {
+                message = "Unable to start smsLib service" + e.getCause().getMessage();
+
+                log.warn( "Unable to start smsLib service", e );
+                throw new SmsServiceException( "Unable to start smsLib service", e );
+            }
+        }
+        else
+        {
+            message = "sms_unable_or_there_is_no_gatewat_service_not_started";
+
+            log.debug( "Sms not enabled or there is no any gateway, won't start service" );
+        }
+    }
+
+    @Override
+    public void stopService()
+    {
+        message = "success";
+
+        try
+        {
+            getService().stopService();
+        }
+        catch ( SMSLibException e )
+        {
+            message = "Unable to stop smsLib service " + e.getCause().getMessage();
+
+            log.warn( "Unable to stop smsLib service", e );
+            throw new SmsServiceException( "Unable to stop smsLib service", e );
+        }
+        catch ( IOException e )
+        {
+            message = "Unable to stop smsLib service" + e.getCause().getMessage();
+
+            log.warn( "Unable to stop smsLib service", e );
+            throw new SmsServiceException( "Unable to stop smsLib service", e );
+        }
+        catch ( InterruptedException e )
+        {
+            message = "Unable to stop smsLib service" + e.getCause().getMessage();
+
+            log.warn( "Unable to stop smsLib service", e );
+            throw new SmsServiceException( "Unable to stop smsLib service", e );
+        }
+    }
+
+    @Override
+    public String getServiceStatus()
+    {
+        ServiceStatus serviceStatus = getService().getServiceStatus();
+
+        if ( serviceStatus == ServiceStatus.STARTED )
+        {
+            return "service_started";
+        }
+        else if ( serviceStatus == ServiceStatus.STARTING )
+        {
+            return "service_starting";
+        }
+        else if ( serviceStatus == ServiceStatus.STOPPED )
+        {
+            return "service_stopped";
+        }
+        else
+        {
+            return "service_stopping";
+        }
+    }
+
+    @Override
+    public String getMessageStatus()
+    {
+        return message;
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private Service getService()
+    {
+        return Service.getInstance();
+    }
+
+    private String createTmpGroup( Set<String> recipients )
+    {
+        String groupName = Thread.currentThread().getName();
+
+        getService().createGroup( groupName );
+
+        for ( String recepient : recipients )
+        {
+            getService().addToGroup( groupName, recepient );
+        }
+
+        return groupName;
+    }
+
+    private void removeGroup( String groupName )
+    {
+        getService().removeGroup( groupName );
     }
 
     private class OutboundNotification

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2012-03-07 11:53:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2012-03-23 04:01:16 +0000
@@ -272,6 +272,7 @@
       <result name="input" type="velocity-json">
         /dhis-web-commons/ajax/jsonResponseInput.vm
       </result>
+	  <param name="onExceptionReturn">plainTextError</param>
     </action>
 
     <action name="addSqlView" class="org.hisp.dhis.dataadmin.action.sqlview.AddSqlViewAction">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/GetSmsConfigurationAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/GetSmsConfigurationAction.java	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/GetSmsConfigurationAction.java	2012-03-23 04:01:16 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.sms.config.ModemGatewayConfig;
 import org.hisp.dhis.sms.config.SmsConfiguration;
 import org.hisp.dhis.sms.config.SmsGatewayConfig;
+import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
@@ -54,6 +55,9 @@
 
     @Autowired
     private SmsConfigurationManager smsConfigurationManager;
+    
+    @Autowired
+    private OutboundSmsTransportService smsLibService;
 
     // -------------------------------------------------------------------------
     // Output
@@ -80,9 +84,11 @@
         return smsConfig;
     }
 
-    public boolean getSmsServiceStatus()
+    private String smsServiceStatus;
+    
+    public String getSmsServiceStatus()
     {
-        return this.smsConfig != null && this.smsConfig.isEnabled();
+        return this.smsServiceStatus;
     }
 
     // -------------------------------------------------------------------------
@@ -92,6 +98,8 @@
     public String execute()
         throws Exception
     {
+        smsServiceStatus = smsLibService.getServiceStatus();
+        
         smsConfig = smsConfigurationManager.getSmsConfiguration();
 
         if ( smsConfig != null )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.java	2011-11-14 12:19:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/MobileSettingsAction.java	2012-03-23 04:01:16 +0000
@@ -1,5 +1,6 @@
 package org.hisp.dhis.mobile.action;
 
+
 /*
  * Copyright (c) 2004-2007, University of Oslo
  * All rights reserved.

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java	2012-03-09 09:40:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ProcessingSendSMSAction.java	2012-03-23 04:01:16 +0000
@@ -31,9 +31,11 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 import org.hisp.dhis.sms.MessageSender;
+import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserService;
@@ -63,6 +65,9 @@
 
     @Autowired
     private MessageSender messageSender;
+    
+    @Autowired
+    private OutboundSmsTransportService smsLibService;
 
     // -------------------------------------------------------------------------
     // Input & Output
@@ -96,18 +101,50 @@
         this.recipients = recipients;
     }
 
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    private I18n i18n;
+
+    // -------------------------------------------------------------------------
+    // I18n
+    // -------------------------------------------------------------------------
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
 
     public String execute()
     {
+        if ( gatewayId == null || gatewayId.isEmpty() )
+        {
+            message = i18n.getString( "please_select_a_gateway_type_to_send_sms" );
+
+            return ERROR;
+        }
+
         if ( smsMessage != null && !smsMessage.isEmpty() )
         {
             if ( recipients != null && !recipients.isEmpty() )
             {
                 messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), true,
                     recipients, gatewayId );
+
+                message = smsLibService.getMessageStatus();
+                
+                if ( message != null && !message.equals( "success" ) )
+                {
+                    return ERROR;
+                }
             }
 
             Collection<OrganisationUnit> units = selectionTreeManager.getSelectedOrganisationUnits();
@@ -116,6 +153,13 @@
             {
                 messageSender.sendMessage( smsSubject, smsMessage, currentUserService.getCurrentUser(), false,
                     new HashSet<User>( userService.getUsersByOrganisationUnits( units ) ), gatewayId );
+   
+                message = smsLibService.getMessageStatus();
+                
+                if ( message != null && !message.equals( "success" ) )
+                {
+                    return ERROR;
+                }
             }
         }
 

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java	2012-03-23 04:01:16 +0000
@@ -0,0 +1,122 @@
+package org.hisp.dhis.mobile.action;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.sms.SmsConfigurationManager;
+import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+
+public class ReloadStartStopServiceAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private SmsConfigurationManager smsConfigurationManager;
+
+    @Autowired
+    private OutboundSmsTransportService smsLibService;
+
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private String actionType;
+
+    public void setActionType( String actionType )
+    {
+        this.actionType = actionType;
+    }
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    // -------------------------------------------------------------------------
+    // I18n
+    // -------------------------------------------------------------------------
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        if ( smsConfigurationManager.getSmsConfiguration() == null )
+        {
+            message = i18n.getString( "smsconfiguration_not_available" );
+
+            return INPUT;
+        }
+
+        if ( actionType != null && actionType.equals( "start" ) )
+        {
+            smsLibService.startService();
+        }
+        else if ( actionType.equals( "stop" ) )
+        {
+            smsLibService.stopService();
+        }
+        else
+        {
+            smsLibService.reloadConfig();
+        }
+
+        message = smsLibService.getMessageStatus();
+        
+        if ( message != null && !message.equals( "success" ) )
+        {            
+            return INPUT;
+        }
+        
+        message = i18n.getString( message );
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml	2012-03-23 04:01:16 +0000
@@ -64,5 +64,8 @@
   
   <bean id="org.hisp.dhis.mobile.action.RemoveGatewayConfigAction" 
 	class="org.hisp.dhis.mobile.action.RemoveGatewayConfigAction" scope="prototype"/>
+  
+  <bean id="org.hisp.dhis.mobile.action.ReloadStartStopServiceAction" 
+	class="org.hisp.dhis.mobile.action.ReloadStartStopServiceAction" scope="prototype"/>
 
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2012-03-21 02:32:51 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties	2012-03-23 04:01:16 +0000
@@ -42,10 +42,26 @@
 api_id=API ID
 save_settings=Save Settings
 add_update_gw=Add or update gateway
+start_sms_service=Start SMS Service
+stop_sms_service=Stop SMS Service
 show_send_sms_form=Show send SMS form
 bulk_gw=BulkSMS Gateway
 clickatell_gw=Clickatell Gateway
 http_gw=Generic HTTP Gateway
 modem_gw=Modem Gateway
 add_update_gateway_management=Add or Update Gateway Configuration Management
-confirm_delete_gateway=Do you want to delete this gateway configuration ?
\ No newline at end of file
+confirm_delete_gateway=Do you want to delete this gateway configuration ?
+smsconfiguration_not_available=SMS Configuration is not available
+service_started=SMS Service is started
+service_starting=SMS Service is starting
+service_stopped=SMS Service is stopped
+service_stopping=SMS Service is stopping
+message_not_sent=Message not sent
+please_select_a_gateway_type_to_send_sms=Please specify a gateway to send SMS
+service_stopped_cannot_send_sms=Service is stopped, can\'t send SMS
+there_is_no_recipient_cannot_send_sms=There is no any recipient, can\'t send SMS
+unable_load_gateway=Unable to load gateway
+unable_start_smslib_service=Unable to start smsLib service
+unable_stop_smslib_service=Unable to stop smsLib service
+sms_unable_or_there_is_no_gatewat_service_not_started=Sms not enabled or there is no any gateway, won\'t start service
+unable_load_configuration_cause_of_there_is_no_gateway=Unable to load the configuration cause there is no any gateway
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml	2012-03-23 04:01:16 +0000
@@ -35,9 +35,9 @@
 
     <action name="sendSMS" class="org.hisp.dhis.mobile.action.ProcessingSendSMSAction">
       <result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+      <result name="error" type="velocity-json">../dhis-web-commons/ajax/jsonResponseError.vm</result>
       <param name="onExceptionReturn">plainTextError</param>
-    </action>
-	
+    </action>	
 	
     <!-- Patient Mobile Setting Action -->
 
@@ -80,6 +80,12 @@
 	  <param name="requiredAuthorities">F_MOBILE_SETTINGS</param>
     </action>
 
+    <action name="reloadStartStopService" class="org.hisp.dhis.mobile.action.ReloadStartStopServiceAction">
+      <result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+      <result name="input" type="velocity-json">../dhis-web-commons/ajax/jsonResponseInput.vm</result>
+      <param name="onExceptionReturn">plainTextError</param>
+    </action>
+	
     <action name="saveSmsConfiguration" class="org.hisp.dhis.mobile.action.SaveSmsConfigurationAction">
       <result name="success" type="redirect">showSMSConfigureForm.action</result>
     </action>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.vm	2012-03-21 08:24:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/sendSMSPage.vm	2012-03-23 04:01:16 +0000
@@ -32,9 +32,9 @@
 			<tr>
 				<td><label for="type">$i18n.getString( "type" ):</label></td>
 				<td>
-				#set( $keys = $gatewayMap.keySet() )
+				#set( $keys = $!gatewayMap.keySet() )
 					<select id="gatewayId" name="gatewayId" style="width: 100%;">
-						#foreach( $key in $keys )
+						#foreach( $key in $!keys )
 						<option value="$gatewayMap.get( $key )">$i18n.getString( $key )</option>
 						#end
 					</select>
@@ -121,7 +121,7 @@
 	function getValidationRulesForSMSPage()
 	{
 		var rules = {};
-		
+
 		if ( isChecked ) {
 			rules = { 'treeSelectedId': { 'required': true } };
 		} else {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smsServiceConfiguration.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smsServiceConfiguration.vm	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smsServiceConfiguration.vm	2012-03-23 04:01:16 +0000
@@ -16,9 +16,25 @@
 		}, {
 			'rules': getValidationRules( 'SMSConfig' )
 		} );
+
+		#if ( $!smsServiceStatus && ( $!smsServiceStatus == "service_started" || $!smsServiceStatus == "service_starting" ) )
+			actionType = "stop";
+			jQuery( "#startStopButton" ).attr( "value", i18n_stop_sms_service );
+		#else
+			actionType = "start";
+			jQuery( "#startStopButton" ).attr( "value", i18n_start_sms_service );
+		#end
+		
+		//alert(actionType);
 	} );
 
 	var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_gateway" ) , "'")';
+	var i18n_stop_sms_service = '$encoder.jsEscape( $i18n.getString( "stop_sms_service" ) , "'")';
+	var i18n_start_sms_service = '$encoder.jsEscape( $i18n.getString( "start_sms_service" ) , "'")';
+	var i18n_sms_service_started = '$encoder.jsEscape( $i18n.getString( "service_started" ) , "'")';
+	var i18n_sms_service_stopped = '$encoder.jsEscape( $i18n.getString( "service_stopped" ) , "'")';
+	var actionType = "start";
+	
 </script>
 
 <h3>$i18n.getString( "sms_service_configuration" )</h3>
@@ -29,25 +45,24 @@
     <col/> ## Input
     <thead>
       <tr>
-        <th colspan="2">$i18n.getString("service_status")</th>
+        <th colspan="2">$i18n.getString( "service_status" )</th>
       </tr>
     </thead>
     <tbody>
 		<tr>
 			<td colspan="2">
 				<div class="overlaps" id="noOverlapsDiv" style="display: block;">
-					#if( $smsService.isRunning() )
-						$i18n.getString("sms_service_is_runnning")
-					#else
-						$i18n.getString("sms_service_is_stopped")
-					#end
+					$i18n.getString( $!encoder.htmlEncode( $!smsServiceStatus ) )
 				</div>
 			</td>
 		</tr>
-      <tr>
-       <td colspan="2" align="right"><input type="button" value="$i18n.getString('reload_configuration')"/><input type="button" value="$i18n.getString('stop_sms_service')"/></td>
-      </tr>
-      <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
+		<tr>
+			<td colspan="2" align="right">
+				<input type="button" value="$i18n.getString( 'reload_configuration' )" onclick="reloadStartStopService( 'reload' );" />
+				<input type="button" id="startStopButton" value="$i18n.getString( 'stop_sms_service' )" onclick="reloadStartStopService( actionType );" />
+			</td>
+		</tr>
+		<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
     </tbody>
 
 	<thead>
@@ -66,7 +81,7 @@
 			<input type="submit" value="$i18n.getString( 'save_settings' )" style="width:13em"/></td>
 		</tr>
 		<tr>
-			<td align="right" colspan="2"><input type="button" value="$i18n.getString('add_update_gw')" style="width:11em#if( !$smsServiceStatus );display:none#end" onclick="window.location.href='showUpdateGateWayConfigForm.action'"/></td>
+			<td align="right" colspan="2"><input type="button" value="$i18n.getString( 'add_update_gw' )" style="width:13em#if( !$smsServiceStatus );display:none#end" onclick="window.location.href='showUpdateGateWayConfigForm.action'"/></td>
 		</tr>
 		<tr>
 			<td colspan="2">
@@ -99,6 +114,34 @@
 
 <script type="text/javascript">
 	
+	function reloadStartStopService( type )
+	{
+		jQuery.getJSON( "reloadStartStopService.action",
+		{
+			actionType: type
+		}, function( json ) {
+			if ( json.response == "success" ) {
+				showSuccessMessage( json.message );
+				
+				if ( actionType == "start" )
+				{
+					actionType = "stop";
+					jQuery( "#startStopButton" ).attr( "value", i18n_stop_sms_service );
+					setInnerHTML( "noOverlapsDiv", i18n_sms_service_started );
+				}
+				else if ( actionType == "stop" )
+				{
+					actionType = "start";
+					jQuery( "#startStopButton" ).attr( "value", i18n_start_sms_service );
+					setInnerHTML( "noOverlapsDiv", i18n_sms_service_stopped );
+				}
+			}
+			else {
+				showErrorMessage( json.message, 7000 );
+			}
+		} );
+	}
+	
 	function removeGateway( key, name )
 	{
 		removeItem( key, name, i18n_confirm_delete, "removeGatewayConfig.action" );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/updateGateway.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/updateGateway.vm	2012-03-21 02:20:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/updateGateway.vm	2012-03-23 04:01:16 +0000
@@ -10,7 +10,7 @@
         changeValueType("bulksms");
     });
 </script>
-<h3>$i18n.getString( "add_update_gateway" )</h3>
+<h3>$i18n.getString( "add_update_gateway_management" )</h3>
 <form id="addGateWayConfigForm" name="addGateWayConfigForm">
 	<table id="detailsList">
 		<tr>