Search in sources :

Example 21 with Group

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

the class EscalateToAdminSLAViolationListener 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("admin");
                String users = adminAssignments.stream().filter(oe -> oe instanceof User).map(oe -> oe.getId()).collect(Collectors.joining(","));
                String groups = adminAssignments.stream().filter(oe -> oe instanceof Group).map(oe -> oe.getId()).collect(Collectors.joining(","));
                String taskName = "SLA violation for case " + caseId;
                String taskDescription = "Service Level Agreement has been violated for case " + caseId;
                if (event.getNodeInstance() != null) {
                    taskName += "Task (" + event.getNodeInstance().getNodeName() + ") SLA violation for case " + caseId;
                    taskDescription += " on task " + event.getNodeInstance().getNodeName();
                }
                logger.debug("Case instance {} has SLA violation, escalating to administrator", caseId);
                CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
                TaskSpecification taskSpec = caseService.newHumanTaskSpec(taskName, taskDescription, users, groups, null);
                caseService.addDynamicTask(caseId, taskSpec);
            } catch (IllegalArgumentException e) {
                logger.debug("There is no admin role defined in case instance {}, unable to escalate SLA violation", caseId);
            }
        }
    }
}
Also used : Cacheable(org.kie.internal.runtime.Cacheable) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) Logger(org.slf4j.Logger) 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) ClassObjectFilter(org.drools.core.ClassObjectFilter) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) Collectors(java.util.stream.Collectors) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Group(org.kie.api.task.model.Group) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KieSession(org.kie.api.runtime.KieSession) User(org.kie.api.task.model.User) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) Group(org.kie.api.task.model.Group) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) User(org.kie.api.task.model.User) 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 22 with Group

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

the class RoundRobinAssignmentStrategy method getExcludedEntities.

private static List<OrganizationalEntity> getExcludedEntities(Task task, UserInfo userInfo) {
    List<OrganizationalEntity> excluded = ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners();
    List<OrganizationalEntity> excludedUsers = new ArrayList<>();
    for (OrganizationalEntity entity : excluded) {
        if (entity instanceof Group) {
            userInfo.getMembersForGroup((Group) entity).forEachRemaining(excludedUsers::add);
        }
    }
    excluded.addAll(excludedUsers);
    return excluded;
}
Also used : Group(org.kie.api.task.model.Group) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList)

Example 23 with Group

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

the class UserGroupCallbackTaskCommand method persistIfNotExists.

protected void persistIfNotExists(final OrganizationalEntity entity, TaskContext context) {
    TaskPersistenceContext tpc = context.getPersistenceContext();
    OrganizationalEntity orgEntity = tpc.findOrgEntity(entity.getId());
    if (orgEntity == null || (orgEntity instanceof Group && entity instanceof User) || (orgEntity instanceof User && entity instanceof Group)) {
        tpc.persistOrgEntity(entity);
    }
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 24 with Group

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

the class UserGroupCallbackTaskCommand method doCallbackOperationForTaskDeadlines.

protected void doCallbackOperationForTaskDeadlines(Deadlines deadlines, TaskContext context) {
    if (deadlines != null) {
        if (deadlines.getStartDeadlines() != null) {
            List<? extends Deadline> startDeadlines = deadlines.getStartDeadlines();
            for (Deadline startDeadline : startDeadlines) {
                List<? extends Escalation> escalations = startDeadline.getEscalations();
                if (escalations != null) {
                    for (Escalation escalation : escalations) {
                        List<? extends Notification> notifications = escalation.getNotifications();
                        List<? extends Reassignment> ressignments = escalation.getReassignments();
                        if (notifications != null) {
                            for (Notification notification : notifications) {
                                List<? extends OrganizationalEntity> recipients = notification.getRecipients();
                                if (recipients != null) {
                                    for (OrganizationalEntity recipient : recipients) {
                                        if (recipient instanceof User) {
                                            doCallbackUserOperation(recipient.getId(), context);
                                        }
                                        if (recipient instanceof Group) {
                                            doCallbackGroupOperation(recipient.getId(), context);
                                        }
                                    }
                                }
                                List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
                                if (administrators != null) {
                                    for (OrganizationalEntity administrator : administrators) {
                                        if (administrator instanceof User) {
                                            doCallbackUserOperation(administrator.getId(), context);
                                        }
                                        if (administrator instanceof Group) {
                                            doCallbackGroupOperation(administrator.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                        if (ressignments != null) {
                            for (Reassignment reassignment : ressignments) {
                                List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
                                if (potentialOwners != null) {
                                    for (OrganizationalEntity potentialOwner : potentialOwners) {
                                        if (potentialOwner instanceof User) {
                                            doCallbackUserOperation(potentialOwner.getId(), context);
                                        }
                                        if (potentialOwner instanceof Group) {
                                            doCallbackGroupOperation(potentialOwner.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (deadlines.getEndDeadlines() != null) {
            List<? extends Deadline> endDeadlines = deadlines.getEndDeadlines();
            for (Deadline endDeadline : endDeadlines) {
                List<? extends Escalation> escalations = endDeadline.getEscalations();
                if (escalations != null) {
                    for (Escalation escalation : escalations) {
                        List<? extends Notification> notifications = escalation.getNotifications();
                        List<? extends Reassignment> ressignments = escalation.getReassignments();
                        if (notifications != null) {
                            for (Notification notification : notifications) {
                                List<? extends OrganizationalEntity> recipients = notification.getRecipients();
                                if (recipients != null) {
                                    for (OrganizationalEntity recipient : recipients) {
                                        if (recipient instanceof User) {
                                            doCallbackUserOperation(recipient.getId(), context);
                                        }
                                        if (recipient instanceof Group) {
                                            doCallbackGroupOperation(recipient.getId(), context);
                                        }
                                    }
                                }
                                List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
                                if (administrators != null) {
                                    for (OrganizationalEntity administrator : administrators) {
                                        if (administrator instanceof User) {
                                            doCallbackUserOperation(administrator.getId(), context);
                                        }
                                        if (administrator instanceof Group) {
                                            doCallbackGroupOperation(administrator.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                        if (ressignments != null) {
                            for (Reassignment reassignment : ressignments) {
                                List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
                                if (potentialOwners != null) {
                                    for (OrganizationalEntity potentialOwner : potentialOwners) {
                                        if (potentialOwner instanceof User) {
                                            doCallbackUserOperation(potentialOwner.getId(), context);
                                        }
                                        if (potentialOwner instanceof Group) {
                                            doCallbackGroupOperation(potentialOwner.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Deadline(org.kie.internal.task.api.model.Deadline) Escalation(org.kie.internal.task.api.model.Escalation) Reassignment(org.kie.internal.task.api.model.Reassignment) Notification(org.kie.internal.task.api.model.Notification)

Example 25 with Group

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

the class UserGroupCallbackTaskCommand method addGroupFromCallbackOperation.

protected void addGroupFromCallbackOperation(String groupId, TaskContext context) {
    Group group = context.getPersistenceContext().findGroup(groupId);
    boolean groupExists = group != null;
    if (!StringUtils.isEmpty(groupId) && !groupExists) {
        group = TaskModelProvider.getFactory().newGroup();
        ((InternalOrganizationalEntity) group).setId(groupId);
        persistIfNotExists(group, context);
    }
}
Also used : Group(org.kie.api.task.model.Group) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Aggregations

Group (org.kie.api.task.model.Group)38 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)29 User (org.kie.api.task.model.User)27 ArrayList (java.util.ArrayList)17 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Task (org.kie.api.task.model.Task)11 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)9 Test (org.junit.Test)8 List (java.util.List)6 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)5 InternalTask (org.kie.internal.task.api.model.InternalTask)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 WorkItem (org.drools.core.process.instance.WorkItem)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 PeopleAssignments (org.kie.api.task.model.PeopleAssignments)4 Iterator (java.util.Iterator)3