use of org.hisp.dhis.sms.config.SmsGatewayConfig 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;
}
use of org.hisp.dhis.sms.config.SmsGatewayConfig 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;
}
use of org.hisp.dhis.sms.config.SmsGatewayConfig in project dhis2-core by dhis2.
the class V2_34_6__Convert_systemsetting_value_column_from_bytea_to_string method updateSmsConfiguration.
private void updateSmsConfiguration(SmsConfiguration smsConfiguration) {
if (smsConfiguration == null) {
return;
}
List<SmsGatewayConfig> existingGatewayConfigs = smsConfiguration.getGateways();
List<SmsGatewayConfig> updatedGatewayConfigs = new ArrayList<>();
for (SmsGatewayConfig gatewayConfig : existingGatewayConfigs) {
if (gatewayConfig instanceof GenericHttpGetGatewayConfig) {
GenericHttpGatewayConfig newGatewayConfig = convertToNewSmsGenericConfig((GenericHttpGetGatewayConfig) gatewayConfig);
updatedGatewayConfigs.add(newGatewayConfig);
} else {
updatedGatewayConfigs.add(gatewayConfig);
}
}
smsConfiguration.setGateways(updatedGatewayConfigs);
}
use of org.hisp.dhis.sms.config.SmsGatewayConfig in project dhis2-core by dhis2.
the class SmsGatewayController method updateGateway.
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@PutMapping("/{uid}")
public WebMessage updateGateway(@PathVariable String uid, HttpServletRequest request) throws IOException {
SmsGatewayConfig config = gatewayAdminService.getByUid(uid);
if (config == null) {
return notFound("No gateway found");
}
SmsGatewayConfig updatedConfig = renderService.fromJson(request.getInputStream(), SmsGatewayConfig.class);
if (gatewayAdminService.hasDefaultGateway() && updatedConfig.isDefault() && !config.isDefault()) {
return conflict("Default gateway already exists");
}
gatewayAdminService.updateGateway(config, updatedConfig);
return ok(String.format("Gateway with uid: %s has been updated", uid));
}
Aggregations