use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.
the class AssociationHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
Association association = new Association();
association.setId(attrs.getValue("id"));
association.setSourceRef(attrs.getValue("sourceRef"));
association.setTargetRef(attrs.getValue("targetRef"));
String direction = attrs.getValue("associationDirection");
if (direction != null) {
boolean acceptableDirection = false;
direction = direction.toLowerCase();
String[] possibleDirections = { "none", "one", "both" };
for (String acceptable : possibleDirections) {
if (acceptable.equals(direction)) {
acceptableDirection = true;
break;
}
}
if (!acceptableDirection) {
throw new IllegalArgumentException("Unknown direction '" + direction + "' used in Association " + association.getId());
}
}
association.setDirection(direction);
/**
* BPMN2 spec, p. 66: "At this point, BPMN provides three standard Artifacts:
* Associations, Groups, and Text Annotations. ... When an Artifact is defined
* it is contained within a Collaboration or a FlowElementsContainer (a Process
* or Choreography)."
*
* (In other words: associations must be defined within a process, not outside)
*/
List<Association> associations = null;
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
if (nodeContainer instanceof Process) {
ExecutableProcess process = (ExecutableProcess) nodeContainer;
associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
if (associations == null) {
associations = new ArrayList<>();
process.setMetaData(ASSOCIATIONS, associations);
}
} else if (nodeContainer instanceof CompositeNode) {
CompositeContextNode compositeNode = (CompositeContextNode) nodeContainer;
associations = (List<Association>) compositeNode.getMetaData(ASSOCIATIONS);
if (associations == null) {
associations = new ArrayList<>();
compositeNode.setMetaData(ProcessHandler.ASSOCIATIONS, associations);
}
} else {
associations = new ArrayList<>();
}
associations.add(association);
return association;
}
use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.
the class BoundaryEventHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
Node node = (Node) parser.getCurrent();
String attachedTo = element.getAttribute("attachedToRef");
Attr cancelActivityAttr = element.getAttributeNode("cancelActivity");
boolean cancelActivity = true;
if (cancelActivityAttr != null) {
cancelActivity = Boolean.parseBoolean(cancelActivityAttr.getValue());
}
// determine type of event definition, so the correct type of node can be
// generated
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("escalationEventDefinition".equals(nodeName)) {
// reuse already created EventNode
handleEscalationNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
node.setMetaData(EVENT_TYPE, "escalation");
break;
} else if ("errorEventDefinition".equals(nodeName)) {
// reuse already created EventNode
handleErrorNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
node.setMetaData(EVENT_TYPE, "error");
break;
} else if ("timerEventDefinition".equals(nodeName)) {
// reuse already created EventNode
handleTimerNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
node.setMetaData(EVENT_TYPE, "timer");
break;
} else if ("compensateEventDefinition".equals(nodeName)) {
// reuse already created EventNode
handleCompensationNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
node.setMetaData(EVENT_TYPE, "compensation");
break;
} else if ("signalEventDefinition".equals(nodeName)) {
// reuse already created EventNode
handleSignalNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
node.setMetaData(EVENT_TYPE, "signal");
break;
} else if ("conditionalEventDefinition".equals(nodeName)) {
handleConditionNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
node.setMetaData(EVENT_TYPE, "condition");
break;
} else if ("messageEventDefinition".equals(nodeName)) {
handleMessageNode(node, element, uri, localName, parser, attachedTo, cancelActivity);
node.setMetaData(EVENT_TYPE, "message");
break;
}
xmlNode = xmlNode.getNextSibling();
}
node.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataOutputTypes));
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
nodeContainer.addNode(node);
((ProcessBuildData) parser.getData()).addNode(node);
return node;
}
use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method expressionActionStateNode.
public ActionNode expressionActionStateNode(long id, String name, NodeContainer nodeContainer, String expression, Action action) {
ActionNode actionNode = new ActionNode();
actionNode.setId(id);
actionNode.setName(name);
ActionDataFilter actionDataFilter = action.getActionDataFilter();
StringBuilder functionArguments = new StringBuilder();
if (action.getFunctionRef().getArguments() != null) {
functionArguments.append("(");
for (JsonNode argument : action.getFunctionRef().getArguments()) {
functionArguments.append(unwrapExpression(argument.toString())).append(",");
}
functionArguments.deleteCharAt(functionArguments.length() - 1);
functionArguments.append(")");
}
String inputFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getFromStateData());
String outputFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getResults());
String scopeFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getToStateData());
ConsequenceAction processAction = new ConsequenceAction(null, "expression(context, " + escapeExpression(expression + functionArguments) + ", " + escapeExpression(inputFilter) + ");");
if (actionDataFilter != null && actionDataFilter.isUseResults()) {
processAction = new ConsequenceAction(null, "expression(context, " + escapeExpression(expression + functionArguments) + ", " + escapeExpression(inputFilter) + ", " + escapeExpression(outputFilter) + ", " + escapeExpression(scopeFilter) + ");");
}
io.automatiko.engine.workflow.base.instance.impl.Action injectAction = context -> {
if (actionDataFilter != null && actionDataFilter.isUseResults()) {
io.automatiko.engine.workflow.sw.ServerlessFunctions.expression(context, expression, inputFilter, outputFilter, scopeFilter);
} else {
io.automatiko.engine.workflow.sw.ServerlessFunctions.expression(context, expression, inputFilter);
}
};
processAction.setMetaData(ACTION, injectAction);
actionNode.setAction(processAction);
nodeContainer.addNode(actionNode);
return actionNode;
}
use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method injectStateNode.
public ActionNode injectStateNode(long id, String name, NodeContainer nodeContainer, String dataToInject) {
ActionNode actionNode = new ActionNode();
actionNode.setId(id);
actionNode.setName(name);
ConsequenceAction processAction = new ConsequenceAction(null, "inject(context, " + escapeExpression(dataToInject) + ");");
io.automatiko.engine.workflow.base.instance.impl.Action injectAction = context -> {
io.automatiko.engine.workflow.sw.ServerlessFunctions.inject(context, dataToInject);
};
processAction.setMetaData(ACTION, injectAction);
actionNode.setAction(processAction);
nodeContainer.addNode(actionNode);
return actionNode;
}
use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.
the class ConnectionHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
String fromId = attrs.getValue("from");
emptyAttributeCheck(localName, "from", fromId, parser);
String toId = attrs.getValue("to");
emptyAttributeCheck(localName, "to", toId, parser);
String bendpoints = attrs.getValue("bendpoints");
String fromType = attrs.getValue("fromType");
if (fromType == null || fromType.trim().length() == 0) {
fromType = NodeImpl.CONNECTION_DEFAULT_TYPE;
}
String toType = attrs.getValue("toType");
if (toType == null || toType.trim().length() == 0) {
toType = NodeImpl.CONNECTION_DEFAULT_TYPE;
}
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
Node fromNode = nodeContainer.getNode(new Long(fromId));
Node toNode = nodeContainer.getNode(new Long(toId));
if (fromNode == null) {
throw new SAXParseException("Node '" + fromId + "'cannot be found", parser.getLocator());
}
if (toNode == null) {
throw new SAXParseException("Node '" + toId + "' cannot be found", parser.getLocator());
}
ConnectionImpl connection = new ConnectionImpl(fromNode, fromType, toNode, toType);
connection.setMetaData("bendpoints", bendpoints);
return connection;
}
Aggregations