use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class ProcessHandler method linkBoundaryEvents.
public void linkBoundaryEvents(NodeContainer nodeContainer) {
for (Node node : nodeContainer.getNodes()) {
if (node instanceof EventNode) {
final String attachedTo = (String) node.getMetaData().get("AttachedTo");
if (attachedTo != null) {
for (EventFilter filter : ((EventNode) node).getEventFilters()) {
String type = ((EventTypeFilter) filter).getType();
Node attachedNode = findNodeByIdOrUniqueIdInMetadata(nodeContainer, attachedTo, "Could not find node to attach to: " + attachedTo);
//
if (!(attachedNode instanceof StateBasedNode) && !type.equals("Compensation")) {
throw new IllegalArgumentException("Boundary events are supported only on StateBasedNode, found node: " + attachedNode.getClass().getName() + " [" + attachedNode.getMetaData().get("UniqueId") + "]");
}
if (type.startsWith("Escalation")) {
linkBoundaryEscalationEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.startsWith("Error-")) {
linkBoundaryErrorEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.startsWith("Timer-")) {
linkBoundaryTimerEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.equals("Compensation")) {
linkBoundaryCompensationEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (node.getMetaData().get("SignalName") != null || type.startsWith("Message-")) {
linkBoundarySignalEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.startsWith("Condition-")) {
linkBoundaryConditionEvent(nodeContainer, node, attachedTo, attachedNode);
}
}
}
}
}
}
use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class ProcessHandler method linkConnections.
public void linkConnections(NodeContainer nodeContainer, List<SequenceFlow> connections) {
if (connections != null) {
for (SequenceFlow connection : connections) {
String sourceRef = connection.getSourceRef();
Node source = findNodeByIdOrUniqueIdInMetadata(nodeContainer, sourceRef, "Could not find source node for connection:" + sourceRef);
if (source instanceof EventNode) {
for (EventFilter eventFilter : ((EventNode) source).getEventFilters()) {
if (eventFilter instanceof EventTypeFilter) {
if ("Compensation".equals(((EventTypeFilter) eventFilter).getType())) {
// BPMN Method & Style, 2nd Ed. (Silver), states this on P. 131
throw new IllegalArgumentException("A Compensation Boundary Event can only be *associated* with a compensation activity via an Association, not via a Sequence Flow element.");
}
}
}
}
String targetRef = connection.getTargetRef();
Node target = findNodeByIdOrUniqueIdInMetadata(nodeContainer, targetRef, "Could not find target node for connection:" + targetRef);
Connection result = new ConnectionImpl(source, NodeImpl.CONNECTION_DEFAULT_TYPE, target, NodeImpl.CONNECTION_DEFAULT_TYPE);
result.setMetaData("bendpoints", connection.getBendpoints());
result.setMetaData("UniqueId", connection.getId());
if ("true".equals(System.getProperty("jbpm.enable.multi.con"))) {
NodeImpl nodeImpl = (NodeImpl) source;
Constraint constraint = buildConstraint(connection, nodeImpl);
if (constraint != null) {
nodeImpl.addConstraint(new ConnectionRef(connection.getId(), target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
}
} else if (source instanceof Split) {
Split split = (Split) source;
Constraint constraint = buildConstraint(connection, split);
split.addConstraint(new ConnectionRef(connection.getId(), target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
}
}
}
}
use of io.automatiko.engine.api.definition.process.Node 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);
}
}
use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class XmlBPMNProcessDumper method visitEscalations.
protected void visitEscalations(Node[] nodes, StringBuilder xmlDump, List<String> escalations) {
for (Node node : nodes) {
if (node instanceof FaultNode) {
FaultNode faultNode = (FaultNode) node;
if (!faultNode.isTerminateParent()) {
String escalationCode = faultNode.getFaultName();
if (!escalations.contains(escalationCode)) {
escalations.add(escalationCode);
xmlDump.append(" <escalation id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(escalationCode) + "\" escalationCode=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(escalationCode) + "\" />" + EOL);
}
}
} else if (node instanceof ActionNode) {
ActionNode actionNode = (ActionNode) node;
if (actionNode.getAction() instanceof ConsequenceAction) {
ConsequenceAction action = (ConsequenceAction) actionNode.getAction();
if (action != null) {
String s = action.getConsequence();
if (s.startsWith("org.drools.core.process.instance.context.exception.ExceptionScopeInstance scopeInstance = (org.drools.core.process.instance.context.exception.ExceptionScopeInstance) ((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).resolveContextInstance(org.drools.core.process.core.context.exception.ExceptionScope.EXCEPTION_SCOPE, \"")) {
s = s.substring(327);
String type = s.substring(0, s.indexOf("\""));
if (!escalations.contains(type)) {
escalations.add(type);
xmlDump.append(" <escalation id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" escalationCode=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" />" + EOL);
}
}
}
} else {
logger.warn("Cannot serialize custom implementation of the Action interface to XML");
}
} else if (node instanceof EventNode) {
EventNode eventNode = (EventNode) node;
String type = (String) eventNode.getMetaData("EscalationEvent");
if (type != null) {
if (!escalations.contains(type)) {
escalations.add(type);
xmlDump.append(" <escalation id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" escalationCode=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" />" + EOL);
}
}
}
if (node instanceof CompositeNode) {
visitEscalations(((CompositeNode) node).getNodes(), xmlDump, escalations);
}
}
}
use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.
the class XmlBPMNProcessDumper method visitInterfaces.
protected void visitInterfaces(Node[] nodes, StringBuilder xmlDump) {
for (Node node : nodes) {
if (node instanceof WorkItemNode) {
Work work = ((WorkItemNode) node).getWork();
if (work != null) {
if ("Service Task".equals(work.getName())) {
String interfaceName = (String) work.getParameter("Interface");
if (interfaceName == null) {
interfaceName = "";
}
String interfaceRef = (String) work.getParameter("interfaceImplementationRef");
if (interfaceRef == null) {
interfaceRef = "";
}
String operationName = (String) work.getParameter("Operation");
if (operationName == null) {
operationName = "";
}
String operationRef = (String) work.getParameter("operationImplementationRef");
if (operationRef == null) {
operationRef = "";
}
String parameterType = (String) work.getParameter("ParameterType");
if (parameterType == null) {
parameterType = "";
}
xmlDump.append(" <itemDefinition id=\"" + getUniqueNodeId(node) + "_InMessageType\" " + ("".equals(parameterType) || "java.lang.Object".equals(parameterType) ? "" : "structureRef=\"" + parameterType + "\" ") + "/>" + EOL + " <message id=\"" + getUniqueNodeId(node) + "_InMessage\" itemRef=\"" + getUniqueNodeId(node) + "_InMessageType\" />" + EOL + " <interface id=\"" + getUniqueNodeId(node) + "_ServiceInterface\" name=\"" + interfaceName + "\" implementationRef=\"" + interfaceRef + "\" >" + EOL + " <operation id=\"" + getUniqueNodeId(node) + "_ServiceOperation\" name=\"" + operationName + "\" implementationRef=\"" + operationRef + "\" >" + EOL + " <inMessageRef>" + getUniqueNodeId(node) + "_InMessage</inMessageRef>" + EOL + " </operation>" + EOL + " </interface>" + EOL + EOL);
} else if ("Send Task".equals(work.getName())) {
String messageType = (String) work.getParameter("MessageType");
if (messageType == null) {
messageType = "";
}
xmlDump.append(" <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + " <message id=\"" + getUniqueNodeId(node) + "_Message\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
} else if ("Receive Task".equals(work.getName())) {
String messageId = (String) work.getParameter("MessageId");
String messageType = (String) work.getParameter("MessageType");
if (messageType == null) {
messageType = "";
}
xmlDump.append(" <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + " <message id=\"" + messageId + "\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
}
}
} else if (node instanceof EndNode) {
String messageType = (String) node.getMetaData().get("MessageType");
if (messageType != null) {
xmlDump.append(" <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + " <message id=\"" + getUniqueNodeId(node) + "_Message\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
}
} else if (node instanceof ActionNode) {
String messageType = (String) node.getMetaData().get("MessageType");
if (messageType != null) {
xmlDump.append(" <itemDefinition id=\"" + getUniqueNodeId(node) + "_MessageType\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + " <message id=\"" + getUniqueNodeId(node) + "_Message\" itemRef=\"" + getUniqueNodeId(node) + "_MessageType\" />" + EOL + EOL);
}
} else if (node instanceof EventNode) {
List<EventFilter> filters = ((EventNode) node).getEventFilters();
if (filters.size() > 0) {
String messageRef = ((EventTypeFilter) filters.get(0)).getType();
if (messageRef.startsWith("Message-")) {
messageRef = messageRef.substring(8);
String messageType = (String) node.getMetaData().get("MessageType");
xmlDump.append(" <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageRef) + "Type\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + " <message id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageRef) + "\" itemRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageRef) + "Type\" />" + EOL + EOL);
}
}
} else if (node instanceof StartNode) {
StartNode startNode = (StartNode) node;
if (startNode.getTriggers() != null && !startNode.getTriggers().isEmpty()) {
Trigger trigger = startNode.getTriggers().get(0);
if (trigger instanceof EventTrigger) {
String eventType = ((EventTypeFilter) ((EventTrigger) trigger).getEventFilters().get(0)).getType();
if (eventType.startsWith("Message-")) {
eventType = eventType.substring(8);
String messageType = (String) node.getMetaData().get("MessageType");
xmlDump.append(" <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(eventType) + "Type\" " + ("".equals(messageType) || "java.lang.Object".equals(messageType) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(messageType) + "\" ") + "/>" + EOL + " <message id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(eventType) + "\" itemRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(eventType) + "Type\" />" + EOL + EOL);
}
}
}
} else if (node instanceof ForEachNode) {
ForEachNode forEachNode = (ForEachNode) node;
String type = null;
if (forEachNode.getVariableType() instanceof ObjectDataType) {
type = ((ObjectDataType) forEachNode.getVariableType()).getClassName();
}
xmlDump.append(" <itemDefinition id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(forEachNode) + "_multiInstanceItemType\" " + (type == null || "java.lang.Object".equals(type) ? "" : "structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" ") + "/>" + EOL + EOL);
}
if (node instanceof CompositeNode) {
visitInterfaces(((CompositeNode) node).getNodes(), xmlDump);
}
}
}
Aggregations