Search in sources :

Example 1 with IncomingSms

use of org.hisp.dhis.sms.incoming.IncomingSms in project dhis2-core by dhis2.

the class SmsConsumerThread method spawnSmsConsumer.

public void spawnSmsConsumer() {
    IncomingSms message = messageQueue.get();
    while (message != null) {
        log.info("Received SMS: " + message.getText());
        try {
            for (IncomingSmsListener listener : listeners) {
                if (listener.accept(message)) {
                    listener.receive(message);
                    messageQueue.remove(message);
                    return;
                }
            }
            log.warn("No SMS command found in received data");
            message.setStatus(SmsMessageStatus.UNHANDLED);
            smsSender.sendMessage(null, "No command found", message.getOriginator());
        } catch (Exception e) {
            log.error("Parse Error " + e.getMessage());
            message.setStatus(SmsMessageStatus.FAILED);
            message.setParsed(false);
        } finally {
            messageQueue.remove(message);
            incomingSmsService.update(message);
            message = messageQueue.get();
        }
    }
}
Also used : IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms) IncomingSmsListener(org.hisp.dhis.sms.incoming.IncomingSmsListener)

Example 2 with IncomingSms

use of org.hisp.dhis.sms.incoming.IncomingSms in project dhis2-core by dhis2.

the class HibernateIncomingSmsStore method getSmsByStatus.

@Override
@SuppressWarnings("unchecked")
public List<IncomingSms> getSmsByStatus(SmsMessageStatus status, String keyword) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(IncomingSms.class).addOrder(Order.desc("sentDate"));
    if (status != null) {
        criteria.add(Restrictions.eq("status", status));
    }
    criteria.add(Restrictions.ilike("originator", "%" + keyword + "%"));
    return criteria.list();
}
Also used : IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 3 with IncomingSms

use of org.hisp.dhis.sms.incoming.IncomingSms in project dhis2-core by dhis2.

the class HibernateIncomingSmsStore method getSmsByStatus.

@Override
@SuppressWarnings("unchecked")
public List<IncomingSms> getSmsByStatus(SmsMessageStatus status, String keyword, Integer min, Integer max) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(IncomingSms.class).addOrder(Order.desc("sentDate"));
    if (status != null) {
        criteria.add(Restrictions.eq("status", status));
    }
    criteria.add(Restrictions.ilike("originator", "%" + keyword + "%"));
    if (min != null && max != null) {
        criteria.setFirstResult(min).setMaxResults(max);
    }
    return criteria.list();
}
Also used : IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

Example 4 with IncomingSms

use of org.hisp.dhis.sms.incoming.IncomingSms in project dhis2-core by dhis2.

the class SmsController method receiveSMSMessage.

@RequestMapping(value = "/inbound", method = RequestMethod.POST, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SETTINGS')")
public void receiveSMSMessage(HttpServletRequest request, HttpServletResponse response) throws WebMessageException, ParseException, IOException {
    IncomingSms sms = renderService.fromJson(request.getInputStream(), IncomingSms.class);
    int smsId = incomingSMSService.save(sms);
    webMessageService.send(WebMessageUtils.ok("Received SMS: " + smsId), response, request);
}
Also used : IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with IncomingSms

use of org.hisp.dhis.sms.incoming.IncomingSms in project dhis2-core by dhis2.

the class UpdateReceiveSMSAction method execute.

@Override
public String execute() throws Exception {
    IncomingSms incomingSms = incomingSmsService.findBy(id);
    incomingSms.setText(text);
    incomingSmsService.update(incomingSms);
    return SUCCESS;
}
Also used : IncomingSms(org.hisp.dhis.sms.incoming.IncomingSms)

Aggregations

IncomingSms (org.hisp.dhis.sms.incoming.IncomingSms)7 Criteria (org.hibernate.Criteria)2 Session (org.hibernate.Session)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Iterator (java.util.Iterator)1 IncomingSmsListener (org.hisp.dhis.sms.incoming.IncomingSmsListener)1 SmsMessageStatus (org.hisp.dhis.sms.incoming.SmsMessageStatus)1 User (org.hisp.dhis.user.User)1 UserQueryParams (org.hisp.dhis.user.UserQueryParams)1