Search in sources :

Example 1 with ClickatellGatewayConfig

use of org.hisp.dhis.sms.config.ClickatellGatewayConfig in project dhis2-core by dhis2.

the class UpdateClickatellGateWayConfigAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
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 = -1;
            if (gatewayConfig == null) {
                gatewayConfig = new ClickatellGatewayConfig();
            } else {
                index = config.getGateways().indexOf(gatewayConfig);
            }
            gatewayConfig.setName(name);
            gatewayConfig.setPassword(password);
            gatewayConfig.setUsername(username);
            gatewayConfig.setUid(CodeGenerator.generateCode(10));
            gatewayConfig.setAuthToken(authToken);
            if (config.getGateways() == null || config.getGateways().isEmpty()) {
                gatewayConfig.setDefault(true);
            }
            if (index >= 0) {
                config.getGateways().set(index, gatewayConfig);
            } else {
                config.getGateways().add(gatewayConfig);
            }
            gatewayAdminService.getGatewayConfigurationMap().put(name, gatewayConfig);
            smsConfigurationManager.updateSmsConfiguration(config);
        }
    }
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) ClickatellGatewayConfig(org.hisp.dhis.sms.config.ClickatellGatewayConfig)

Example 2 with ClickatellGatewayConfig

use of org.hisp.dhis.sms.config.ClickatellGatewayConfig in project dhis2-core by dhis2.

the class GetSmsConfigurationAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    smsConfig = smsConfigurationManager.getSmsConfiguration();
    if (smsConfig != null) {
        int index = 0;
        for (SmsGatewayConfig gw : smsConfig.getGateways()) {
            index = smsConfig.getGateways().indexOf(gw);
            gatewayConfigMap.put(index, gw);
            if (gw instanceof BulkSmsGatewayConfig) {
                bulkIndex = index;
            } else if (gw instanceof ClickatellGatewayConfig) {
                clickatellIndex = index;
            } else {
                httpIndex = index;
            }
        }
    } else {
        smsConfig = new SmsConfiguration(true);
        smsConfigurationManager.updateSmsConfiguration(smsConfig);
    }
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) ClickatellGatewayConfig(org.hisp.dhis.sms.config.ClickatellGatewayConfig) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig)

Example 3 with ClickatellGatewayConfig

use of org.hisp.dhis.sms.config.ClickatellGatewayConfig in project dhis2-core by dhis2.

the class RemoveGatewayConfigAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration();
    Iterator<SmsGatewayConfig> it = smsConfig.getGateways().iterator();
    while (it.hasNext()) {
        if (smsConfig.getGateways().indexOf(it.next()) == id) {
            SmsGatewayConfig gatewayConfig = smsConfig.getGateways().get(id);
            it.remove();
            smsConfigurationManager.updateSmsConfiguration(smsConfig);
            if (gatewayConfig instanceof BulkSmsGatewayConfig) {
                gatewayAdminService.getGatewayConfigurationMap().remove(gatewayConfig.getName());
            }
            if (gatewayConfig instanceof ClickatellGatewayConfig) {
                gatewayAdminService.getGatewayConfigurationMap().remove(gatewayConfig.getName());
            }
            if (gatewayConfig instanceof GenericHttpGatewayConfig) {
                gatewayAdminService.getGatewayConfigurationMap().remove(gatewayConfig.getName());
            }
            log.info(gatewayConfig.getName() + " configuration has been removed");
            break;
        }
    }
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) ClickatellGatewayConfig(org.hisp.dhis.sms.config.ClickatellGatewayConfig) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) GenericHttpGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGatewayConfig)

Aggregations

ClickatellGatewayConfig (org.hisp.dhis.sms.config.ClickatellGatewayConfig)3 SmsConfiguration (org.hisp.dhis.sms.config.SmsConfiguration)3 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)2 SmsGatewayConfig (org.hisp.dhis.sms.config.SmsGatewayConfig)2 GenericHttpGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGatewayConfig)1