use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class ProgramMessageController method saveMessages.
// -------------------------------------------------------------------------
// POST
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_MOBILE_SENDSMS')")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" })
public void saveMessages(HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
ProgramMessageBatch batch = renderService.fromJson(request.getInputStream(), ProgramMessageBatch.class);
for (ProgramMessage programMessage : batch.getProgramMessages()) {
programMessageService.validatePayload(programMessage);
}
BatchResponseStatus status = programMessageService.sendMessages(batch.getProgramMessages());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), status);
}
use of org.hisp.dhis.outboundmessage.BatchResponseStatus 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.BatchResponseStatus in project dhis2-core by dhis2.
the class DefaultProgramMessageService method sendMessages.
@Override
@Transactional
public BatchResponseStatus sendMessages(List<ProgramMessage> programMessages) {
List<ProgramMessage> populatedProgramMessages = programMessages.stream().filter(this::hasDataWriteAccess).map(this::setAttributesBasedOnStrategy).collect(Collectors.toList());
List<OutboundMessageBatch> batches = createBatches(populatedProgramMessages);
BatchResponseStatus status = new BatchResponseStatus(messageBatchService.sendBatches(batches));
saveProgramMessages(programMessages, status);
return status;
}
use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class DefaultProgramNotificationService method sendProgramMessages.
private void sendProgramMessages(Set<ProgramMessage> messages) {
if (messages.isEmpty()) {
return;
}
log.debug(String.format("Dispatching %d ProgramMessages", messages.size()));
BatchResponseStatus status = programMessageService.sendMessages(Lists.newArrayList(messages));
log.debug(String.format("Resulting status from ProgramMessageService:\n %s", status.toString()));
}
use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class ProgramNotificationServiceTest method testSendEnrollmentNotification.
@Test
void testSendEnrollmentNotification() {
when(programInstanceStore.get(anyLong())).thenReturn(programInstances.iterator().next());
when(programMessageService.sendMessages(anyList())).thenAnswer(invocation -> {
sentProgramMessages.addAll((List<ProgramMessage>) invocation.getArguments()[0]);
return new BatchResponseStatus(Collections.emptyList());
});
when(programNotificationRenderer.render(any(ProgramInstance.class), any(NotificationTemplate.class))).thenReturn(notificationMessage);
programNotificationTemplate.setNotificationTrigger(NotificationTrigger.ENROLLMENT);
programNotificationService.sendEnrollmentNotifications(programInstances.iterator().next().getId());
assertEquals(1, sentProgramMessages.size());
ProgramMessage programMessage = sentProgramMessages.iterator().next();
assertEquals(TrackedEntityInstance.class, programMessage.getRecipients().getTrackedEntityInstance().getClass());
assertEquals(tei, programMessage.getRecipients().getTrackedEntityInstance());
}
Aggregations