Search in sources :

Example 6 with Connection

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

the class CompositeNode method removeIncomingConnection.

public void removeIncomingConnection(String type, Connection connection) {
    super.removeIncomingConnection(type, connection);
    CompositeNode.NodeAndType nodeAndType = internalGetLinkedIncomingNode(type);
    if (nodeAndType != null) {
        for (Connection inConnection : nodeAndType.getNode().getIncomingConnections(nodeAndType.getType())) {
            if (((CompositeNodeStart) inConnection.getFrom()).getInNodeId() == connection.getFrom().getId()) {
                Node compositeNodeStart = inConnection.getFrom();
                ((ConnectionImpl) inConnection).terminate();
                internalRemoveNode(compositeNodeStart);
                return;
            }
        }
        throw new IllegalArgumentException("Could not find internal incoming 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 7 with Connection

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

the class XmlBPMNProcessDumper method visitConnectionsDi.

private void visitConnectionsDi(Node[] nodes, StringBuilder xmlDump) {
    List<Connection> connections = new ArrayList<Connection>();
    for (Node node : nodes) {
        for (List<Connection> connectionList : node.getIncomingConnections().values()) {
            connections.addAll(connectionList);
        }
        if (node instanceof CompositeNode) {
            visitConnectionsDi(((CompositeNode) node).getNodes(), xmlDump);
        }
    }
    for (Connection connection : connections) {
        String bendpoints = (String) connection.getMetaData().get("bendpoints");
        xmlDump.append("      <bpmndi:BPMNEdge bpmnElement=\"" + getUniqueNodeId(connection.getFrom()) + "-" + getUniqueNodeId(connection.getTo()) + "\" >" + EOL);
        Integer x = (Integer) connection.getFrom().getMetaData().get("x");
        if (x == null) {
            x = 0;
        }
        Integer y = (Integer) connection.getFrom().getMetaData().get("y");
        if (y == null) {
            y = 0;
        }
        Integer width = (Integer) connection.getFrom().getMetaData().get("width");
        if (width == null) {
            width = 40;
        }
        Integer height = (Integer) connection.getFrom().getMetaData().get("height");
        if (height == null) {
            height = 40;
        }
        xmlDump.append("        <di:waypoint x=\"" + (x + width / 2) + "\" y=\"" + (y + height / 2) + "\" />" + EOL);
        if (bendpoints != null) {
            bendpoints = bendpoints.substring(1, bendpoints.length() - 1);
            String[] points = bendpoints.split(";");
            for (String point : points) {
                String[] coords = point.split(",");
                if (coords.length == 2) {
                    xmlDump.append("        <di:waypoint x=\"" + coords[0] + "\" y=\"" + coords[1] + "\" />" + EOL);
                }
            }
        }
        x = (Integer) connection.getTo().getMetaData().get("x");
        if (x == null) {
            x = 0;
        }
        y = (Integer) connection.getTo().getMetaData().get("y");
        if (y == null) {
            y = 0;
        }
        width = (Integer) connection.getTo().getMetaData().get("width");
        if (width == null) {
            width = 40;
        }
        height = (Integer) connection.getTo().getMetaData().get("height");
        if (height == null) {
            height = 40;
        }
        xmlDump.append("        <di:waypoint x=\"" + (x + width / 2) + "\" y=\"" + (y + height / 2) + "\" />" + EOL);
        xmlDump.append("      </bpmndi:BPMNEdge>" + EOL);
    }
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) 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) ArrayList(java.util.ArrayList)

Example 8 with Connection

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

the class XmlBPMNProcessDumper method visitConnections.

private void visitConnections(Node[] nodes, StringBuilder xmlDump, int metaDataType) {
    xmlDump.append("    <!-- connections -->" + EOL);
    List<Connection> connections = new ArrayList<Connection>();
    for (Node node : nodes) {
        for (List<Connection> connectionList : node.getIncomingConnections().values()) {
            connections.addAll(connectionList);
        }
    }
    for (Connection connection : connections) {
        visitConnection(connection, xmlDump, metaDataType);
    }
    xmlDump.append(EOL);
}
Also used : ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) 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) ArrayList(java.util.ArrayList)

Example 9 with Connection

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

the class BPMNPlaneHandler method processConnectionInfo.

private boolean processConnectionInfo(ConnectionInfo connectionInfo, Node[] nodes) {
    for (Node node : nodes) {
        for (List<Connection> connections : node.getOutgoingConnections().values()) {
            for (Connection connection : connections) {
                String id = (String) connection.getMetaData().get("UniqueId");
                if (id != null && id.equals(connectionInfo.getElementRef())) {
                    ((ConnectionImpl) connection).setMetaData("bendpoints", connectionInfo.getBendpoints());
                    ((ConnectionImpl) connection).setMetaData("x", connectionInfo.getXs());
                    ((ConnectionImpl) connection).setMetaData("y", connectionInfo.getYs());
                    return true;
                }
            }
        }
        if (node instanceof NodeContainer) {
            boolean found = processConnectionInfo(connectionInfo, ((NodeContainer) node).getNodes());
            if (found) {
                return true;
            }
        }
    }
    return false;
}
Also used : ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) 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) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer)

Example 10 with Connection

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

the class SplitInstance method executeStrategy.

protected void executeStrategy(Split split, String type) {
    // TODO make different strategies for each type
    String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
    if (uniqueId == null) {
        uniqueId = ((NodeImpl) getNode()).getUniqueId();
    }
    switch(split.getType()) {
        case Split.TYPE_AND:
            triggerCompleted(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, true);
            break;
        case Split.TYPE_XOR:
            List<Connection> outgoing = split.getDefaultOutgoingConnections();
            int priority = Integer.MAX_VALUE;
            Connection selected = null;
            for (final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
                final Connection connection = (Connection) iterator.next();
                ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint(connection);
                if (constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
                    try {
                        if (constraint.evaluate(this, connection, constraint)) {
                            selected = connection;
                            priority = constraint.getPriority();
                        }
                    } catch (RuntimeException e) {
                        throw new RuntimeException("Exception when trying to evaluate constraint " + constraint.getName() + " in split " + split.getName(), e);
                    }
                }
            }
            ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
            if (selected == null) {
                for (final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    if (split.isDefault(connection)) {
                        selected = connection;
                        break;
                    }
                }
            }
            if (selected == null) {
                throw new IllegalArgumentException("XOR split could not find at least one valid outgoing connection for split " + getSplit().getName());
            }
            if (!hasLoop(selected.getTo(), split)) {
                setLevel(1);
                ((NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(1);
            }
            triggerConnection(selected);
            ((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
            break;
        case Split.TYPE_OR:
            ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
            outgoing = split.getDefaultOutgoingConnections();
            boolean found = false;
            List<NodeInstanceTrigger> nodeInstances = new ArrayList<NodeInstanceTrigger>();
            List<Connection> outgoingCopy = new ArrayList<Connection>(outgoing);
            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) split.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 (getProcessInstance().getState() == STATE_COMPLETED || getProcessInstance().getState() == STATE_ABORTED) {
                    return;
                }
                triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
            }
            if (!found) {
                for (final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint(connection);
                    if (constraint != null && constraint.isDefault() || split.isDefault(connection)) {
                        triggerConnection(connection);
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                throw new IllegalArgumentException("OR split could not find at least one valid outgoing connection for split " + getSplit().getName());
            }
            ((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
            break;
        case Split.TYPE_XAND:
            ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
            Node node = getNode();
            List<Connection> connections = null;
            if (node != null) {
                connections = node.getOutgoingConnections(type);
            }
            if (connections == null || connections.isEmpty()) {
                ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
            } else {
                ExclusiveGroupInstance groupInstance = new ExclusiveGroupInstance();
                io.automatiko.engine.api.runtime.process.NodeInstanceContainer parent = getNodeInstanceContainer();
                if (parent instanceof ContextInstanceContainer) {
                    ((ContextInstanceContainer) parent).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, groupInstance);
                } else {
                    throw new IllegalArgumentException("An Exclusive AND is only possible if the parent is a context instance container");
                }
                Map<io.automatiko.engine.workflow.process.instance.NodeInstance, String> nodeInstancesMap = new HashMap<io.automatiko.engine.workflow.process.instance.NodeInstance, String>();
                for (Connection connection : connections) {
                    nodeInstancesMap.put(followConnection(connection), connection.getToType());
                }
                for (NodeInstance nodeInstance : nodeInstancesMap.keySet()) {
                    groupInstance.addNodeInstance(nodeInstance);
                }
                for (Map.Entry<io.automatiko.engine.workflow.process.instance.NodeInstance, String> entry : nodeInstancesMap.entrySet()) {
                    // stop if this process instance has been aborted / completed
                    if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
                        return;
                    }
                    boolean hidden = false;
                    if (getNode().getMetaData().get("hidden") != null) {
                        hidden = true;
                    }
                    InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
                    if (!hidden) {
                        runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
                    }
                    ((io.automatiko.engine.workflow.process.instance.NodeInstance) entry.getKey()).trigger(this, entry.getValue());
                    if (!hidden) {
                        runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
                    }
                }
            }
            ((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
            break;
        default:
            throw new IllegalArgumentException("Illegal split type " + split.getType());
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) HashMap(java.util.HashMap) Node(io.automatiko.engine.api.definition.process.Node) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) ConstraintEvaluator(io.automatiko.engine.workflow.base.instance.impl.ConstraintEvaluator) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) Connection(io.automatiko.engine.api.definition.process.Connection) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) 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