Search in sources :

Example 1 with NodeInstanceNotFoundException

use of org.jbpm.services.api.NodeInstanceNotFoundException in project jbpm by kiegroup.

the class CancelNodeInstanceCommand method execute.

public Void execute(Context context) {
    logger.debug("About to cancel node instance with id {} on process instance {}", nodeInstanceId, processInstanceId);
    KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
    RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, false);
    if (wfp == null) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
    }
    NodeInstance nodeInstance = wfp.getNodeInstances(true).stream().filter(ni -> ni.getId() == nodeInstanceId).findFirst().orElse(null);
    if (nodeInstance == null) {
        throw new NodeInstanceNotFoundException("Node instance with id " + nodeInstanceId + " not found");
    }
    logger.debug("Found node instance {} to be canceled", nodeInstance);
    ((NodeInstanceImpl) nodeInstance).cancel();
    logger.debug("Node instance {} canceled successfully", nodeInstance);
    return null;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) NodeInstanceNotFoundException(org.jbpm.services.api.NodeInstanceNotFoundException) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 2 with NodeInstanceNotFoundException

use of org.jbpm.services.api.NodeInstanceNotFoundException in project jbpm by kiegroup.

the class RetriggerNodeInstanceCommand method execute.

public Void execute(Context context) {
    KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
    logger.debug("About to retrigger node instance with id {} on process instance {}", nodeInstanceId, processInstanceId);
    RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, false);
    if (wfp == null) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
    }
    NodeInstance nodeInstance = wfp.getNodeInstances(true).stream().filter(ni -> ni.getId() == nodeInstanceId).findFirst().orElse(null);
    if (nodeInstance == null) {
        throw new NodeInstanceNotFoundException("Node instance with id " + nodeInstanceId + " not found");
    }
    logger.debug("Found node instance {} to be retriggered", nodeInstance);
    ((NodeInstanceImpl) nodeInstance).retrigger(true);
    logger.debug("Node instance {} retriggered successfully", nodeInstance);
    return null;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) NodeInstanceNotFoundException(org.jbpm.services.api.NodeInstanceNotFoundException) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Aggregations

RegistryContext (org.drools.core.command.impl.RegistryContext)2 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)2 NodeInstanceNotFoundException (org.jbpm.services.api.NodeInstanceNotFoundException)2 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)2 NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)2 KieSession (org.kie.api.runtime.KieSession)2 NodeInstance (org.kie.api.runtime.process.NodeInstance)2