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;
}
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());
}
}
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);
}
}
}
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");
}
}
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);
}
}
Aggregations