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