use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSender method generateSummary.
private OutboundMessageResponseSummary generateSummary(List<OutboundMessageResponse> statuses, OutboundMessageBatch batch, SmsGateway smsGateway) {
Set<GatewayResponse> okCodes = Sets.newHashSet(GatewayResponse.RESULT_CODE_0, GatewayResponse.RESULT_CODE_200, GatewayResponse.RESULT_CODE_202);
OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary();
int total, sent = 0;
boolean ok = true;
String errorMessage = StringUtils.EMPTY;
total = batch.getMessages().size();
for (OutboundMessageResponse status : statuses) {
if (okCodes.contains(status.getResponseObject())) {
sent = (smsGateway instanceof BulkSmsGateway) ? total : sent + 1;
} else {
ok = false;
errorMessage = status.getDescription();
}
}
summary.setTotal(total);
summary.setChannel(DeliveryChannel.SMS);
summary.setSent(sent);
summary.setFailed(total - sent);
if (!ok) {
summary.setBatchStatus(OutboundMessageBatchStatus.FAILED);
summary.setErrorMessage(errorMessage);
log.error(errorMessage);
} else {
summary.setBatchStatus(OutboundMessageBatchStatus.COMPLETED);
summary.setResponseMessage("SENT");
log.info("SMS batch processed successfully");
}
return summary;
}
use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSender method createMessageResponseSummary.
private OutboundMessageResponseSummary createMessageResponseSummary(String responseMessage, DeliveryChannel channel, OutboundMessageBatchStatus batchStatus, OutboundMessageBatch batch) {
OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary(responseMessage, channel, batchStatus);
summary.setTotal(batch.getMessages().size());
log.warn(responseMessage);
return summary;
}
use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSender method createMessageResponseSummary.
private OutboundMessageResponseSummary createMessageResponseSummary(String responseMessage, DeliveryChannel channel, OutboundMessageBatchStatus batchStatus, int total) {
OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary(responseMessage, channel, batchStatus);
summary.setTotal(total);
log.warn(responseMessage);
return summary;
}
use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSender method generateSummary.
private OutboundMessageResponseSummary generateSummary(List<OutboundMessageResponse> statuses, OutboundMessageBatch batch) {
Set<GatewayResponse> okCodes = Sets.newHashSet(GatewayResponse.RESULT_CODE_0, GatewayResponse.RESULT_CODE_200, GatewayResponse.RESULT_CODE_202);
OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary();
int total, sent = 0;
boolean ok = true;
String errorMessage = StringUtils.EMPTY;
total = batch.getMessages().size();
for (OutboundMessageResponse status : statuses) {
if (okCodes.contains(status.getResponseObject())) {
sent++;
} else {
ok = false;
errorMessage = status.getDescription();
}
}
summary.setTotal(total);
summary.setChannel(DeliveryChannel.SMS);
summary.setSent(sent);
summary.setFailed(total - sent);
if (!ok) {
summary.setBatchStatus(OutboundMessageBatchStatus.FAILED);
summary.setErrorMessage(errorMessage);
log.error(errorMessage);
} else {
summary.setBatchStatus(OutboundMessageBatchStatus.COMPLETED);
summary.setResponseMessage("SENT");
log.debug("SMS batch processed successfully");
}
return summary;
}
use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.
the class SmsMessageSenderTest method testSendMessageBatchWithOutMaxRecipients.
@Test
void testSendMessageBatchWithOutMaxRecipients() {
// stub for GateAdministrationService
when(gatewayAdministrationService.getDefaultGateway()).thenReturn(smsGatewayConfig);
mockGateway();
responseForCompletedBatch();
createOutBoundMessagesWithOutMaxRecipients();
ArgumentCaptor<OutboundMessageBatch> argumentCaptor = ArgumentCaptor.forClass(OutboundMessageBatch.class);
OutboundMessageBatch batch = new OutboundMessageBatch(outboundMessages, DeliveryChannel.SMS);
OutboundMessageResponseSummary summary = smsMessageSender.sendMessageBatch(batch);
assertNotNull(summary);
assertEquals(OutboundMessageBatchStatus.COMPLETED, summary.getBatchStatus());
verify(bulkSmsGateway, times(1)).sendBatch(argumentCaptor.capture(), any());
assertEquals(batch, argumentCaptor.getValue());
assertEquals(4, argumentCaptor.getValue().size());
}
Aggregations