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