use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class CaseServiceImpl method addDynamicTask.
@Override
public void addDynamicTask(Long processInstanceId, TaskSpecification taskSpecification) throws ProcessInstanceNotFoundException {
ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
if (pi == null || !pi.getState().equals(ProcessInstance.STATE_ACTIVE)) {
throw new ProcessInstanceNotFoundException("No process instance found with id " + processInstanceId + " or it's not active anymore");
}
String caseId = pi.getCorrelationKey();
authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.ADD_TASK_TO_CASE);
processService.execute(pi.getDeploymentId(), ProcessInstanceIdContext.get(processInstanceId), new AddDynamicTaskCommand(identityProvider, caseId, taskSpecification.getNodeType(), pi.getId(), taskSpecification.getParameters()));
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class AddDynamicProcessCommand method execute.
@Override
public Long execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
if (processInstance == null) {
throw new ProcessInstanceNotFoundException("No process instance found with id " + processInstanceId);
}
try {
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
FactHandle factHandle = ksession.getFactHandle(caseFile);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters);
long subProcessInstanceId = DynamicUtils.addDynamicSubProcess(processInstance, ksession, processId, parameters);
ksession.update(factHandle, caseFile);
triggerRules(ksession);
caseEventSupport.fireAfterDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters, subProcessInstanceId);
return subProcessInstanceId;
} catch (IllegalArgumentException e) {
throw new ProcessDefinitionNotFoundException(e.getMessage());
}
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class AddDynamicProcessToStageCommand method execute.
@Override
public Long execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
if (processInstance == null) {
throw new ProcessInstanceNotFoundException("No process instance found with id " + processInstanceId);
}
DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances(true).stream().filter(ni -> (ni instanceof DynamicNodeInstance) && stageId.equals(ni.getNode().getMetaData().get("UniqueId"))).findFirst().orElse(null);
if (dynamicContext == null) {
throw new StageNotFoundException("No stage found with id " + stageId);
}
try {
CaseFileInstance caseFile = getCaseFile(ksession, caseId);
CaseEventSupport caseEventSupport = getCaseEventSupport(context);
caseEventSupport.fireBeforeDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters);
long subProcessInstanceId = DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, processId, parameters);
if (subProcessInstanceId < 0) {
throw new ProcessDefinitionNotFoundException("No process definition found with id: " + processId);
}
caseEventSupport.fireAfterDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters, subProcessInstanceId);
return subProcessInstanceId;
} catch (IllegalArgumentException e) {
throw new ProcessDefinitionNotFoundException(e.getMessage());
}
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImplWithDeploymentIdTest method testStartProcessAndAbortThenChangeVariables.
@Test
public void testStartProcessAndAbortThenChangeVariables() {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "test");
params.put("approval_reviewComment", "need review");
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
processService.abortProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
ProcessInstance pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
assertNull(pi);
try {
processService.getProcessInstanceVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment");
fail("Process instance was aborted so variables do not exist");
} catch (ProcessInstanceNotFoundException e) {
// expected
}
try {
processService.getProcessInstanceVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment");
fail("Process instance was aborted so variables do not exist");
} catch (ProcessInstanceNotFoundException e) {
// expected
}
params = new HashMap<String, Object>();
params.put("approval_document", "updated document");
params.put("approval_reviewComment", "final review");
try {
processService.setProcessVariables(deploymentUnit.getIdentifier(), processInstanceId, params);
fail("Process instance was aborted so cannot be changed");
} catch (ProcessInstanceNotFoundException e) {
// expected
}
try {
processService.setProcessVariable(deploymentUnit.getIdentifier(), processInstanceId, "approval_reviewComment", "updated review comment");
fail("Process instance was aborted so cannot be changed");
} catch (ProcessInstanceNotFoundException e) {
// expected
}
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class ProcessServiceWithServiceRegistryTest method testRunScriptProcessWithServiceRegistryInScriptTask.
@Test
public void testRunScriptProcessWithServiceRegistryInScriptTask() {
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), PROCESS_ID_SCRIPT_TASK);
assertNotNull(processInstanceId);
try {
ProcessInstance pi = processService.getProcessInstance(processInstanceId);
if (pi != null) {
fail("Process should be already completed");
}
} catch (ProcessInstanceNotFoundException e) {
// expected
}
Collection<VariableDesc> variables = runtimeDataService.getVariableHistory(processInstanceId, "correlationKey", new QueryContext());
assertNotNull(variables);
assertEquals(1, variables.size());
VariableDesc ckVar = variables.iterator().next();
assertNotNull(ckVar);
assertEquals("1", ckVar.getNewValue());
}
Aggregations