Search in sources :

Example 1 with DeliveryChannel

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;
}
Also used : ProgramMessageService(org.hisp.dhis.program.message.ProgramMessageService) java.util(java.util) CategoryService(org.hisp.dhis.category.CategoryService) NotificationMessageRenderer(org.hisp.dhis.notification.NotificationMessageRenderer) BiFunction(java.util.function.BiFunction) DataSet(org.hisp.dhis.dataset.DataSet) MessageConversationParams(org.hisp.dhis.message.MessageConversationParams) PeriodService(org.hisp.dhis.period.PeriodService) BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Autowired(org.springframework.beans.factory.annotation.Autowired) CompleteDataSetRegistrationService(org.hisp.dhis.dataset.CompleteDataSetRegistrationService) SendStrategy(org.hisp.dhis.notification.SendStrategy) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) MessageService(org.hisp.dhis.message.MessageService) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Service(org.springframework.stereotype.Service) User(org.hisp.dhis.user.User) NotificationTrigger(org.hisp.dhis.program.notification.NotificationTrigger) I18nManager(org.hisp.dhis.i18n.I18nManager) Period(org.hisp.dhis.period.Period) Function(com.google.common.base.Function) MessageType(org.hisp.dhis.message.MessageType) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) UserGroup(org.hisp.dhis.user.UserGroup) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) NotificationMessage(org.hisp.dhis.notification.NotificationMessage) DateUtils(org.hisp.dhis.util.DateUtils) TextUtils(org.hisp.dhis.commons.util.TextUtils) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients)

Example 2 with DeliveryChannel

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;
}
Also used : DefaultOutboundMessageBatchService(org.hisp.dhis.outboundmessage.DefaultOutboundMessageBatchService) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) HashMap(java.util.HashMap) MessageSender(org.hisp.dhis.message.MessageSender) SmsMessageSender(org.hisp.dhis.sms.config.SmsMessageSender) EmailMessageSender(org.hisp.dhis.message.EmailMessageSender) Bean(org.springframework.context.annotation.Bean)

Example 3 with DeliveryChannel

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients)

Example 4 with DeliveryChannel

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);
}
Also used : DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) MessageSender(org.hisp.dhis.message.MessageSender)

Aggregations

DeliveryChannel (org.hisp.dhis.common.DeliveryChannel)4 MessageSender (org.hisp.dhis.message.MessageSender)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)2 Function (com.google.common.base.Function)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 java.util (java.util)1 HashMap (java.util.HashMap)1 BiFunction (java.util.function.BiFunction)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CategoryService (org.hisp.dhis.category.CategoryService)1 TextUtils (org.hisp.dhis.commons.util.TextUtils)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 CompleteDataSetRegistrationService (org.hisp.dhis.dataset.CompleteDataSetRegistrationService)1 DataSet (org.hisp.dhis.dataset.DataSet)1