use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class TriggerNodeCommand method execute.
public Void execute(Context context) {
KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
logger.debug("About to trigger (create) node instance for node {} in process instance {}", nodeId, processInstanceId);
RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, false);
if (wfp == null) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
}
Node node = wfp.getRuleFlowProcess().getNodesRecursively().stream().filter(ni -> ni.getId() == nodeId).findFirst().orElse(null);
if (node == null) {
throw new NodeNotFoundException("Node instance with id " + nodeId + " not found");
}
logger.debug("Triggering node {} on process instance {}", node, wfp);
wfp.getNodeInstance(node).trigger(null, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
logger.debug("Node {} successfully triggered", node);
return null;
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImpl method abortProcessInstance.
@Override
public void abortProcessInstance(Long processInstanceId) {
ProcessInstanceDesc piDesc = dataService.getProcessInstanceById(processInstanceId);
if (piDesc == null || piDesc.getState() != ProcessInstance.STATE_ACTIVE) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found");
}
abortProcessInstance(piDesc.getDeploymentId(), processInstanceId);
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImpl method setProcessVariables.
@Override
public void setProcessVariables(Long processInstanceId, Map<String, Object> variables) {
ProcessInstanceDesc piDesc = dataService.getProcessInstanceById(processInstanceId);
if (piDesc == null || piDesc.getState() != ProcessInstance.STATE_ACTIVE) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found");
}
setProcessVariables(piDesc.getDeploymentId(), processInstanceId, variables);
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImpl method completeWorkItem.
@Override
public void completeWorkItem(String deploymentId, Long processInstanceId, Long id, Map<String, Object> results) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
results = process(results, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
if (workItem == null) {
throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
}
ksession.getWorkItemManager().completeWorkItem(id, results);
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.jbpm.services.api.ProcessInstanceNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImpl method getAvailableSignals.
@Override
public Collection<String> getAvailableSignals(String deploymentId, Long processInstanceId) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
Collection<String> activeSignals = new ArrayList<>();
if (processInstance != null) {
((ProcessInstanceImpl) processInstance).setProcess(ksession.getKieBase().getProcess(processInstance.getProcessId()));
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
Collection<String> activeBoundaryNodesSignals = getActiveBoundaryNodesSignals(processInstance, activeNodes);
activeSignals.addAll(collectActiveSignals(activeNodes));
activeSignals.addAll(activeBoundaryNodesSignals);
}
return activeSignals;
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
Aggregations