Search in sources :

Example 31 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity 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 32 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class CaseFileInstanceImpl method getAssignments.

@Override
public Collection<OrganizationalEntity> getAssignments(String roleName) {
    String[] roleNames = roleName.split(separator);
    Collection<OrganizationalEntity> foundAssignments = new ArrayList<>();
    for (String role : roleNames) {
        CaseRoleInstance caseRoleInstance = this.roles.get(role);
        if (caseRoleInstance == null) {
            throw new IllegalArgumentException("No role with name " + role + " was found");
        }
        foundAssignments.addAll(caseRoleInstance.getRoleAssignments());
    }
    return foundAssignments;
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 33 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class CaseFileInstanceImpl method getRolesForOrgEntities.

public List<String> getRolesForOrgEntities(List<String> orgEntities) {
    List<String> collected = new ArrayList<>();
    if (roles == null || roles.isEmpty()) {
        return collected;
    }
    List<CaseRoleInstance> roleInstances = new ArrayList<>();
    for (Entry<String, CaseRoleInstance> entry : roles.entrySet()) {
        roleInstances.add(entry.getValue());
    }
    for (CaseRoleInstance cri : roleInstances) {
        if (cri.getRoleAssignments() == null || cri.getRoleAssignments().isEmpty()) {
            continue;
        }
        for (OrganizationalEntity assignee : cri.getRoleAssignments()) {
            if (orgEntities.contains(assignee.getId())) {
                collected.add(cri.getRoleName());
            }
        }
    }
    return collected;
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 34 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class NotifyOwnerSLAViolationListener method afterSLAViolated.

@Override
public void afterSLAViolated(SLAViolatedEvent event) {
    CaseFileInstance caseFile = getCaseFile((KieSession) event.getKieRuntime());
    if (caseFile != null) {
        String caseId = ((WorkflowProcessInstanceImpl) event.getProcessInstance()).getCorrelationKey();
        if (caseFile.getCaseId().equals(caseId)) {
            try {
                Collection<OrganizationalEntity> adminAssignments = ((CaseAssignment) caseFile).getAssignments("owner");
                String recipients = adminAssignments.stream().map(oe -> userInfo.getEmailForEntity(oe)).collect(Collectors.joining(";"));
                logger.debug("Case instance {} has SLA violation, notifying owner", caseId);
                CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
                Map<String, Object> parameters = buildEmailParameters(recipients, caseId, event);
                TaskSpecification taskSpec = caseService.newTaskSpec("Email", "SLA Violation for case " + caseId, parameters);
                caseService.addDynamicTask(caseId, taskSpec);
            } catch (IllegalArgumentException e) {
                logger.debug("There is no owner role defined in case instance {}, unable to notify SLA violation", caseId);
            }
        }
    }
}
Also used : Cacheable(org.kie.internal.runtime.Cacheable) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) Logger(org.slf4j.Logger) UserInfo(org.kie.internal.task.api.UserInfo) UserDataServiceProvider(org.jbpm.runtime.manager.impl.identity.UserDataServiceProvider) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) Collection(java.util.Collection) CaseService(org.jbpm.casemgmt.api.CaseService) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ClassObjectFilter(org.drools.core.ClassObjectFilter) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) Collectors(java.util.stream.Collectors) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) Map(java.util.Map) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KieSession(org.kie.api.runtime.KieSession) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) CaseService(org.jbpm.casemgmt.api.CaseService) CaseAssignment(org.kie.api.runtime.process.CaseAssignment)

Example 35 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class EmailNotificationPublisherTest method testEmailNotificationWithoutTemplate.

@Test
public void testEmailNotificationWithoutTemplate() throws Exception {
    EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo);
    Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newUser("john")));
    publisher.publish("admin@jbpm.org", "Test notification", recipients, "Test body");
    assertEquals(1, wiser.getMessages().size());
    MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
    // Side effect of MIME encoding (I think.. ): \r\n..
    String content = ((String) msg.getContent()).replace("\r\n", "");
    assertEquals("Test body", content);
    assertEquals("Test notification", msg.getSubject());
    assertEquals("admin@jbpm.org", ((InternetAddress) msg.getFrom()[0]).getAddress());
    assertEquals("john@domain.com", ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
    assertNull(msg.getRecipients(RecipientType.CC));
    assertNull(msg.getRecipients(RecipientType.BCC));
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Aggregations

OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)146 Test (org.junit.Test)93 HashMap (java.util.HashMap)69 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)55 ArrayList (java.util.ArrayList)54 User (org.kie.api.task.model.User)52 UserImpl (org.jbpm.services.task.impl.model.UserImpl)51 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)48 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)41 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)36 InternalTask (org.kie.internal.task.api.model.InternalTask)35 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)34 Task (org.kie.api.task.model.Task)33 QueryContext (org.kie.api.runtime.query.QueryContext)32 Group (org.kie.api.task.model.Group)29 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)26 TaskSummary (org.kie.api.task.model.TaskSummary)25 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)24 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)24 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)24