Search in sources :

Example 1 with CaseCommentEvent

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;
}
Also used : Cacheable(org.kie.internal.runtime.Cacheable) Logger(org.slf4j.Logger) Collection(java.util.Collection) CaseEventListener(org.jbpm.casemgmt.api.event.CaseEventListener) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) ServiceLoader(java.util.ServiceLoader) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) Collectors(java.util.stream.Collectors) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) List(java.util.List) Matcher(java.util.regex.Matcher) Map(java.util.Map) NotificationPublisher(org.kie.internal.utils.NotificationPublisher) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) Pattern(java.util.regex.Pattern) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) HashSet(java.util.HashSet)

Example 2 with CaseCommentEvent

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");
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with CaseCommentEvent

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);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) TestNotificationPublisher(org.jbpm.casemgmt.impl.util.TestNotificationPublisher) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with CaseCommentEvent

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);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) TestNotificationPublisher(org.jbpm.casemgmt.impl.util.TestNotificationPublisher) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with CaseCommentEvent

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");
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CaseCommentEvent (org.jbpm.casemgmt.api.event.CaseCommentEvent)6 ArrayList (java.util.ArrayList)5 CommentInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl)5 Test (org.junit.Test)5 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)3 TestNotificationPublisher (org.jbpm.casemgmt.impl.util.TestNotificationPublisher)2 User (org.kie.api.task.model.User)2 MessageFormat (java.text.MessageFormat)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 CaseEventListener (org.jbpm.casemgmt.api.event.CaseEventListener)1