Search in sources :

Example 16 with SmsGatewayConfig

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;
}
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 17 with SmsGatewayConfig

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;
}
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)

Example 18 with SmsGatewayConfig

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);
}
Also used : ArrayList(java.util.ArrayList) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) GenericHttpGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGatewayConfig) GenericHttpGetGatewayConfig(org.hisp.dhis.sms.config.GenericHttpGetGatewayConfig)

Example 19 with SmsGatewayConfig

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));
}
Also used : SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

SmsGatewayConfig (org.hisp.dhis.sms.config.SmsGatewayConfig)19 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 SmsConfiguration (org.hisp.dhis.sms.config.SmsConfiguration)8 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)6 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 GenericHttpGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGatewayConfig)3 ArrayList (java.util.ArrayList)2 ClickatellGatewayConfig (org.hisp.dhis.sms.config.ClickatellGatewayConfig)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 TaskId (org.hisp.dhis.scheduling.TaskId)1 GenericHttpGetGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGetGatewayConfig)1 User (org.hisp.dhis.user.User)1 UserGroup (org.hisp.dhis.user.UserGroup)1