use of org.hisp.dhis.sms.outbound.OutboundSms in project dhis2-core by dhis2.
the class SendScheduledMessageTask method sendMessages.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void sendMessages() {
List<OutboundSms> outboundSmsList = outboundSmsService.getOutboundSms(OutboundSmsStatus.OUTBOUND);
if (outboundSmsList != null) {
for (OutboundSms outboundSms : outboundSmsList) {
outboundSms.setDate(new Date());
outboundSms.setStatus(OutboundSmsStatus.SENT);
smsSender.sendMessage(null, outboundSms.getMessage(), outboundSms.getRecipients());
}
}
}
use of org.hisp.dhis.sms.outbound.OutboundSms in project dhis2-core by dhis2.
the class HibernateOutboundSmsStore method get.
@SuppressWarnings("unchecked")
@Override
public List<OutboundSms> get(OutboundSmsStatus status) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(OutboundSms.class).addOrder(Order.desc("date"));
if (status != null) {
criteria.add(Restrictions.eq("status", status));
}
return criteria.list();
}
use of org.hisp.dhis.sms.outbound.OutboundSms in project dhis2-core by dhis2.
the class HibernateOutboundSmsStore method get.
@SuppressWarnings("unchecked")
@Override
public List<OutboundSms> get(OutboundSmsStatus status, Integer min, Integer max) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(OutboundSms.class).addOrder(Order.desc("date"));
if (status != null) {
criteria.add(Restrictions.eq("status", status));
}
if (min != null && max != null) {
criteria.setFirstResult(min).setMaxResults(max);
}
return criteria.list();
}
use of org.hisp.dhis.sms.outbound.OutboundSms in project dhis2-core by dhis2.
the class ShowSentSMSAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
listOutboundSMS = new ArrayList<>();
if (filterStatusType != null && filterStatusType == 0) {
total = outboundSmsService.getOutboundSms(OutboundSmsStatus.OUTBOUND).size();
paging = createPaging(total);
listOutboundSMS = outboundSmsService.getOutboundSms(OutboundSmsStatus.OUTBOUND, paging.getStartPos(), paging.getPageSize());
}
if (filterStatusType != null && filterStatusType == 1) {
total = outboundSmsService.getOutboundSms(OutboundSmsStatus.SENT).size();
paging = createPaging(total);
listOutboundSMS = outboundSmsService.getOutboundSms(OutboundSmsStatus.SENT, paging.getStartPos(), paging.getPageSize());
}
if (filterStatusType != null && filterStatusType == 2) {
total = outboundSmsService.getOutboundSms(OutboundSmsStatus.ERROR).size();
paging = createPaging(total);
listOutboundSMS = outboundSmsService.getOutboundSms(OutboundSmsStatus.ERROR, paging.getStartPos(), paging.getPageSize());
}
if (filterStatusType != null && filterStatusType == 3 || filterStatusType == null) {
filterStatusType = 3;
total = outboundSmsService.getAllOutboundSms().size();
paging = createPaging(total);
listOutboundSMS = outboundSmsService.getAllOutboundSms(paging.getStartPos(), paging.getPageSize());
}
// Get the name of recipients
recipientNames = new ArrayList<>();
recipientNames.add("");
String tempString;
for (OutboundSms outboundSms : listOutboundSMS) {
tempString = "";
for (String phoneNumber : outboundSms.getRecipients()) {
Collection<User> users = userService.getUsersByPhoneNumber(phoneNumber);
if (users == null || users.size() == 0) {
tempString += "[unknown]";
} else if (users.size() > 0) {
Iterator<User> usersIterator = users.iterator();
while (usersIterator.hasNext()) {
User user = usersIterator.next();
tempString += "[" + user.getUsername() + "]";
}
}
}
recipientNames.add(tempString);
}
return SUCCESS;
}
use of org.hisp.dhis.sms.outbound.OutboundSms in project dhis2-core by dhis2.
the class SmsController method sendSMSMessage.
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(value = "/outbound", method = RequestMethod.POST, consumes = "application/json")
public void sendSMSMessage(HttpServletResponse response, HttpServletRequest request) throws WebMessageException, IOException {
OutboundSms sms = renderService.fromJson(request.getInputStream(), OutboundSms.class);
OutboundMessageResponse status = smsSender.sendMessage(null, sms.getMessage(), sms.getRecipients());
if (status.isOk()) {
webMessageService.send(WebMessageUtils.ok("SMS sent"), response, request);
} else {
throw new WebMessageException(WebMessageUtils.error(status.getDescription()));
}
}
Aggregations