Search in sources :

Example 6 with SmsGatewayConfig

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

the class DefaultSmsConfigurationManager method setDefaultSMSGateway.

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

Example 7 with SmsGatewayConfig

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

the class DefaultSmsConfigurationManager method checkInstanceOfGateway.

@Override
public SmsGatewayConfig checkInstanceOfGateway(Class<?> clazz) {
    if (getSmsConfiguration() == null) {
        SmsConfiguration smsConfig = new SmsConfiguration(true);
        updateSmsConfiguration(smsConfig);
    }
    for (SmsGatewayConfig gateway : getSmsConfiguration().getGateways()) {
        if (gateway.getClass().equals(clazz)) {
            return gateway;
        }
    }
    return null;
}
Also used : SmsConfiguration(org.hisp.dhis.sms.config.SmsConfiguration) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig)

Example 8 with SmsGatewayConfig

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

the class SmsGatewayController method removeGateway.

// -------------------------------------------------------------------------
// DELETE
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/{uid}", method = RequestMethod.DELETE)
public void removeGateway(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
    SmsGatewayConfig gateway = gatewayAdminService.getGatewayConfigurationByUid(uid);
    if (gateway == null) {
        throw new WebMessageException(WebMessageUtils.notFound("No gateway found with id: " + uid));
    }
    gatewayAdminService.removeGatewayByUid(uid);
    webMessageService.send(WebMessageUtils.ok("Gateway removed successfully"), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with SmsGatewayConfig

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

the class SmsGatewayController method setDefault.

@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/default/{uid}", method = RequestMethod.PUT)
public void setDefault(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
    SmsGatewayConfig gateway = gatewayAdminService.getGatewayConfigurationByUid(uid);
    if (gateway == null) {
        throw new WebMessageException(WebMessageUtils.notFound("No gateway found"));
    }
    gatewayAdminService.setDefaultGateway(uid);
    webMessageService.send(WebMessageUtils.ok(gateway.getName() + " is set to default"), response, request);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with SmsGatewayConfig

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

the class SmsGatewayController method getDefault.

@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/default", method = RequestMethod.GET)
public void getDefault(HttpServletRequest request, HttpServletResponse response) throws WebMessageException, IOException {
    SmsGatewayConfig defaultGateway = gatewayAdminService.getDefaultGateway();
    if (defaultGateway == null) {
        throw new WebMessageException(WebMessageUtils.notFound("No default gateway found"));
    }
    renderService.toJson(response.getOutputStream(), defaultGateway);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) BulkSmsGatewayConfig(org.hisp.dhis.sms.config.BulkSmsGatewayConfig) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SmsGatewayConfig (org.hisp.dhis.sms.config.SmsGatewayConfig)13 SmsConfiguration (org.hisp.dhis.sms.config.SmsConfiguration)8 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 ClickatellGatewayConfig (org.hisp.dhis.sms.config.ClickatellGatewayConfig)2 GenericHttpGatewayConfig (org.hisp.dhis.sms.config.GenericHttpGatewayConfig)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)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 User (org.hisp.dhis.user.User)1 UserGroup (org.hisp.dhis.user.UserGroup)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1