use of org.kie.internal.utils.NotificationPublisher in project jbpm by kiegroup.
the class CommentNotificationEventListener method buildAndPublishNotification.
protected void buildAndPublishNotification(CaseCommentEvent event) {
if (publishers.isEmpty()) {
logger.debug("No publishers available, skipping comment notifications");
return;
}
CommentInstance comment = event.getComment();
List<String> mentionedRoles = extractMentionedRoles(comment.getComment());
if (mentionedRoles.isEmpty()) {
logger.debug("No one has been mentioned in the comment, skipping comment notification");
return;
}
logger.debug("Found mentions {} in comment {}", mentionedRoles, comment.getId());
StringBuilder commentContent = new StringBuilder(comment.getComment());
Set<OrganizationalEntity> recipients = collectOrgEntitiesByRole(mentionedRoles, event, commentContent);
String notificationSubject = MessageFormat.format(subject, event.getCaseId());
Map<String, Object> parameters = buildParams(event, commentContent);
for (NotificationPublisher publisher : publishers) {
if (!publisher.isActive()) {
logger.debug("Publisher {} is not active, skipping it", publisher);
continue;
}
try {
publisher.publish(sender, notificationSubject, recipients, template, parameters);
} catch (IllegalArgumentException e) {
publisher.publish(sender, notificationSubject, recipients, commentContent.toString());
}
}
}
Aggregations