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