Search in sources :

Example 6 with NotificationMessage

use of org.hisp.dhis.notification.NotificationMessage in project dhis2-core by dhis2.

the class ValidationNotificationServiceTest method initTest.

/*
     * Configure org unit hierarchy like so:
     *
     * Root / \ lvlOneLeft lvlOneRight / \ lvlTwoLeftLeft lvlTwoLeftRight
     */
/**
 * We mock the sending of messages to write to a local List (which we can
 * inspect). Also, the renderer is replaced with a mock which returns a
 * static subject/message-pair.
 */
@BeforeEach
void initTest() {
    subject = new DefaultValidationNotificationService(renderer, messageService, validationResultService);
    this.periodService = new DefaultPeriodService(periodStore);
    sentMessages = new ArrayList<>();
    when(messageService.sendValidationMessage(anySet(), anyString(), anyString(), any(MessageConversationPriority.class))).then(invocation -> {
        sentMessages.add(new MockMessage(invocation.getArguments()));
        return 42L;
    });
    // Stub renderer
    when(renderer.render(any(), any())).thenReturn(new NotificationMessage(STATIC_MOCK_SUBJECT, STATIC_MOCK_MESSAGE));
}
Also used : NotificationMessage(org.hisp.dhis.notification.NotificationMessage) MessageConversationPriority(org.hisp.dhis.message.MessageConversationPriority) DefaultPeriodService(org.hisp.dhis.period.DefaultPeriodService) DefaultValidationNotificationService(org.hisp.dhis.validation.notification.DefaultValidationNotificationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with NotificationMessage

use of org.hisp.dhis.notification.NotificationMessage in project dhis2-core by dhis2.

the class DefaultValidationNotificationService method createSingleNotifications.

private Map<Set<User>, NotificationMessage> createSingleNotifications(SortedSet<MessagePair> messagePairs) {
    BiMap<Set<User>, NotificationMessage> singleNotificationCollection = HashBiMap.create();
    for (MessagePair messagePair : messagePairs) {
        NotificationMessage notificationMessage = notificationMessageRenderer.render(messagePair.result, messagePair.template);
        notificationMessage.setPriority(getPriority(messagePair.result.getValidationRule().getImportance()));
        singleNotificationCollection.put(new HashSet<>(), notificationMessage);
        resolveRecipients(messagePair).forEach(user -> singleNotificationCollection.inverse().get(notificationMessage).add(user));
    }
    return singleNotificationCollection;
}
Also used : SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) NotificationMessage(org.hisp.dhis.notification.NotificationMessage)

Aggregations

NotificationMessage (org.hisp.dhis.notification.NotificationMessage)7 Date (java.util.Date)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 TreeSet (java.util.TreeSet)2 MessageConversationPriority (org.hisp.dhis.message.MessageConversationPriority)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 Sets (com.google.common.collect.Sets)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 NotNull (javax.validation.constraints.NotNull)1 Slf4j (lombok.extern.slf4j.Slf4j)1 BooleanUtils (org.apache.commons.lang3.BooleanUtils)1