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;
}
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, ","));
}
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;
}
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;
}
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;
}
Aggregations