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);
}
}
}
}
Aggregations