Search in sources :

Example 1 with SmsConfiguration

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

the class DefaultSmsConfigurationManager method gatewayExists.

@Override
public boolean gatewayExists(String gatewayId) {
    SmsConfiguration config = getSmsConfiguration();
    List<SmsGatewayConfig> gatewayList = config.getGateways();
    for (SmsGatewayConfig gw : gatewayList) {
        if (gw.getName().equals(gatewayId)) {
            return true;
        }
    }
    return false;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig)

Example 2 with SmsConfiguration

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

the class SaveSmsConfigurationAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration();
    if (smsConfig == null) {
        smsConfig = new SmsConfiguration(true);
    }
    smsConfigurationManager.updateSmsConfiguration(smsConfig);
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration)

Example 3 with SmsConfiguration

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

the class UpdateBulkGateWayConfigAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    if (gatewayType != null && gatewayType.equals("bulksms")) {
        SmsConfiguration smsConfig = smsConfigurationManager.getSmsConfiguration();
        if (smsConfig != null) {
            BulkSmsGatewayConfig bulkGatewayConfig = (BulkSmsGatewayConfig) smsConfigurationManager.checkInstanceOfGateway(BulkSmsGatewayConfig.class);
            int index = -1;
            if (bulkGatewayConfig == null) {
                bulkGatewayConfig = new BulkSmsGatewayConfig();
            } else {
                index = smsConfig.getGateways().indexOf(bulkGatewayConfig);
            }
            bulkGatewayConfig.setName(name);
            bulkGatewayConfig.setPassword(password);
            bulkGatewayConfig.setUsername(username);
            bulkGatewayConfig.setUid(CodeGenerator.generateCode(10));
            if (smsConfig.getGateways() == null || smsConfig.getGateways().isEmpty()) {
                bulkGatewayConfig.setDefault(true);
            }
            if (index >= 0) {
                smsConfig.getGateways().set(index, bulkGatewayConfig);
            } else {
                smsConfig.getGateways().add(bulkGatewayConfig);
            }
            gatewayAdminService.getGatewayConfigurationMap().put(name, bulkGatewayConfig);
            smsConfigurationManager.updateSmsConfiguration(smsConfig);
        }
    }
    return SUCCESS;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig)

Example 4 with SmsConfiguration

use of org.hisp.dhis.sms.config.SmsConfiguration 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 5 with SmsConfiguration

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

the class UpdateGenericHTTPGateWayConfigAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
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 = -1;
            if (gatewayConfig == null) {
                gatewayConfig = new GenericHttpGatewayConfig();
            } else {
                index = config.getGateways().indexOf(gatewayConfig);
            }
            gatewayConfig.setMessageParameter(messageParameter);
            gatewayConfig.setRecipientParameter(recipientParameter);
            gatewayConfig.setName(name);
            gatewayConfig.setUrlTemplate(urlTemplate);
            gatewayConfig.setUid(CodeGenerator.generateCode(10));
            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) GenericHttpGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGatewayConfig)

Aggregations

SmsConfiguration (org.hisp.dhis.sms.config.SmsConfiguration)14 SmsGatewayConfig (org.hisp.dhis.sms.config.SmsGatewayConfig)8 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)4 ClickatellGatewayConfig (org.hisp.dhis.sms.config.ClickatellGatewayConfig)3 GenericHttpGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGatewayConfig)3 HashSet (java.util.HashSet)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 ProgramMessageQueryParams (org.hisp.dhis.program.message.ProgramMessageQueryParams)1 ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1