Search in sources :

Example 16 with Connection

use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.

the class CompositeNodeInstance method internalTrigger.

@Override
public void internalTrigger(final io.automatiko.engine.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 (Connection connection : connections) {
            if ((connection.getFrom() instanceof CompositeNode.CompositeNodeStart) && (from == null || ((CompositeNode.CompositeNodeStart) connection.getFrom()).getInNode().getId() == from.getNodeId())) {
                NodeInstance nodeInstance = getNodeInstance(connection.getFrom());
                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);
                    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(io.automatiko.engine.workflow.process.core.node.StartNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Connection(io.automatiko.engine.api.definition.process.Connection) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance)

Example 17 with Connection

use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.

the class StateNodeInstance method signalEvent.

public void signalEvent(String type, Object event) {
    if ("signal".equals(type)) {
        if (event instanceof String) {
            for (Connection connection : getStateNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
                boolean selected = false;
                Constraint constraint = getStateNode().getConstraint(connection);
                if (constraint == null) {
                    if (((String) event).equals(connection.getTo().getName())) {
                        selected = true;
                    }
                } else if (((String) event).equals(constraint.getName())) {
                    selected = true;
                }
                if (selected) {
                    triggerEvent(ExtendedNodeImpl.EVENT_NODE_EXIT);
                    removeEventListeners();
                    ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
                    triggerConnection(connection);
                    return;
                }
            }
        }
    } else if ("variableChanged".equals(type)) {
        if (isCompleted()) {
            triggerCompleted();
        }
    } else {
        super.signalEvent(type, event);
    }
}
Also used : Constraint(io.automatiko.engine.workflow.process.core.Constraint) Connection(io.automatiko.engine.api.definition.process.Connection)

Example 18 with Connection

use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method triggerNodeInstance.

protected void triggerNodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance nodeInstance, String type, boolean fireEvents) {
    if (nodeInstance == null) {
        return;
    }
    leaveTime = new Date();
    boolean hidden = false;
    if (getNode().getMetaData().get(HIDDEN) != null) {
        hidden = true;
    }
    InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
    if (!hidden && fireEvents) {
        runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
    }
    // trigger next node
    nodeInstance.trigger(this, type);
    Collection<Connection> outgoing = getNode().getOutgoingConnections(type);
    for (Connection conn : outgoing) {
        if (conn.getTo().getId() == nodeInstance.getNodeId()) {
            this.metaData.put(OUTGOING_CONNECTION, conn.getMetaData().get(UNIQUE_ID));
            break;
        }
    }
    if (!hidden && fireEvents) {
        runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
    }
}
Also used : Connection(io.automatiko.engine.api.definition.process.Connection) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Date(java.util.Date)

Example 19 with Connection

use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method retry.

public void retry() {
    boolean hidden = false;
    if (getNode().getMetaData().get(HIDDEN) != null) {
        hidden = true;
    }
    InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
    try {
        internalChangeState(NodeInstanceState.Active);
        internalTrigger(this, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
        Collection<Connection> outgoing = getNode().getOutgoingConnections(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
        for (Connection conn : outgoing) {
            if (conn.getTo().getId() == getNodeId()) {
                this.metaData.put(OUTGOING_CONNECTION, conn.getMetaData().get(UNIQUE_ID));
                break;
            }
        }
        if (!hidden) {
            runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
        }
    } catch (Exception e) {
        String errorId = captureError(e);
        internalChangeState(NodeInstanceState.Failed);
        runtime.getProcessEventSupport().fireAfterNodeInstanceFailed(getProcessInstance(), this, errorId, getRootException(e).getMessage(), e, runtime);
        // stop after capturing error
        return;
    }
}
Also used : Connection(io.automatiko.engine.api.definition.process.Connection) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)

Example 20 with Connection

use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method continueToNextNode.

protected void continueToNextNode(String type, Node node) {
    List<Connection> connections = null;
    if (node != null) {
        if ("true".equals(System.getProperty("jbpm.enable.multi.con")) && ((NodeImpl) node).getConstraints().size() > 0) {
            int priority;
            connections = ((NodeImpl) node).getDefaultOutgoingConnections();
            boolean found = false;
            List<NodeInstanceTrigger> nodeInstances = new ArrayList<>();
            List<Connection> outgoingCopy = new ArrayList<>(connections);
            while (!outgoingCopy.isEmpty()) {
                priority = Integer.MAX_VALUE;
                Connection selectedConnection = null;
                ConstraintEvaluator selectedConstraint = null;
                for (final Connection connection : outgoingCopy) {
                    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 (((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != STATE_ACTIVE) {
                    return;
                }
                triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
            }
            if (!found) {
                for (final Connection connection : connections) {
                    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;
        }
        InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
        if (!hidden) {
            runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
        }
        // notify container
        ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
        if (!hidden) {
            runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
        }
    } else {
        Map<io.automatiko.engine.workflow.process.instance.NodeInstance, String> nodeInstances = new HashMap<>();
        for (Connection connection : connections) {
            nodeInstances.put(followConnection(connection), connection.getToType());
        }
        for (Map.Entry<io.automatiko.engine.workflow.process.instance.NodeInstance, String> nodeInstance : nodeInstances.entrySet()) {
            // stop if this process instance has been aborted / completed
            int state = ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState();
            if (state == STATE_COMPLETED || state == STATE_ABORTED) {
                return;
            }
            try {
                triggerNodeInstance(nodeInstance.getKey(), nodeInstance.getValue());
            } catch (Exception e) {
                logger.warn("Error caught at executing node instance " + nodeInstance.getKey(), e);
            }
        }
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) HashMap(java.util.HashMap) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) ConstraintEvaluator(io.automatiko.engine.workflow.base.instance.impl.ConstraintEvaluator) Connection(io.automatiko.engine.api.definition.process.Connection) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ActionNodeInstance(io.automatiko.engine.workflow.process.instance.node.ActionNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Connection (io.automatiko.engine.api.definition.process.Connection)22 Node (io.automatiko.engine.api.definition.process.Node)12 ArrayList (java.util.ArrayList)11 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)5 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)5 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)5 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)5 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)5 List (java.util.List)5 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)4 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)4 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)4 Map (java.util.Map)4 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)3 NodeInstanceContainer (io.automatiko.engine.api.runtime.process.NodeInstanceContainer)3 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)3 Join (io.automatiko.engine.workflow.process.core.node.Join)3 Split (io.automatiko.engine.workflow.process.core.node.Split)3 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)3