Search in sources :

Example 51 with ProcessInstanceNotFoundException

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;
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) NodeNotFoundException(org.jbpm.services.api.NodeNotFoundException) Node(org.kie.api.definition.process.Node) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 52 with ProcessInstanceNotFoundException

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);
}
Also used : ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 53 with ProcessInstanceNotFoundException

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);
}
Also used : ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 54 with ProcessInstanceNotFoundException

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);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 55 with ProcessInstanceNotFoundException

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);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ArrayList(java.util.ArrayList) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) KieSession(org.kie.api.runtime.KieSession) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Aggregations

ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)56 KieSession (org.kie.api.runtime.KieSession)21 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)16 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)16 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)13 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)13 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)13 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)13 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)13 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)13 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)10 After (org.junit.After)10 RegistryContext (org.drools.core.command.impl.RegistryContext)8 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)7 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)4 WorkItem (org.kie.api.runtime.process.WorkItem)4 ArrayList (java.util.ArrayList)3