=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsConfigurationManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsConfigurationManager.java 2012-03-12 20:25:54 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/SmsConfigurationManager.java 2012-03-20 11:07:14 +0000 @@ -28,11 +28,13 @@ */ import org.hisp.dhis.sms.config.SmsConfiguration; +import org.hisp.dhis.sms.config.SmsGatewayConfig; public interface SmsConfigurationManager { SmsConfiguration getSmsConfiguration(); void updateSmsConfiguration( SmsConfiguration config ); - + + SmsGatewayConfig checkInstanceOfGateway( Class clazz ); } \ No newline at end of file === modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/SmsConfigurationManagerImpl.java' --- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/SmsConfigurationManagerImpl.java 2012-03-01 08:56:47 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/SmsConfigurationManagerImpl.java 2012-03-20 11:07:14 +0000 @@ -34,9 +34,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hisp.dhis.setting.SystemSettingManager; -import org.hisp.dhis.sms.SmsConfigurationManager; import org.hisp.dhis.sms.config.SmsConfigurable; import org.hisp.dhis.sms.config.SmsConfiguration; +import org.hisp.dhis.sms.config.SmsGatewayConfig; import org.springframework.beans.factory.annotation.Autowired; /** @@ -102,4 +102,18 @@ // Reinitialize components relying on sms config. initializeSmsConfigurables(); } + + @Override + public SmsGatewayConfig checkInstanceOfGateway( Class clazz ) + { + for ( SmsGatewayConfig gateway : getSmsConfiguration().getGateways() ) + { + if ( gateway.getClass().equals( clazz ) ) + { + return gateway; + } + } + + return null; + } } === modified file 'dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceTest.java' --- dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceTest.java 2012-03-09 09:40:27 +0000 +++ dhis-2/dhis-services/dhis-service-sms/src/test/java/org/hisp/dhis/sms/outbound/OutboundSmsServiceTest.java 2012-03-20 11:07:14 +0000 @@ -50,7 +50,6 @@ public class OutboundSmsServiceTest extends AbstractSmsTest { - // These are only used for the integration test with store @Autowired === removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/AddGateWayConfigAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/AddGateWayConfigAction.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/AddGateWayConfigAction.java 1970-01-01 00:00:00 +0000 @@ -1,14 +0,0 @@ -package org.hisp.dhis.mobile.action; - -import com.opensymphony.xwork2.Action; - -public class AddGateWayConfigAction - implements Action -{ - public String execute() - throws Exception - { - return SUCCESS; - } - -} === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowUpdateGateWayConfigFormAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ShowUpdateGateWayConfigFormAction.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/ShowUpdateGateWayConfigFormAction.java 2012-03-20 11:07:14 +0000 @@ -0,0 +1,103 @@ +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 java.util.HashMap; +import java.util.Map; + +import org.hisp.dhis.sms.SmsConfigurationManager; +import org.hisp.dhis.sms.config.BulkSmsGatewayConfig; +import org.hisp.dhis.sms.config.ClickatellGatewayConfig; +import org.hisp.dhis.sms.config.ModemGatewayConfig; +import org.hisp.dhis.sms.config.SmsConfiguration; +import org.hisp.dhis.sms.config.SmsGatewayConfig; +import org.springframework.beans.factory.annotation.Autowired; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public class ShowUpdateGateWayConfigFormAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private SmsConfigurationManager smsConfigurationManager; + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private Map gatewayConfigMap = new HashMap(); + + public Map getGatewayConfigMap() + { + return gatewayConfigMap; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration(); + + if ( smsConfig != null ) + { + for ( SmsGatewayConfig gw : smsConfig.getGateways() ) + { + if ( gw instanceof BulkSmsGatewayConfig ) + { + gatewayConfigMap.put( 0, gw ); + } + else if ( gw instanceof ClickatellGatewayConfig ) + { + gatewayConfigMap.put( 1, gw ); + } + else if ( gw instanceof ModemGatewayConfig ) + { + gatewayConfigMap.put( 2, gw ); + } + else + { + gatewayConfigMap.put( 3, gw ); + } + } + } + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateBulkGateWayConfigAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateBulkGateWayConfigAction.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/UpdateBulkGateWayConfigAction.java 2012-03-20 11:07:14 +0000 @@ -0,0 +1,135 @@ +package org.hisp.dhis.mobile.action; + +/* + * Copyright (c) 2004-2011, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.sms.SmsConfigurationManager; +import org.hisp.dhis.sms.config.BulkSmsGatewayConfig; +import org.hisp.dhis.sms.config.SmsConfiguration; +import org.springframework.beans.factory.annotation.Autowired; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public class UpdateBulkGateWayConfigAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private SmsConfigurationManager smsConfigurationManager; + + public void setSmsConfigurationManager( SmsConfigurationManager smsConfigurationManager ) + { + this.smsConfigurationManager = smsConfigurationManager; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + private String password; + + public void setPassword( String password ) + { + this.password = password; + } + + private String username; + + public void setUsername( String username ) + { + this.username = username; + } + + private String gatewayType; + + public void setGatewayType( String gatewayType ) + { + this.gatewayType = gatewayType; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + if ( gatewayType != null && gatewayType.equals( "bulksms" ) ) + { + SmsConfiguration config = smsConfigurationManager.getSmsConfiguration(); + + if ( config != null ) + { + BulkSmsGatewayConfig gatewayConfig = (BulkSmsGatewayConfig) smsConfigurationManager + .checkInstanceOfGateway( BulkSmsGatewayConfig.class ); + + int index = 0; + + if ( gatewayConfig == null ) + { + gatewayConfig = new BulkSmsGatewayConfig(); + } + else + { + index = config.getGateways().indexOf( gatewayConfig ); + } + + gatewayConfig.setName( name ); + gatewayConfig.setPassword( password ); + gatewayConfig.setUsername( username ); + + if ( index >= 0 ) + { + config.getGateways().set( index, gatewayConfig ); + } + else + { + config.getGateways().add( gatewayConfig ); + } + + smsConfigurationManager.updateSmsConfiguration( config ); + } + } + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateClickatellGateWayConfigAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateClickatellGateWayConfigAction.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/UpdateClickatellGateWayConfigAction.java 2012-03-20 11:07:14 +0000 @@ -0,0 +1,143 @@ +package org.hisp.dhis.mobile.action; + +/* + * Copyright (c) 2004-2011, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.sms.SmsConfigurationManager; +import org.hisp.dhis.sms.config.ClickatellGatewayConfig; +import org.hisp.dhis.sms.config.SmsConfiguration; +import org.springframework.beans.factory.annotation.Autowired; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public class UpdateClickatellGateWayConfigAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private SmsConfigurationManager smsConfigurationManager; + + public void setSmsConfigurationManager( SmsConfigurationManager smsConfigurationManager ) + { + this.smsConfigurationManager = smsConfigurationManager; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + private String password; + + public void setPassword( String password ) + { + this.password = password; + } + + private String username; + + public void setUsername( String username ) + { + this.username = username; + } + + private String apiId; + + public void setApiId( String apiId ) + { + this.apiId = apiId; + } + + private String gatewayType; + + public void setGatewayType( String gatewayType ) + { + this.gatewayType = gatewayType; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + if ( gatewayType != null && gatewayType.equals( "clickatell" ) ) + { + SmsConfiguration config = smsConfigurationManager.getSmsConfiguration(); + + if ( config != null ) + { + ClickatellGatewayConfig gatewayConfig = (ClickatellGatewayConfig) smsConfigurationManager + .checkInstanceOfGateway( ClickatellGatewayConfig.class ); + + int index = 0; + + if ( gatewayConfig == null ) + { + gatewayConfig = new ClickatellGatewayConfig(); + } + else + { + index = config.getGateways().indexOf( gatewayConfig ); + } + + gatewayConfig.setName( name ); + gatewayConfig.setPassword( password ); + gatewayConfig.setUsername( username ); + gatewayConfig.setApiId( apiId ); + + if ( index >= 0 ) + { + config.getGateways().set( index, gatewayConfig ); + } + else + { + config.getGateways().add( gatewayConfig ); + } + + smsConfigurationManager.updateSmsConfiguration( config ); + } + } + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateGenericHTTPGateWayConfigAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateGenericHTTPGateWayConfigAction.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/UpdateGenericHTTPGateWayConfigAction.java 2012-03-20 11:07:14 +0000 @@ -0,0 +1,150 @@ +package org.hisp.dhis.mobile.action; + +/* + * Copyright (c) 2004-2011, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.HashMap; +import java.util.Map; + +import org.hisp.dhis.sms.SmsConfigurationManager; +import org.hisp.dhis.sms.config.GenericHttpGatewayConfig; +import org.hisp.dhis.sms.config.SmsConfiguration; +import org.springframework.beans.factory.annotation.Autowired; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public class UpdateGenericHTTPGateWayConfigAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private SmsConfigurationManager smsConfigurationManager; + + public void setSmsConfigurationManager( SmsConfigurationManager smsConfigurationManager ) + { + this.smsConfigurationManager = smsConfigurationManager; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + private String password; + + public void setPassword( String password ) + { + this.password = password; + } + + private String username; + + public void setUsername( String username ) + { + this.username = username; + } + + private String urlTemplate; + + public void setUrlTemplate( String url ) + { + this.urlTemplate = url; + } + + private String gatewayType; + + public void setGatewayType( String gatewayType ) + { + this.gatewayType = gatewayType; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + if ( gatewayType != null && gatewayType.equals( "http" ) ) + { + SmsConfiguration config = smsConfigurationManager.getSmsConfiguration(); + + if ( config != null ) + { + GenericHttpGatewayConfig gatewayConfig = (GenericHttpGatewayConfig) smsConfigurationManager + .checkInstanceOfGateway( GenericHttpGatewayConfig.class ); + + int index = 0; + + if ( gatewayConfig == null ) + { + gatewayConfig = new GenericHttpGatewayConfig(); + } + else + { + index = config.getGateways().indexOf( gatewayConfig ); + } + + Map map = new HashMap(); + + map.put( "username", username ); + map.put( "password", password ); + + gatewayConfig.setParameters( map ); + gatewayConfig.setName( name ); + gatewayConfig.setUrlTemplate( urlTemplate ); + + if ( index >= 0 ) + { + config.getGateways().set( index, gatewayConfig ); + } + else + { + config.getGateways().add( gatewayConfig ); + } + + smsConfigurationManager.updateSmsConfiguration( config ); + } + } + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateModemGateWayConfigAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/UpdateModemGateWayConfigAction.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/UpdateModemGateWayConfigAction.java 2012-03-20 11:07:14 +0000 @@ -0,0 +1,175 @@ +package org.hisp.dhis.mobile.action; + +/* + * Copyright (c) 2004-2011, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.sms.SmsConfigurationManager; +import org.hisp.dhis.sms.config.ModemGatewayConfig; +import org.hisp.dhis.sms.config.SmsConfiguration; +import org.springframework.beans.factory.annotation.Autowired; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ + +public class UpdateModemGateWayConfigAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private SmsConfigurationManager smsConfigurationManager; + + public void setSmsConfigurationManager( SmsConfigurationManager smsConfigurationManager ) + { + this.smsConfigurationManager = smsConfigurationManager; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String gatewayType; + + public void setGatewayType( String gatewayType ) + { + this.gatewayType = gatewayType; + } + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + private String port; + + public void setPort( String port ) + { + this.port = port; + } + + private Integer baudRate; + + public void setBaudRate( Integer baudRate ) + { + this.baudRate = baudRate; + } + + private String manufacturer; + + public void setManufacturer( String manufacturer ) + { + this.manufacturer = manufacturer; + } + + private String model; + + public void setModel( String model ) + { + this.model = model; + } + + private String pin; + + public void setPin( String pin ) + { + this.pin = pin; + } + + public boolean inbound; + + public void setInbound( boolean inbound ) + { + this.inbound = inbound; + } + + public boolean outbound; + + public void setOutbound( boolean outbound ) + { + this.outbound = outbound; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + if ( gatewayType != null && gatewayType.equals( "modem" ) ) + { + SmsConfiguration config = smsConfigurationManager.getSmsConfiguration(); + + if ( config != null ) + { + ModemGatewayConfig gatewayConfig = (ModemGatewayConfig) smsConfigurationManager + .checkInstanceOfGateway( ModemGatewayConfig.class ); + + int index = 0; + + if ( gatewayConfig == null ) + { + gatewayConfig = new ModemGatewayConfig(); + } + else + { + index = config.getGateways().indexOf( gatewayConfig ); + } + + gatewayConfig.setName( name ); + gatewayConfig.setPort( port ); + gatewayConfig.setBaudRate( baudRate ); + gatewayConfig.setManufacturer( manufacturer ); + gatewayConfig.setModel( model ); + gatewayConfig.setPin( pin ); + gatewayConfig.setInbound( inbound ); + gatewayConfig.setOutbound( outbound ); + + if ( index >= 0 ) + { + config.getGateways().set( index, gatewayConfig ); + } + else + { + config.getGateways().add( gatewayConfig ); + } + + smsConfigurationManager.updateSmsConfiguration( config ); + } + } + + 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-15 03:52:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/META-INF/dhis/beans.xml 2012-03-20 11:07:14 +0000 @@ -46,7 +46,20 @@ - - + + + + + + + + + + === 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-14 10:36:55 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/org/hisp/dhis/mobile/i18n_module.properties 2012-03-20 11:07:14 +0000 @@ -45,4 +45,4 @@ bulk_gw=BulkSMS Gateway clickatell_gw=Clickatell Gateway generic_http_gw=Generic HTTP Gateway -modem_gateway=Modem Gateway \ No newline at end of file +modem_gw=Modem 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-15 10:01:47 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/resources/struts.xml 2012-03-20 11:07:14 +0000 @@ -72,9 +72,9 @@ F_MOBILE_SETTINGS - + /main.vm - /dhis-web-maintenance-mobile/addGateway.vm + /dhis-web-maintenance-mobile/updateGateway.vm /dhis-web-maintenance-mobile/menu.vm === removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/addGateway.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/addGateway.vm 2011-11-14 08:57:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/addGateway.vm 1970-01-01 00:00:00 +0000 @@ -1,107 +0,0 @@ - - -

$i18n.getString("add_gateway")

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$i18n.getString("gateway_type")
$i18n.getString("type"): - -
$i18n.getString("gateway_configuration")
$i18n.getString("gateway_name"):
$i18n.getString("port"):
$i18n.getString("baudrate"):
$i18n.getString("manufacturer"):
$i18n.getString("model"):
$i18n.getString("pin"):
$i18n.getString("inbound"): - -
$i18n.getString("outbound"): - -
$i18n.getString("gateway_name"):
$i18n.getString("username")::
$i18n.getString("password"):
$i18n.getString("gateway_name"):
$i18n.getString("username")::
$i18n.getString("password")::
$i18n.getString("api_id")::
-
- === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/gateway.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/gateway.js 2011-11-14 08:57:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/gateway.js 2012-03-20 11:07:14 +0000 @@ -1,16 +1,20 @@ +currentType = ''; + function changeValueType( value ) { hideAll(); - if ( value == 'modem') - { + + if ( value == 'modem' ) { showById( "modemFields" ); - } else if (value == 'bulksms') - { + } else if ( value == 'bulksms' ) { showById( "bulksmsFields" ); - } else - { + } else if ( value == 'clickatell' ) { showById( "clickatellFields" ); - } + } else { + showById( "genericHTTPFields" ); + } + + currentType = type; } function hideAll() @@ -18,4 +22,109 @@ hideById( "modemFields" ); hideById( "bulksmsFields" ); hideById( "clickatellFields" ); + hideById( "genericHTTPFields" ); +} + +function getValidationRulesGateway() +{ + var rules = {}; + + if ( currentType == 'modem' ) { + rules = { + 'modemFields input[id=name]' : { 'required' : true }, + 'modemFields input[id=port]' : { 'required' : true }, + 'modemFields input[id=baudrate]' : { 'required' : true }, + 'modemFields input[id=manufacturer]' : { 'required' : true }, + 'modemFields input[id=model]' : { 'required' : true }, + 'modemFields input[id=pin]' : { 'required' : true }, + 'modemFields select[id=inbound]' : { 'required' : true }, + 'modemFields select[id=outbound]' : { 'required' : true } + }; + } else if ( currentType == 'bulksms' ) { + rules = { + 'bulksmsFields input[id=name]' : { 'required' : true }, + 'bulksmsFields input[id=username]' : { 'required' : true }, + 'bulksmsFields input[id=password]' : { 'required' : true } + }; + } else if ( currentType == 'clickatell' ) { + rules = { + 'clickatellFields input[id=name]' : { 'required' : true }, + 'clickatellFields input[id=username]' : { 'required' : true }, + 'clickatellFields input[id=password]' : { 'required' : true }, + 'clickatellFields input[id=apiId]' : { 'required' : true } + }; + } else { + rules = { + 'genericHTTPFields input[id=name]' : { 'required' : true }, + 'genericHTTPFields input[id=username]' : { 'required' : true }, + 'genericHTTPFields input[id=password]' : { 'required' : true }, + 'genericHTTPFields input[id=urlTemplate]' : { 'required' : true } + }; + } + + return rules; +} + +function saveGatewayConfig() +{ + if ( currentType == 'modem' ) + { + jQuery.postJSON( "saveBulkSMSConfig.action", { + gatewayType: getFieldValue( 'gatewayType' ), + name: getFieldValue( 'modemFields input[id=name]' ), + port: getFieldValue( 'modemFields input[id=port]' ), + baudrate: getFieldValue( 'modemFields input[id=baudrate]' ), + manufacturer: getFieldValue( 'modemFields input[id=manufacturer]' ), + model: getFieldValue( 'modemFields input[id=model]' ), + pin: getFieldValue( 'modemFields input[id=pin]' ), + inbound: getFieldValue( 'modemFields select[id=inbound]' ), + outbound: getFieldValue( 'modemFields select[id=outbound]' ) + }, function ( json ) { + showMessage( json ); + } ); + } + else if ( currentType == 'bulksms' ) + { + jQuery.postJSON( "saveBulkSMSConfig.action", { + gatewayType: getFieldValue( 'gatewayType' ), + name: getFieldValue( 'bulksmsFields input[id=name]' ), + username: getFieldValue( 'bulksmsFields input[id=username]' ), + password: getFieldValue( 'bulksmsFields input[id=password]' ) + }, function ( json ) { + showMessage( json ); + } ); + } + else if ( currentType == 'clickatell' ) + { + jQuery.postJSON( "saveBulkSMSConfig.action", { + gatewayType: getFieldValue( 'gatewayType' ), + name: getFieldValue( 'clickatellFields input[id=name]' ), + username: getFieldValue( 'clickatellFields input[id=username]' ), + password: getFieldValue( 'clickatellFields input[id=password]' ), + apiId: getFieldValue( 'clickatellFields input[id=apiId]' ) + }, function ( json ) { + showMessage( json ); + } ); + } + else + { + jQuery.postJSON( "saveBulkSMSConfig.action", { + gatewayType: getFieldValue( 'gatewayType' ), + name: getFieldValue( 'genericHTTPFields input[id=name]' ), + username: getFieldValue( 'genericHTTPFields input[id=username]' ), + password: getFieldValue( 'genericHTTPFields input[id=password]' ), + urlTemplate: getFieldValue( 'genericHTTPFields input[id=urlTemplate]' ) + }, function ( json ) { + showMessage( json ); + } ); + } +} + +function showMessage( json ) +{ + if ( json.response == "success" ) { + showSuccessMessage( json.message ); + } else { + showErrorMessage( json.message ); + } } \ No newline at end of file === 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-14 10:36:55 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smsServiceConfiguration.vm 2012-03-20 11:07:14 +0000 @@ -46,14 +46,14 @@ $i18n.getString("polling_interval_in_seconds"): - + $i18n.getString("server_phone_number"): - + - + @@ -70,8 +70,8 @@ $gateWay.name - $i18n.getString( 'edit' ) - $i18n.getString( 'remove' ) + #end === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/updateGateway.vm 2012-03-20 11:07:14 +0000 @@ -0,0 +1,140 @@ + + +

$i18n.getString( "add_update_gateway" )

+
+ + + + + + + + + + + + #set( $modemGateway = $!gatewayConfigMap.get( 2 ) ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #set( $bulkGateway = $!gatewayConfigMap.get( 0 ) ) + + + + + + + + + + + + + + + #set( $clickatellGateway = $!gatewayConfigMap.get( 1 ) ) + + + + + + + + + + + + + + + + + + + #set( $httpGateway = $!gatewayConfigMap.get( 3 ) ) + + + + + + + + + + + + + + + + + + + + + +
$i18n.getString( "gateway_type" )
$i18n.getString( "type" ): + +
$i18n.getString( "gateway_configuration" )
$i18n.getString( "gateway_name" ):
$i18n.getString( "port" ):
$i18n.getString( "baudrate" ):
$i18n.getString( "manufacturer" ):
$i18n.getString( "model" ):
$i18n.getString( "pin" ):
$i18n.getString( "inbound" ): + +
$i18n.getString( "outbound" ): + +
$i18n.getString( "gateway_name" ):
$i18n.getString( "username" ):
$i18n.getString( "password" ):
$i18n.getString( "gateway_name" ):
$i18n.getString( "username" ):
$i18n.getString( "password" ):
$i18n.getString( "api_id" ):
$i18n.getString( "gateway_name" ):
$i18n.getString( "username" ):
$i18n.getString( "password" ):
$i18n.getString( "url_template" ):
+
+
+