Search in sources :

Example 6 with OutboundMessageResponseSummary

use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.

the class SmsMessageSenderTest method testSendMessageBatchWithOutGatewayConfiguration.

@Test
void testSendMessageBatchWithOutGatewayConfiguration() {
    when(gatewayAdministrationService.getDefaultGateway()).thenReturn(null);
    responseForFailedBatch();
    OutboundMessageBatch batch = new OutboundMessageBatch(outboundMessages, DeliveryChannel.SMS);
    OutboundMessageResponseSummary summary = smsMessageSender.sendMessageBatch(batch);
    assertNotNull(summary);
    assertEquals(OutboundMessageBatchStatus.FAILED, summary.getBatchStatus());
    assertEquals(NO_CONFIG, summary.getErrorMessage());
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) Test(org.junit.jupiter.api.Test)

Example 7 with OutboundMessageResponseSummary

use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.

the class DataSetNotificationServiceTest method setUpConfigurations.

private void setUpConfigurations() {
    categoryOptionCombo = new CategoryOptionCombo();
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitB = createOrganisationUnit('B');
    organisationUnitA.setPhoneNumber(PHONE_NUMBER);
    organisationUnitB.setPhoneNumber(PHONE_NUMBER);
    periodA = createPeriod(new MonthlyPeriodType(), getDate(2000, 1, 1), getDate(2000, 1, 31));
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementA.setUid(DATA_ELEMENT_A_UID);
    dataElementB.setUid(DATA_ELEMENT_B_UID);
    dataSetA = createDataSet('A', new MonthlyPeriodType());
    dataSetA.addDataSetElement(dataElementA);
    dataSetA.addDataSetElement(dataElementB);
    dataSetA.getSources().add(organisationUnitA);
    dataSetA.getSources().add(organisationUnitB);
    smsTemplateA = new DataSetNotificationTemplate();
    smsTemplateA.setUid(TEMPALTE_A_UID);
    smsTemplateA.setDataSetNotificationTrigger(DataSetNotificationTrigger.DATA_SET_COMPLETION);
    smsTemplateA.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.SMS));
    smsTemplateA.setNotificationRecipient(DataSetNotificationRecipient.ORGANISATION_UNIT_CONTACT);
    smsTemplateA.getDataSets().add(dataSetA);
    emailTemplateB = new DataSetNotificationTemplate();
    emailTemplateB.setUid(TEMPALTE_B_UID);
    emailTemplateB.setDataSetNotificationTrigger(DataSetNotificationTrigger.DATA_SET_COMPLETION);
    emailTemplateB.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.EMAIL));
    emailTemplateB.setNotificationRecipient(DataSetNotificationRecipient.ORGANISATION_UNIT_CONTACT);
    emailTemplateB.getDataSets().add(dataSetA);
    templates.add(smsTemplateA);
    registrationA = new CompleteDataSetRegistration(dataSetA, periodA, organisationUnitA, categoryOptionCombo, new Date(), "", new Date(), "", true);
    notificationMessage = new NotificationMessage("subject", "message");
    summary = new OutboundMessageResponseSummary();
    summary.setBatchStatus(OutboundMessageBatchStatus.COMPLETED);
    summary.setChannel(DeliveryChannel.SMS);
    successStatus = new BatchResponseStatus(Arrays.asList(summary));
}
Also used : BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) NotificationMessage(org.hisp.dhis.notification.NotificationMessage) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date)

Example 8 with OutboundMessageResponseSummary

use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.

the class EmailMessageSender method generateSummary.

private OutboundMessageResponseSummary generateSummary(List<OutboundMessageResponse> statuses) {
    OutboundMessageResponseSummary summary = new OutboundMessageResponseSummary();
    int total, sent = 0;
    boolean ok = true;
    String errorMessage = StringUtils.EMPTY;
    total = statuses.size();
    for (OutboundMessageResponse status : statuses) {
        if (EmailResponse.SENT.equals(status.getResponseObject())) {
            sent++;
        } else {
            ok = false;
            errorMessage = status.getDescription();
        }
    }
    summary.setTotal(total);
    summary.setChannel(DeliveryChannel.EMAIL);
    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("EMAIL batch processed successfully");
    }
    return summary;
}
Also used : OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse)

Example 9 with OutboundMessageResponseSummary

use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.

the class DefaultProgramMessageService method sendMessagesAsync.

@Override
@Transactional
public void sendMessagesAsync(List<ProgramMessage> programMessages) {
    List<ProgramMessage> populatedProgramMessages = programMessages.stream().filter(this::hasDataWriteAccess).map(this::setAttributesBasedOnStrategy).collect(Collectors.toList());
    List<OutboundMessageBatch> batches = createBatches(populatedProgramMessages);
    for (OutboundMessageBatch batch : batches) {
        ListenableFuture<OutboundMessageResponseSummary> future = smsSender.sendMessageBatchAsync(batch);
        future.addCallback(sendingCallback.getBatchCallBack());
    }
}
Also used : OutboundMessageBatch(org.hisp.dhis.outboundmessage.OutboundMessageBatch) OutboundMessageResponseSummary(org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with OutboundMessageResponseSummary

use of org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary in project dhis2-core by dhis2.

the class SmsMessageSenderTest method testIfBatchIsNull.

@Test
void testIfBatchIsNull() {
    OutboundMessageResponseSummary summary = smsMessageSender.sendMessageBatch(null);
    assertNotNull(summary);
    assertEquals(OutboundMessageBatchStatus.ABORTED, summary.getBatchStatus());
}
Also used : 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