Search in sources :

Example 1 with IncomingSmsListener

use of org.hisp.dhis.sms.incoming.IncomingSmsListener 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 IncomingSmsListener

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

the class ReimportSMSAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    incomingSMS = incomingSmsService.findBy(Integer.parseInt(incomingSMSId));
    if (incomingSMS == null) {
        return "error";
    }
    try {
        for (IncomingSmsListener listener : listeners) {
            if (listener.accept(incomingSMS)) {
                listener.receive(incomingSMS);
                incomingSMS.setStatus(SmsMessageStatus.PROCESSED);
                incomingSmsService.update(incomingSMS);
                message = "SMS imported";
                return SUCCESS;
            }
        }
        message = "No Command Found";
    } catch (Exception e) {
        message = e.getMessage();
        return "error";
    }
    return SUCCESS;
}
Also used : IncomingSmsListener(org.hisp.dhis.sms.incoming.IncomingSmsListener)

Aggregations

IncomingSmsListener (org.hisp.dhis.sms.incoming.IncomingSmsListener)2 IncomingSms (org.hisp.dhis.sms.incoming.IncomingSms)1