Search in sources :

Example 1 with NodeInstance

use of org.jbpm.workflow.instance.NodeInstance in project jbpm by kiegroup.

the class RuleFlowProcessInstance method internalStart.

public void internalStart(String trigger) {
    StartNode startNode = getRuleFlowProcess().getStart(trigger);
    if (startNode != null) {
        ((NodeInstance) getNodeInstance(startNode)).trigger(null, null);
    }
    // activate ad hoc fragments if they are marked as such
    List<Node> autoStartNodes = getRuleFlowProcess().getAutoStartNodes();
    autoStartNodes.forEach(austoStartNode -> signalEvent(austoStartNode.getName(), null));
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) Node(org.kie.api.definition.process.Node) StartNode(org.jbpm.workflow.core.node.StartNode) NodeInstance(org.jbpm.workflow.instance.NodeInstance)

Example 2 with NodeInstance

use of org.jbpm.workflow.instance.NodeInstance in project jbpm by kiegroup.

the class DefaultExceptionScopeInstance method handleException.

public void handleException(ExceptionHandler handler, String exception, Object params) {
    if (handler instanceof ActionExceptionHandler) {
        ActionExceptionHandler exceptionHandler = (ActionExceptionHandler) handler;
        Action action = (Action) exceptionHandler.getAction().getMetaData("Action");
        try {
            ProcessInstance processInstance = getProcessInstance();
            ProcessContext processContext = new ProcessContext(processInstance.getKnowledgeRuntime());
            ContextInstanceContainer contextInstanceContainer = getContextInstanceContainer();
            if (contextInstanceContainer instanceof NodeInstance) {
                processContext.setNodeInstance((NodeInstance) contextInstanceContainer);
            } else {
                processContext.setProcessInstance(processInstance);
            }
            String faultVariable = exceptionHandler.getFaultVariable();
            if (faultVariable != null) {
                processContext.setVariable(faultVariable, params);
            }
            action.execute(processContext);
        } catch (Exception e) {
            throw new RuntimeException("unable to execute Action", e);
        }
    } else {
        throw new IllegalArgumentException("Unknown exception handler " + handler);
    }
}
Also used : Action(org.jbpm.process.instance.impl.Action) ProcessInstance(org.jbpm.process.instance.ProcessInstance) ContextInstanceContainer(org.jbpm.process.instance.ContextInstanceContainer) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) NodeInstance(org.jbpm.workflow.instance.NodeInstance) ProcessContext(org.drools.core.spi.ProcessContext)

Example 3 with NodeInstance

use of org.jbpm.workflow.instance.NodeInstance in project jbpm by kiegroup.

the class CompositeNodeInstance method triggerCompleted.

public void triggerCompleted(String outType) {
    boolean cancelRemainingInstances = getCompositeNode().isCancelRemainingInstances();
    ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(getLevel());
    triggerCompleted(outType, cancelRemainingInstances);
    if (cancelRemainingInstances) {
        while (!nodeInstances.isEmpty()) {
            NodeInstance nodeInstance = (NodeInstance) nodeInstances.get(0);
            ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).cancel();
        }
    }
}
Also used : NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) NodeInstance(org.jbpm.workflow.instance.NodeInstance)

Example 4 with NodeInstance

use of org.jbpm.workflow.instance.NodeInstance in project jbpm by kiegroup.

the class CompositeNodeInstance method internalTrigger.

public void internalTrigger(final org.kie.api.runtime.process.NodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
        return;
    }
    CompositeNode.NodeAndType nodeAndType = getCompositeNode().internalGetLinkedIncomingNode(type);
    if (nodeAndType != null) {
        List<Connection> connections = nodeAndType.getNode().getIncomingConnections(nodeAndType.getType());
        for (Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) {
            Connection connection = iterator.next();
            if ((connection.getFrom() instanceof CompositeNode.CompositeNodeStart) && (from == null || ((CompositeNode.CompositeNodeStart) connection.getFrom()).getInNode().getId() == from.getNodeId())) {
                NodeInstance nodeInstance = getNodeInstance(connection.getFrom());
                ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, nodeAndType.getType());
                return;
            }
        }
    } else {
        // try to search for start nodes
        boolean found = false;
        for (Node node : getCompositeNode().getNodes()) {
            if (node instanceof StartNode) {
                StartNode startNode = (StartNode) node;
                if (startNode.getTriggers() == null || startNode.getTriggers().isEmpty()) {
                    NodeInstance nodeInstance = getNodeInstance(startNode);
                    ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, null);
                    found = true;
                }
            }
        }
        if (found) {
            return;
        }
    }
    if (isLinkedIncomingNodeRequired()) {
        throw new IllegalArgumentException("Could not find start for composite node: " + type);
    }
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) Connection(org.kie.api.definition.process.Connection) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) NodeInstance(org.jbpm.workflow.instance.NodeInstance)

Example 5 with NodeInstance

use of org.jbpm.workflow.instance.NodeInstance in project jbpm by kiegroup.

the class CompositeNodeInstance method cancel.

public void cancel() {
    while (!nodeInstances.isEmpty()) {
        NodeInstance nodeInstance = (NodeInstance) nodeInstances.get(0);
        ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).cancel();
    }
    super.cancel();
}
Also used : NodeInstance(org.jbpm.workflow.instance.NodeInstance)

Aggregations

NodeInstance (org.jbpm.workflow.instance.NodeInstance)14 CompositeNodeInstance (org.jbpm.workflow.instance.node.CompositeNodeInstance)6 EventNodeInstance (org.jbpm.workflow.instance.node.EventNodeInstance)6 EventSubProcessNodeInstance (org.jbpm.workflow.instance.node.EventSubProcessNodeInstance)6 Node (org.kie.api.definition.process.Node)6 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)4 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)4 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)4 EndNodeInstance (org.jbpm.workflow.instance.node.EndNodeInstance)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)3 AsyncEventNode (org.jbpm.workflow.core.node.AsyncEventNode)3 EndNode (org.jbpm.workflow.core.node.EndNode)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 StartNode (org.jbpm.workflow.core.node.StartNode)3 StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CompensationScope (org.jbpm.process.core.context.exception.CompensationScope)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)2