Search in sources :

Example 6 with OutboundSms

use of org.hisp.dhis.sms.outbound.OutboundSms in project dhis2-core by dhis2.

the class SendSmsTask method run.

@Override
public void run() {
    notifier.notify(taskId, "Sending SMS");
    status = smsSender.sendMessage(smsSubject, text, null, currentUser, new HashSet<>(recipientsList), false);
    OutboundSms sms = new OutboundSms();
    sms.setMessage(text);
    sms.setRecipients(recipientsList.stream().map(item -> item.getPhoneNumber()).collect(Collectors.toSet()));
    if (status.isOk()) {
        notifier.notify(taskId, "Message sending successful");
        sms.setStatus(OutboundSmsStatus.SENT);
    } else {
        notifier.notify(taskId, "Message sending failed");
        sms.setStatus(OutboundSmsStatus.FAILED);
    }
    outboundSmsService.saveOutboundSms(sms);
}
Also used : OutboundSms(org.hisp.dhis.sms.outbound.OutboundSms) HashSet(java.util.HashSet)

Example 7 with OutboundSms

use of org.hisp.dhis.sms.outbound.OutboundSms in project dhis2-core by dhis2.

the class HibernateOutboundSmsStore method getAllOutboundSms.

@SuppressWarnings("unchecked")
@Override
public List<OutboundSms> getAllOutboundSms(Integer min, Integer max) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(OutboundSms.class).addOrder(Order.desc("date"));
    if (min != null && max != null) {
        criteria.setFirstResult(min).setMaxResults(max);
    }
    return criteria.list();
}
Also used : OutboundSms(org.hisp.dhis.sms.outbound.OutboundSms) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Aggregations

OutboundSms (org.hisp.dhis.sms.outbound.OutboundSms)7 Criteria (org.hibernate.Criteria)3 Session (org.hibernate.Session)3 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)1 User (org.hisp.dhis.user.User)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1