Search in sources :

Example 1 with SmsGatewayConfig

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

the class DefaultSmsConfigurationManager method gatewayExists.

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

Example 2 with SmsGatewayConfig

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

the class SmsGatewayController method getGatewayConfiguration.

@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/{uid}", method = RequestMethod.GET, produces = "application/json")
public void getGatewayConfiguration(@PathVariable String uid, HttpServletRequest request, HttpServletResponse response) throws WebMessageException, IOException {
    SmsGatewayConfig gateway = gatewayAdminService.getGatewayConfigurationByUid(uid);
    if (gateway == null) {
        throw new WebMessageException(WebMessageUtils.notFound("No gateway found"));
    }
    renderService.toJson(response.getOutputStream(), gateway);
}
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 3 with SmsGatewayConfig

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

the class ProcessingSendSMSAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
public String execute() throws Exception {
    SmsGatewayConfig defaultgateway = gatewayAdminService.getDefaultGateway();
    if (defaultgateway == null) {
        message = i18n.getString("please_select_a_gateway_type_to_send_sms");
        return ERROR;
    }
    if (text == null || text.trim().length() == 0) {
        message = i18n.getString("no_message");
        return ERROR;
    }
    User currentUser = currentUserService.getCurrentUser();
    List<User> recipientsList = new ArrayList<>();
    if ("phone".equals(sendTarget)) {
        ObjectMapper mapper = new ObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        recipients = mapper.readValue(recipients.iterator().next(), Set.class);
        for (String each : recipients) {
            User user = new User();
            user.setPhoneNumber(each);
            recipientsList.add(user);
        }
    // message = messageSender.sendMessage( smsSubject, smsMessage,
    // currentUser, true, recipients, gatewayId );
    } else if ("userGroup".equals(sendTarget)) {
        UserGroup group = userGroupService.getUserGroup(userGroup);
        if (group == null) {
            message = i18n.getString("selected_user_group_is_unavailable");
            return ERROR;
        }
        if (group.getMembers() == null || group.getMembers().isEmpty()) {
            message = i18n.getString("selected_user_group_has_no_member");
            return ERROR;
        }
        recipientsList = new ArrayList<>(group.getMembers());
    } else if ("user".equals(sendTarget)) {
        Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits();
        if (units != null && !units.isEmpty()) {
            for (OrganisationUnit unit : units) {
                recipientsList.addAll(unit.getUsers());
            }
            if (recipientsList.isEmpty()) {
                message = i18n.getString("there_is_no_user_assigned_to_selected_units");
                return ERROR;
            }
        // message = messageSender.sendMessage( smsSubject, smsMessage,
        // currentUser, false, users, gatewayId );
        }
    } else if ("unit".equals(sendTarget)) {
        for (OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits()) {
            if (unit.getPhoneNumber() != null && !unit.getPhoneNumber().isEmpty()) {
                User user = new User();
                user.setPhoneNumber(unit.getPhoneNumber());
                recipientsList.add(user);
            }
        }
        if (recipientsList.isEmpty()) {
            message = i18n.getString("selected_units_have_no_phone_number");
            return ERROR;
        }
    }
    TaskId taskId = new TaskId(TaskCategory.SENDING_SMS, currentUser);
    notifier.clear(taskId);
    sendSmsTask.setTaskId(taskId);
    sendSmsTask.setCurrentUser(currentUser);
    sendSmsTask.setRecipientsList(recipientsList);
    sendSmsTask.setSmsSubject(smsSubject);
    sendSmsTask.setText(text);
    scheduler.executeTask(sendSmsTask);
    if (message != null && !message.equals("success")) {
        message = i18n.getString(message);
        return ERROR;
    }
    if (message == null) {
        message = "An inter error occurs, please contact your administration";
        return ERROR;
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) HashSet(java.util.HashSet) Set(java.util.Set) TaskId(org.hisp.dhis.scheduling.TaskId) ArrayList(java.util.ArrayList) SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UserGroup(org.hisp.dhis.user.UserGroup)

Example 4 with SmsGatewayConfig

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

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

the class SmsGatewayController method addGateway.

@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@PostMapping
@ResponseBody
public WebMessage addGateway(HttpServletRequest request, HttpServletResponse response) throws IOException {
    SmsGatewayConfig config = renderService.fromJson(request.getInputStream(), SmsGatewayConfig.class);
    if (config == null) {
        return conflict("Cannot de-serialize SMS configurations");
    }
    gatewayAdminService.addGateway(config);
    return ok("Gateway configuration added").setLocation("/gateways/" + config.getUid());
}
Also used : SmsGatewayConfig(org.hisp.dhis.sms.config.SmsGatewayConfig) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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