use of org.jbpm.casemgmt.api.CaseService in project jbpm by kiegroup.
the class StartCaseWorkItemHandler method abortWorkItem.
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
String caseId = (String) workItem.getParameter(CASE_ID);
boolean destroy = true;
if (workItem.getParameter(DESTROY_ON_ABORT) != null) {
destroy = Boolean.parseBoolean((String) workItem.getParameter(DESTROY_ON_ABORT));
}
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
try {
if (destroy) {
logger.debug("Case {} is going to be destroyed", caseId);
caseService.destroyCase(caseId);
} else {
logger.debug("Case {} is going to be canceled", caseId);
caseService.cancelCase(caseId);
}
} catch (CaseNotFoundException e) {
logger.warn("Case instance {} was not found", caseId);
} catch (Exception e) {
logger.error("Unexpected error during canceling case instance {}", caseId, e);
}
}
use of org.jbpm.casemgmt.api.CaseService in project jbpm by kiegroup.
the class StartProcessSLAViolationListener 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)) {
logger.debug("Case instance {} has SLA violation, escalating starting new process instance for {}", caseId, processId);
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
Long slaViolationProcessInstanceId = caseService.addDynamicSubprocess(caseId, processId, null);
logger.debug("Process instance with id {} was created to handle SLA violation for case {}", slaViolationProcessInstanceId, caseId);
}
}
}
use of org.jbpm.casemgmt.api.CaseService in project jbpm by kiegroup.
the class AsyncCloseCaseCommand method execute.
@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
String caseId = (String) ((WorkItem) ctx.getData("workItem")).getParameter("CaseId");
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
caseService.closeCase(caseId, "Closing case from async command");
return new ExecutionResults();
}
use of org.jbpm.casemgmt.api.CaseService 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);
}
}
}
}
use of org.jbpm.casemgmt.api.CaseService in project jbpm by kiegroup.
the class StartCaseWorkItemHandler method executeWorkItem.
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
String deploymentId = (String) workItem.getParameter(DEPLOYMENT_ID);
if (deploymentId == null) {
deploymentId = ((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId();
}
RuntimeManager targetRuntimeManager = RuntimeManagerRegistry.get().getManager(deploymentId);
if (targetRuntimeManager == null || !(targetRuntimeManager instanceof PerCaseRuntimeManager)) {
throw new IllegalArgumentException("Requested target deployment does not exist or is not per case strategy");
}
String caseDefinitionId = (String) workItem.getParameter(CASE_DEFINITION_ID);
if (caseDefinitionId == null || caseDefinitionId.trim().isEmpty()) {
throw new IllegalArgumentException(CASE_DEFINITION_ID + " is a required parameter for StartCaseWorkItemHandler");
}
Map<String, Object> caseFileData = new HashMap<>();
Map<String, List<String>> accessRestrictions = new HashMap<>();
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
parseParameters(workItem, caseFileData, roleAssignments, accessRestrictions);
long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
long workItemId = workItem.getId();
logger.debug("Parent process instance id {} and work item instance id {} for new case instance", processInstanceId, workItemId);
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
CaseFileInstance subCaseFile = caseService.newCaseFileInstanceWithRestrictions(deploymentId, caseDefinitionId, caseFileData, roleAssignments, accessRestrictions);
((CaseFileInstanceImpl) subCaseFile).setParentInstanceId(processInstanceId);
((CaseFileInstanceImpl) subCaseFile).setParentWorkItemId(workItemId);
String caseId = caseService.startCase(deploymentId, caseDefinitionId, subCaseFile);
logger.debug("Case with id {} has been successfully started");
boolean independent = Boolean.parseBoolean((String) workItem.getParameter(INDEPENDENT));
if (independent) {
Map<String, Object> results = new HashMap<>();
results.put(CASE_ID, caseId);
try {
CaseFileInstance snapshot = caseService.getCaseFileInstance(caseId);
results.putAll(snapshot.getData());
} catch (CaseNotFoundException e) {
// case is already completed
logger.debug("Case is already completed, not possible to fetch case file data any more");
}
logger.debug("Completing directly (without waiting for case instance {} completion) work item with id {}", caseId, workItem.getId());
((CaseFileInstanceImpl) subCaseFile).setParentInstanceId(null);
((CaseFileInstanceImpl) subCaseFile).setParentWorkItemId(null);
manager.completeWorkItem(workItem.getId(), results);
} else {
// save case id so the abort work item can abort/destroy the case instance
((WorkItemImpl) workItem).setParameter(CASE_ID, caseId);
logger.debug("Waiting for case instance {} completion before completing work item with id {}", caseId, workItem.getId());
}
}
Aggregations