Search in sources :

Example 1 with OutboundMessageResponseSummary

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;
}
Also used : GatewayResponse(org.hisp.dhis.sms.outbound.GatewayResponse) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 2 with OutboundMessageResponseSummary

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;
}
Also used : OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary)

Example 3 with OutboundMessageResponseSummary

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;
}
Also used : OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary)

Example 4 with OutboundMessageResponseSummary

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;
}
Also used : GatewayResponse(org.hisp.dhis.sms.outbound.GatewayResponse) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 5 with OutboundMessageResponseSummary

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());
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) Test(org.junit.jupiter.api.Test)

Aggregations

OutboundMessageResponseSummary (org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary)14 OutboundMessageBatch (org.hisp.dhis.outboundmessage.OutboundMessageBatch)6 Test (org.junit.jupiter.api.Test)6 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)4 GatewayResponse (org.hisp.dhis.sms.outbound.GatewayResponse)2 Date (java.util.Date)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 NotificationMessage (org.hisp.dhis.notification.NotificationMessage)1 BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)1 OutboundMessage (org.hisp.dhis.outboundmessage.OutboundMessage)1 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)1 BulkSmsGatewayConfig (org.hisp.dhis.sms.config.BulkSmsGatewayConfig)1 Transactional (org.springframework.transaction.annotation.Transactional)1