Search in sources :

Example 1 with GenericHttpGatewayConfig

use of org.hisp.dhis.sms.config.GenericHttpGatewayConfig 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)

Example 2 with GenericHttpGatewayConfig

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

the class GenericSmsGatewayTest method setUp.

@BeforeEach
public void setUp() {
    subject = new SimplisticHttpGetGateWay(restTemplate, pbeStringEncryptor);
    gatewayConfig = new GenericHttpGatewayConfig();
    gatewayConfig.setUseGet(false);
    gatewayConfig.setName("generic");
    gatewayConfig.setUrlTemplate(GATEWAY_URL);
    gatewayConfig.setDefault(true);
    gatewayConfig.setUid(UID);
    username = new GenericGatewayParameter();
    username.setKey("user");
    username.setValue("user_uio");
    username.setEncode(false);
    username.setHeader(true);
    username.setConfidential(false);
    password = new GenericGatewayParameter();
    password.setKey("password");
    password.setValue("abc123");
    password.setEncode(false);
    password.setHeader(true);
    password.setConfidential(true);
    valueStore.put(SmsGateway.KEY_TEXT, SmsUtils.encode(TEXT));
    valueStore.put(SmsGateway.KEY_RECIPIENT, StringUtils.join(RECIPIENTS, ","));
}
Also used : GenericGatewayParameter(org.hisp.dhis.sms.config.GenericGatewayParameter) SimplisticHttpGetGateWay(org.hisp.dhis.sms.config.SimplisticHttpGetGateWay) GenericHttpGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGatewayConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with GenericHttpGatewayConfig

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

the class SmsConfigurationController method getTest.

@GetMapping("test")
@ResponseBody
public SmsConfiguration getTest() {
    SmsConfiguration smsConfiguration = new SmsConfiguration();
    SmsGatewayConfig gatewayConfig = new GenericHttpGatewayConfig();
    gatewayConfig.setUrlTemplate("http://storset.org/");
    smsConfiguration.setGateways(Collections.singletonList(gatewayConfig));
    return smsConfiguration;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) GenericHttpGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGatewayConfig) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with GenericHttpGatewayConfig

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

the class V2_34_6__Convert_systemsetting_value_column_from_bytea_to_string method convertToNewSmsGenericConfig.

private GenericHttpGatewayConfig convertToNewSmsGenericConfig(GenericHttpGetGatewayConfig gatewayConfig) {
    GenericHttpGatewayConfig newGatewayConfig = new GenericHttpGatewayConfig();
    newGatewayConfig.setContentType(ContentType.FORM_URL_ENCODED);
    newGatewayConfig.setDefault(gatewayConfig.isDefault());
    newGatewayConfig.setName(gatewayConfig.getName());
    newGatewayConfig.setParameters(gatewayConfig.getParameters());
    newGatewayConfig.setPassword(gatewayConfig.getPassword());
    newGatewayConfig.setUid(gatewayConfig.getUid());
    newGatewayConfig.setUrlTemplate(gatewayConfig.getUrlTemplate() + "?" + createConfigurationTemplateFromConfig(gatewayConfig));
    newGatewayConfig.setUseGet(true);
    newGatewayConfig.setSendUrlParameters(true);
    newGatewayConfig.setUsername(gatewayConfig.getUsername());
    return newGatewayConfig;
}
Also used : GenericHttpGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGatewayConfig)

Example 5 with GenericHttpGatewayConfig

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

GenericHttpGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGatewayConfig)7 SmsConfiguration (org.hisp.dhis.sms.config.SmsConfiguration)3 SmsGatewayConfig (org.hisp.dhis.sms.config.SmsGatewayConfig)3 ArrayList (java.util.ArrayList)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)1 ClickatellGatewayConfig (org.hisp.dhis.sms.config.ClickatellGatewayConfig)1 GenericGatewayParameter (org.hisp.dhis.sms.config.GenericGatewayParameter)1 GenericHttpGetGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGetGatewayConfig)1 SimplisticHttpGetGateWay (org.hisp.dhis.sms.config.SimplisticHttpGetGateWay)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1