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