use of org.jbpm.casemgmt.api.event.CaseCommentEvent in project jbpm by kiegroup.
the class CommentNotificationEventListener method collectOrgEntitiesByRole.
protected Set<OrganizationalEntity> collectOrgEntitiesByRole(List<String> mentionedRoles, CaseCommentEvent event, StringBuilder commentContent) {
Set<OrganizationalEntity> recipients = new HashSet<>();
CommentInstance comment = event.getComment();
for (String roleName : mentionedRoles) {
if (comment.getRestrictedTo() != null && !comment.getRestrictedTo().isEmpty() && !comment.getRestrictedTo().contains(roleName)) {
// mentioned role is not allowed to see this comment so remove it from the list
continue;
}
try {
Collection<OrganizationalEntity> assignments = ((CaseAssignment) event.getCaseFile()).getAssignments(roleName);
recipients.addAll(assignments);
String assignmnetsFlatten = assignments.stream().map(oe -> oe.getId()).collect(Collectors.joining(","));
String updatedCommentContent = commentContent.toString().replaceAll("@" + roleName, assignmnetsFlatten);
commentContent.setLength(0);
commentContent.append(updatedCommentContent);
} catch (IllegalArgumentException e) {
logger.debug("Role {} does not exist in case {}", roleName, event.getCaseId());
}
}
return recipients;
}
use of org.jbpm.casemgmt.api.event.CaseCommentEvent in project jbpm by kiegroup.
the class CommentNotificationEventListenerTest method testCollectOrgEntitiesByRole.
@Test
public void testCollectOrgEntitiesByRole() {
CommentNotificationEventListener listener = new CommentNotificationEventListener();
List<String> mentionedRoles = new ArrayList<>();
mentionedRoles.add("owner");
mentionedRoles.add("manager");
CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
StringBuilder commentContent = new StringBuilder(comment.getComment());
Set<OrganizationalEntity> collected = listener.collectOrgEntitiesByRole(mentionedRoles, event, commentContent);
assertThat(collected).hasSize(2);
assertThat(collected).allMatch(item -> item instanceof User);
assertThat(commentContent.toString()).isEqualTo("simple comment for john and mary");
}
use of org.jbpm.casemgmt.api.event.CaseCommentEvent in project jbpm by kiegroup.
the class CommentNotificationEventListenerTest method testNotificationOnCommentAddedWithRawBody.
@Test
public void testNotificationOnCommentAddedWithRawBody() {
CommentNotificationEventListener listener = new CommentNotificationEventListener();
List<String> mentionedRoles = new ArrayList<>();
mentionedRoles.add("owner");
mentionedRoles.add("manager");
CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
TestNotificationPublisher publisher = new TestNotificationPublisher(true);
listener.addPublisher(publisher);
listener.afterCaseCommentAdded(event);
String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-00001) comment to [[UserImpl:'mary'], [UserImpl:'john']] with body simple comment for john and mary";
List<String> published = publisher.get();
assertThat(published).hasSize(1);
assertThat(published.get(0)).isEqualTo(expectedNotification);
}
use of org.jbpm.casemgmt.api.event.CaseCommentEvent in project jbpm by kiegroup.
the class CommentNotificationEventListenerTest method testNotificationOnCommentAdded.
@Test
public void testNotificationOnCommentAdded() {
CommentNotificationEventListener listener = new CommentNotificationEventListener();
List<String> mentionedRoles = new ArrayList<>();
mentionedRoles.add("owner");
mentionedRoles.add("manager");
CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
TestNotificationPublisher publisher = new TestNotificationPublisher(false);
listener.addPublisher(publisher);
listener.afterCaseCommentAdded(event);
String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-00001) comment to [[UserImpl:'mary'], [UserImpl:'john']] with template mentioned-in-comment";
List<String> published = publisher.get();
assertThat(published).hasSize(1);
assertThat(published.get(0)).isEqualTo(expectedNotification);
}
use of org.jbpm.casemgmt.api.event.CaseCommentEvent in project jbpm by kiegroup.
the class CommentNotificationEventListenerTest method testCollectOrgEntitiesByRoleNotExistingRole.
@Test
public void testCollectOrgEntitiesByRoleNotExistingRole() {
CommentNotificationEventListener listener = new CommentNotificationEventListener();
List<String> mentionedRoles = new ArrayList<>();
mentionedRoles.add("owner");
mentionedRoles.add("manager");
CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
// add additional role that is not in case file
mentionedRoles.add("notexisting");
StringBuilder commentContent = new StringBuilder(comment.getComment());
Set<OrganizationalEntity> collected = listener.collectOrgEntitiesByRole(mentionedRoles, event, commentContent);
assertThat(collected).hasSize(2);
assertThat(collected).allMatch(item -> item instanceof User);
assertThat(commentContent.toString()).isEqualTo("simple comment for john and mary");
}
Aggregations