use of org.hisp.dhis.notification.SendStrategy in project dhis2-core by dhis2.
the class DefaultValidationNotificationService method sendNotifications.
// -------------------------------------------------------------------------
// ValidationNotificationService implementation
// -------------------------------------------------------------------------
@Override
public Set<ValidationResult> sendNotifications(Set<ValidationResult> validationResults) {
if (validationResults.isEmpty()) {
return Sets.newHashSet();
}
Clock clock = new Clock(log).startClock().logTime(String.format("Creating notifications for %d validation results", validationResults.size()));
// Filter out un-applicable validation results and put in (natural) order
SortedSet<ValidationResult> applicableResults = validationResults.stream().filter(IS_APPLICABLE_RESULT).collect(Collectors.toCollection(TreeSet::new));
// Transform into distinct pairs of ValidationRule and ValidationNotificationTemplate
SortedSet<MessagePair> messagePairs = createMessagePairs(applicableResults);
// Segregate MessagePairs based on SendStrategy
Map<SendStrategy, SortedSet<MessagePair>> segregatedMap = segregateMessagePairBasedOnStrategy(messagePairs);
Map<SendStrategy, Map<Set<User>, NotificationMessage>> notficationCollections = new HashMap<>();
notficationCollections.put(SendStrategy.SINGLE_NOTIFICATION, createSingleNotifications(segregatedMap.getOrDefault(SendStrategy.SINGLE_NOTIFICATION, new TreeSet<>())));
notficationCollections.put(SendStrategy.COLLECTIVE_SUMMARY, createSummaryNotifications(segregatedMap.getOrDefault(SendStrategy.COLLECTIVE_SUMMARY, new TreeSet<>())));
for (Map.Entry<SendStrategy, Map<Set<User>, NotificationMessage>> entry : notficationCollections.entrySet()) {
clock.logTime(String.format("Sending %d %s notification(s)", entry.getValue().size(), entry.getKey().getDescription()));
entry.getValue().forEach(this::sendNotification);
}
clock.logTime("Done sending validation notifications");
return applicableResults;
}
Aggregations