Search in sources :

Example 11 with Connection

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

the class JoinInstance method checkNodes.

private boolean checkNodes(Set<Long> vistedNodes, Node startAt, Node currentNode, Node lookFor) {
    if (currentNode == null) {
        // for dynamic/ad hoc task there is no node
        return false;
    }
    List<Connection> connections = currentNode.getOutgoingConnections(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
    // special handling for XOR split as it usually is used for arbitrary loops
    if (currentNode instanceof Split && ((Split) currentNode).getType() == Split.TYPE_XOR) {
        if (vistedNodes.contains(startAt.getId())) {
            return false;
        }
        for (Connection conn : connections) {
            Set<Long> xorCopy = new HashSet<Long>(vistedNodes);
            Node nextNode = conn.getTo();
            if (nextNode == null) {
                continue;
            } else {
                xorCopy.add(nextNode.getId());
                if (nextNode.getId() != lookFor.getId()) {
                    checkNodes(xorCopy, currentNode, nextNode, lookFor);
                }
            }
            if (xorCopy.contains(lookFor.getId())) {
                vistedNodes.addAll(xorCopy);
                return true;
            }
        }
    } else {
        for (Connection conn : connections) {
            Node nextNode = conn.getTo();
            if (nextNode == null) {
                continue;
            } else {
                if (vistedNodes.contains(nextNode.getId())) {
                    // we have already been here so let's continue
                    continue;
                }
                if (nextNode.getId() == lookFor.getId()) {
                    // we found the node that we are looking for, add it and continue to find out
                    // other parts
                    // as it could be part of a loop
                    vistedNodes.add(nextNode.getId());
                    continue;
                }
                vistedNodes.add(nextNode.getId());
                if (startAt.getId() == nextNode.getId()) {
                    return true;
                } else {
                    boolean nestedCheck = checkNodes(vistedNodes, startAt, nextNode, lookFor);
                    if (nestedCheck) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Node(io.automatiko.engine.api.definition.process.Node) Connection(io.automatiko.engine.api.definition.process.Connection) Split(io.automatiko.engine.workflow.process.core.node.Split) HashSet(java.util.HashSet)

Example 12 with Connection

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

the class JoinInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("An ActionNode only accepts default incoming connections!");
    }
    triggerTime = new Date();
    final Join join = getJoin();
    switch(join.getType()) {
        case Join.TYPE_XOR:
            triggerCompleted();
            break;
        case Join.TYPE_AND:
            Integer count = (Integer) this.triggers.get(from.getNodeId());
            if (count == null) {
                this.triggers.put(from.getNodeId(), 1);
            } else {
                this.triggers.put(from.getNodeId(), count.intValue() + 1);
            }
            if (checkAllActivated()) {
                decreaseAllTriggers();
                triggerCompleted();
            }
            break;
        case Join.TYPE_DISCRIMINATOR:
            boolean triggerCompleted = triggers.isEmpty();
            triggers.put(from.getNodeId(), new Integer(1));
            if (checkAllActivated()) {
                resetAllTriggers();
            }
            if (triggerCompleted) {
                triggerCompleted();
            }
            break;
        case Join.TYPE_N_OF_M:
            count = (Integer) this.triggers.get(from.getNodeId());
            if (count == null) {
                this.triggers.put(from.getNodeId(), 1);
            } else {
                this.triggers.put(from.getNodeId(), count.intValue() + 1);
            }
            int counter = 0;
            for (final Connection connection : getJoin().getDefaultIncomingConnections()) {
                if (this.triggers.get(connection.getFrom().getId()) != null) {
                    counter++;
                }
            }
            String n = join.getN();
            Integer number = null;
            if (n.startsWith("#{") && n.endsWith("}")) {
                n = n.substring(2, n.length() - 1);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, n);
                if (variableScopeInstance == null) {
                    throw new IllegalArgumentException("Could not find variable " + n + " when executing join.");
                }
                Object value = variableScopeInstance.getVariable(n);
                if (value instanceof Number) {
                    number = ((Number) value).intValue();
                } else {
                    throw new IllegalArgumentException("Variable " + n + " did not return a number when executing join: " + value);
                }
            } else {
                number = Integer.parseInt(n);
            }
            if (counter >= number) {
                resetAllTriggers();
                NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
                cancelRemainingDirectFlows(nodeInstanceContainer, getJoin());
                triggerCompleted();
            }
            break;
        case Join.TYPE_OR:
            NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
            boolean activePathExists = existsActiveDirectFlow(nodeInstanceContainer, getJoin());
            if (!activePathExists) {
                triggerCompleted();
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal join type " + join.getType());
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) Connection(io.automatiko.engine.api.definition.process.Connection) Join(io.automatiko.engine.workflow.process.core.node.Join) Date(java.util.Date)

Example 13 with Connection

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

the class AbstractCompositeNodeHandler method visitConnectionsAndAssociations.

protected void visitConnectionsAndAssociations(Node node, StringBuilder xmlDump, int metaDataType) {
    // add associations
    List<Connection> connections = getSubConnections((CompositeNode) node);
    xmlDump.append("    <!-- connections -->" + EOL);
    for (Connection connection : connections) {
        XmlBPMNProcessDumper.INSTANCE.visitConnection(connection, xmlDump, metaDataType);
    }
    // add associations
    List<Association> associations = (List<Association>) node.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            XmlBPMNProcessDumper.INSTANCE.visitAssociation(association, xmlDump);
        }
    }
}
Also used : Association(io.automatiko.engine.workflow.bpmn2.core.Association) Connection(io.automatiko.engine.api.definition.process.Connection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 14 with Connection

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

the class CompositeNode method removeOutgoingConnection.

public void removeOutgoingConnection(String type, Connection connection) {
    super.removeOutgoingConnection(type, connection);
    CompositeNode.NodeAndType nodeAndType = internalGetLinkedOutgoingNode(type);
    if (nodeAndType != null) {
        for (Connection outConnection : nodeAndType.getNode().getOutgoingConnections(nodeAndType.getType())) {
            if (((CompositeNodeEnd) outConnection.getTo()).getOutNodeId() == connection.getTo().getId()) {
                Node compositeNodeEnd = outConnection.getTo();
                ((ConnectionImpl) outConnection).terminate();
                internalRemoveNode(compositeNodeEnd);
                return;
            }
        }
        throw new IllegalArgumentException("Could not find internal outgoing connection for node");
    }
}
Also used : Node(io.automatiko.engine.api.definition.process.Node) Connection(io.automatiko.engine.api.definition.process.Connection) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)

Example 15 with Connection

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

the class ServerlessWorkflowFactory method collectConnectedNodes.

public void collectConnectedNodes(Node start, NodeContainer container, List<Long> nodeIds) {
    List<Connection> outgoingConnections = start.getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE);
    if (outgoingConnections.isEmpty()) {
        return;
    }
    for (Connection conn : outgoingConnections) {
        nodeIds.add(conn.getTo().getId());
        collectConnectedNodes(conn.getTo(), container, nodeIds);
    }
}
Also used : Connection(io.automatiko.engine.api.definition.process.Connection)

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