Search in sources :

Example 6 with CaseService

use of org.jbpm.casemgmt.api.CaseService 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)

Aggregations

CaseService (org.jbpm.casemgmt.api.CaseService)6 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)4 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)3 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 ClassObjectFilter (org.drools.core.ClassObjectFilter)2 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)2 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)2 ServiceRegistry (org.jbpm.services.api.service.ServiceRegistry)2 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)2 SLAViolatedEvent (org.kie.api.event.process.SLAViolatedEvent)2 KieSession (org.kie.api.runtime.KieSession)2 CaseAssignment (org.kie.api.runtime.process.CaseAssignment)2 Cacheable (org.kie.internal.runtime.Cacheable)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1