Search in sources :

Example 21 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.

the class ListTimersCommand method execute.

public List<TimerInstance> execute(Context context) {
    List<TimerInstance> timers = new ArrayList<TimerInstance>();
    KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
    TimerManager tm = getTimerManager(kieSession);
    RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, true);
    if (wfp == null) {
        throw new ProcessInstanceNotFoundException("No process instance can be found for id " + processInstanceId);
    }
    processNodeInstance(tm, wfp, timers);
    return timers;
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) TimerInstance(org.jbpm.services.api.admin.TimerInstance) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) TimerManager(org.jbpm.process.instance.timer.TimerManager) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 22 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance 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)

Example 23 with RuleFlowProcessInstance

use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance 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)

Aggregations

RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)23 KieSession (org.kie.api.runtime.KieSession)14 Test (org.junit.Test)12 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 RegistryContext (org.drools.core.command.impl.RegistryContext)6 KieBase (org.kie.api.KieBase)6 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)5 StringReader (java.io.StringReader)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 WorkflowProcessImpl (org.jbpm.workflow.core.impl.WorkflowProcessImpl)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)3 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)3 ReturnValueDescr (org.drools.compiler.compiler.ReturnValueDescr)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)3 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)3 ReturnValueConstraintEvaluator (org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator)3 TimerManager (org.jbpm.process.instance.timer.TimerManager)3 ArrayList (java.util.ArrayList)2 ProcessDescr (org.drools.compiler.lang.descr.ProcessDescr)2