use of org.hisp.dhis.common.DeliveryChannel in project dhis2-core by dhis2.
the class DefaultDataSetNotificationService method resolveExternalRecipientsForSchedule.
private ProgramMessageRecipients resolveExternalRecipientsForSchedule(DataSetNotificationTemplate template, CompleteDataSetRegistration registration) {
ProgramMessageRecipients recipients = new ProgramMessageRecipients();
for (DeliveryChannel channel : template.getDeliveryChannels()) {
Set<OrganisationUnit> ous = registration.getDataSet().getSources().stream().filter(ou -> VALIDATOR.get(channel).test(ou)).collect(Collectors.toSet());
recipients = RECIPIENT_MAPPER.get(channel).apply(ous, recipients);
}
return recipients;
}
use of org.hisp.dhis.common.DeliveryChannel in project dhis2-core by dhis2.
the class ServiceConfig method defaultOutboundMessageBatchService.
@Bean("org.hisp.dhis.outboundmessage.OutboundMessageService")
public DefaultOutboundMessageBatchService defaultOutboundMessageBatchService(SmsMessageSender smsMessageSender, EmailMessageSender emailMessageSender) {
Map<DeliveryChannel, MessageSender> channels = new HashMap<>();
channels.put(DeliveryChannel.SMS, smsMessageSender);
channels.put(DeliveryChannel.EMAIL, emailMessageSender);
DefaultOutboundMessageBatchService service = new DefaultOutboundMessageBatchService();
service.setMessageSenders(channels);
return service;
}
use of org.hisp.dhis.common.DeliveryChannel in project dhis2-core by dhis2.
the class DefaultDataSetNotificationService method resolveExternalRecipients.
private ProgramMessageRecipients resolveExternalRecipients(DataSetNotificationTemplate template, CompleteDataSetRegistration registration) {
ProgramMessageRecipients recipients = new ProgramMessageRecipients();
OrganisationUnit ou = registration.getSource();
for (DeliveryChannel channel : template.getDeliveryChannels()) {
if (VALIDATOR.get(channel).test(ou)) {
recipients = RECIPIENT_MAPPER.get(channel).apply(Sets.newHashSet(ou), recipients);
} else {
log.error(String.format("DataSet notification not sent due to invalid %s recipient", channel));
throw new IllegalArgumentException(String.format("Invalid %s recipient", channel));
}
}
return recipients;
}
use of org.hisp.dhis.common.DeliveryChannel in project dhis2-core by dhis2.
the class DefaultOutboundMessageBatchService method send.
// ---------------------------------------------------------------------
// Supportive Methods
// ---------------------------------------------------------------------
private OutboundMessageResponseSummary send(OutboundMessageBatch batch) {
DeliveryChannel channel = batch.getDeliveryChannel();
MessageSender sender = messageSenders.get(channel);
if (sender == null) {
String errorMessage = String.format("No server/gateway found for delivery channel %s", channel);
log.error(errorMessage);
return new OutboundMessageResponseSummary(errorMessage, channel, OutboundMessageBatchStatus.FAILED);
} else if (!sender.isConfigured()) {
String errorMessage = String.format("Server/gateway for delivery channel %s is not configured", channel);
log.error(errorMessage);
return new OutboundMessageResponseSummary(errorMessage, channel, OutboundMessageBatchStatus.FAILED);
}
log.info("Invoking message sender: " + sender.getClass().getSimpleName());
return sender.sendMessageBatch(batch);
}
Aggregations