Search in sources :

Example 26 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class WorkflowProcessInstanceImpl method nodeInstanceCompleted.

public void nodeInstanceCompleted(NodeInstance nodeInstance, String outType) {
    Node nodeInstanceNode = nodeInstance.getNode();
    if (nodeInstanceNode != null) {
        Object compensationBoolObj = nodeInstanceNode.getMetaData().get("isForCompensation");
        boolean isForCompensation = compensationBoolObj == null ? false : ((Boolean) compensationBoolObj);
        if (isForCompensation) {
            return;
        }
    }
    if (nodeInstance instanceof EndNodeInstance || ((org.jbpm.workflow.core.WorkflowProcess) getWorkflowProcess()).isDynamic() || nodeInstance instanceof CompositeNodeInstance) {
        if (((org.jbpm.workflow.core.WorkflowProcess) getProcess()).isAutoComplete()) {
            if (canComplete()) {
                setState(ProcessInstance.STATE_COMPLETED);
            }
        }
    } else {
        throw new IllegalArgumentException("Completing a node instance that has no outgoing connection is not supported.");
    }
}
Also used : CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) 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) EndNodeInstance(org.jbpm.workflow.instance.node.EndNodeInstance) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess)

Example 27 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class AsyncEventNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    super.internalTrigger(from, type);
    ExecutorService executorService = (ExecutorService) getProcessInstance().getKnowledgeRuntime().getEnvironment().get("ExecutorService");
    if (executorService != null) {
        RuntimeManager runtimeManager = ((RuntimeManager) getProcessInstance().getKnowledgeRuntime().getEnvironment().get("RuntimeManager"));
        CommandContext ctx = new CommandContext();
        ctx.setData("deploymentId", runtimeManager.getIdentifier());
        ctx.setData("processInstanceId", getProcessInstance().getId());
        ctx.setData("Signal", getEventType());
        ctx.setData("Event", null);
        executorService.scheduleRequest(AsyncSignalEventCommand.class.getName(), ctx);
        Node node = getNode();
        if (node != null) {
            String uniqueId = (String) node.getMetaData().get("UniqueId");
            if (uniqueId == null) {
                uniqueId = ((NodeImpl) node).getUniqueId();
            }
            ((WorkflowProcessInstanceImpl) getProcessInstance()).getIterationLevels().remove(getNode().getMetaData().get("UniqueId"));
        }
    } else {
        logger.warn("No async executor service found continuing as sync operation...");
        // if there is no executor service available move as sync node
        triggerCompleted();
    }
}
Also used : CommandContext(org.kie.api.executor.CommandContext) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) Node(org.kie.api.definition.process.Node) ExecutorService(org.kie.api.executor.ExecutorService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AsyncSignalEventCommand(org.jbpm.process.core.async.AsyncSignalEventCommand)

Example 28 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class CompensationEventListener method findNode.

private Node findNode(String nodeId) {
    Node found = null;
    Queue<Node> allProcessNodes = new LinkedList<Node>();
    allProcessNodes.addAll(Arrays.asList(instance.getNodeContainer().getNodes()));
    while (!allProcessNodes.isEmpty()) {
        Node node = allProcessNodes.poll();
        if (nodeId.equals(node.getMetaData().get("UniqueId"))) {
            found = node;
            break;
        }
        if (node instanceof NodeContainer) {
            allProcessNodes.addAll(Arrays.asList(((NodeContainer) node).getNodes()));
        }
    }
    return found;
}
Also used : Node(org.kie.api.definition.process.Node) NodeContainer(org.kie.api.definition.process.NodeContainer) LinkedList(java.util.LinkedList)

Example 29 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class NodeInstanceImpl method triggerCompleted.

protected void triggerCompleted(String type, boolean remove) {
    getExecutionErrorHandler().processed(this);
    Node node = getNode();
    if (node != null) {
        String uniqueId = (String) node.getMetaData().get("UniqueId");
        if (uniqueId == null) {
            uniqueId = ((NodeImpl) node).getUniqueId();
        }
        ((WorkflowProcessInstanceImpl) processInstance).addCompletedNodeId(uniqueId);
        ((WorkflowProcessInstanceImpl) processInstance).getIterationLevels().remove(uniqueId);
    }
    // if node instance was cancelled, or containing container instance was cancelled
    if ((getNodeInstanceContainer().getNodeInstance(getId()) == null) || (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE)) {
        return;
    }
    if (remove) {
        ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
    }
    List<Connection> connections = null;
    if (node != null) {
        if ("true".equals(System.getProperty("jbpm.enable.multi.con")) && ((NodeImpl) node).getConstraints().size() > 0) {
            int priority = Integer.MAX_VALUE;
            connections = ((NodeImpl) node).getDefaultOutgoingConnections();
            boolean found = false;
            List<NodeInstanceTrigger> nodeInstances = new ArrayList<NodeInstanceTrigger>();
            List<Connection> outgoingCopy = new ArrayList<Connection>(connections);
            while (!outgoingCopy.isEmpty()) {
                priority = Integer.MAX_VALUE;
                Connection selectedConnection = null;
                ConstraintEvaluator selectedConstraint = null;
                for (final Iterator<Connection> iterator = outgoingCopy.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
                    if (constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
                        priority = constraint.getPriority();
                        selectedConnection = connection;
                        selectedConstraint = constraint;
                    }
                }
                if (selectedConstraint == null) {
                    break;
                }
                if (selectedConstraint.evaluate(this, selectedConnection, selectedConstraint)) {
                    nodeInstances.add(new NodeInstanceTrigger(followConnection(selectedConnection), selectedConnection.getToType()));
                    found = true;
                }
                outgoingCopy.remove(selectedConnection);
            }
            for (NodeInstanceTrigger nodeInstance : nodeInstances) {
                // stop if this process instance has been aborted / completed
                if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
                    return;
                }
                triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
            }
            if (!found) {
                for (final Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
                    if (constraint.isDefault()) {
                        triggerConnection(connection);
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                throw new IllegalArgumentException("Uncontrolled flow node could not find at least one valid outgoing connection " + getNode().getName());
            }
            return;
        } else {
            connections = node.getOutgoingConnections(type);
        }
    }
    if (connections == null || connections.isEmpty()) {
        boolean hidden = false;
        Node currentNode = getNode();
        if (currentNode != null && currentNode.getMetaData().get("hidden") != null) {
            hidden = true;
        }
        InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
        if (!hidden) {
            ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
        }
        // notify container
        ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
        if (!hidden) {
            ((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
        }
    } else {
        Map<org.jbpm.workflow.instance.NodeInstance, String> nodeInstances = new HashMap<org.jbpm.workflow.instance.NodeInstance, String>();
        for (Connection connection : connections) {
            nodeInstances.put(followConnection(connection), connection.getToType());
        }
        for (Map.Entry<org.jbpm.workflow.instance.NodeInstance, String> nodeInstance : nodeInstances.entrySet()) {
            // stop if this process instance has been aborted / completed
            if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
                return;
            }
            triggerNodeInstance(nodeInstance.getKey(), nodeInstance.getValue());
        }
    }
}
Also used : NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) HashMap(java.util.HashMap) Node(org.kie.api.definition.process.Node) Connection(org.kie.api.definition.process.Connection) ArrayList(java.util.ArrayList) ConstraintEvaluator(org.jbpm.process.instance.impl.ConstraintEvaluator) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) NodeInstance(org.kie.api.runtime.process.NodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) ActionNodeInstance(org.jbpm.workflow.instance.node.ActionNodeInstance) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with Node

use of org.kie.api.definition.process.Node in project jbpm by kiegroup.

the class CompositeNode method addNode.

public void addNode(Node node) {
    // and delegate to GUI command that drops node
    if (node.getId() <= 0) {
        long id = 0;
        for (Node n : nodeContainer.getNodes()) {
            if (n.getId() > id) {
                id = n.getId();
            }
        }
        ((org.jbpm.workflow.core.Node) node).setId(++id);
    }
    nodeContainer.addNode(node);
    ((org.jbpm.workflow.core.Node) node).setNodeContainer(this);
}
Also used : Node(org.kie.api.definition.process.Node)

Aggregations

Node (org.kie.api.definition.process.Node)70 StartNode (org.jbpm.workflow.core.node.StartNode)27 EventNode (org.jbpm.workflow.core.node.EventNode)26 ActionNode (org.jbpm.workflow.core.node.ActionNode)25 EndNode (org.jbpm.workflow.core.node.EndNode)25 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)22 ArrayList (java.util.ArrayList)20 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)20 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)19 FaultNode (org.jbpm.workflow.core.node.FaultNode)17 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)17 StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)15 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)13 NodeContainer (org.kie.api.definition.process.NodeContainer)13 DynamicNode (org.jbpm.workflow.core.node.DynamicNode)11 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)11 StateNode (org.jbpm.workflow.core.node.StateNode)11 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)10 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)10 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)10