private static NotificationMessage createSummarizedMessage(
SortedSet<MessagePair> pairs, final Map<MessagePair, NotificationMessage> renderedNotificationsMap,
final Date validationDate )
{
Map<Importance, Long> counts = pairs.stream()
.map( m -> m.result.getValidationRule().getImportance() )
.collect( Collectors.groupingBy( Function.identity(), Collectors.counting() ) );
String subject = String.format(
"Validation violations as of %s",
DateUtils.getLongDateString( validationDate )
);
String message = String.format(
"Violations: High %d, medium %d, low %d",
counts.getOrDefault( HIGH, 0L ),
counts.getOrDefault( Importance.MEDIUM, 0L ),
counts.getOrDefault( LOW, 0L ) );
message = message + pairs.stream().sorted()
.map( renderedNotificationsMap::get )
.map( n -> String.format( "%s%s%s", n.getSubject(), LN, n.getMessage() ) )
.reduce( "", ( initStr, newStr ) -> String.format( "%s%s%s", initStr, LN + LN, newStr ) );
NotificationMessage notificationMessage = new NotificationMessage( subject, message );
notificationMessage.setPriority( getPriority( counts.getOrDefault( HIGH, 0L ) > 0 ? HIGH : counts.getOrDefault( MEDIUM, 0L ) > 0 ? MEDIUM : LOW ) );
return notificationMessage;
}