use of org.jbpm.workflow.core.node.CompositeNode in project jbpm by kiegroup.
the class CompositeNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
super.writeNode(getNodeName(), node, xmlDump, includeMeta);
CompositeNode compositeNode = (CompositeNode) node;
writeAttributes(compositeNode, xmlDump, includeMeta);
xmlDump.append(">" + EOL);
if (includeMeta) {
writeMetaData(compositeNode, xmlDump);
}
for (String eventType : compositeNode.getActionTypes()) {
writeActions(eventType, compositeNode.getActions(eventType), xmlDump);
}
writeTimers(compositeNode.getTimers(), xmlDump);
if (compositeNode instanceof CompositeContextNode) {
VariableScope variableScope = (VariableScope) ((CompositeContextNode) compositeNode).getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope != null) {
List<Variable> variables = variableScope.getVariables();
XmlWorkflowProcessDumper.visitVariables(variables, xmlDump);
}
ExceptionScope exceptionScope = (ExceptionScope) ((CompositeContextNode) compositeNode).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
if (exceptionScope != null) {
XmlWorkflowProcessDumper.visitExceptionHandlers(exceptionScope.getExceptionHandlers(), xmlDump);
}
}
List<Node> subNodes = getSubNodes(compositeNode);
xmlDump.append(" <nodes>" + EOL);
for (Node subNode : subNodes) {
XmlRuleFlowProcessDumper.INSTANCE.visitNode(subNode, xmlDump, includeMeta);
}
xmlDump.append(" </nodes>" + EOL);
List<Connection> connections = getSubConnections(compositeNode);
xmlDump.append(" <connections>" + EOL);
for (Connection connection : connections) {
XmlRuleFlowProcessDumper.INSTANCE.visitConnection(connection, xmlDump, includeMeta);
}
xmlDump.append(" </connections>" + EOL);
Map<String, CompositeNode.NodeAndType> inPorts = getInPorts(compositeNode);
xmlDump.append(" <in-ports>" + EOL);
for (Map.Entry<String, CompositeNode.NodeAndType> entry : inPorts.entrySet()) {
xmlDump.append(" <in-port type=\"" + entry.getKey() + "\" nodeId=\"" + entry.getValue().getNodeId() + "\" nodeInType=\"" + entry.getValue().getType() + "\" />" + EOL);
}
xmlDump.append(" </in-ports>" + EOL);
Map<String, CompositeNode.NodeAndType> outPorts = getOutPorts(compositeNode);
xmlDump.append(" <out-ports>" + EOL);
for (Map.Entry<String, CompositeNode.NodeAndType> entry : outPorts.entrySet()) {
xmlDump.append(" <out-port type=\"" + entry.getKey() + "\" nodeId=\"" + entry.getValue().getNodeId() + "\" nodeOutType=\"" + entry.getValue().getType() + "\" />" + EOL);
}
xmlDump.append(" </out-ports>" + EOL);
endNode(getNodeName(), xmlDump);
}
use of org.jbpm.workflow.core.node.CompositeNode in project jbpm by kiegroup.
the class RuleFlowProcessValidator method checkAllNodesConnectedToStart.
private void checkAllNodesConnectedToStart(final NodeContainer container, boolean isDynamic, final List<ProcessValidationError> errors, RuleFlowProcess process) {
final Map<Node, Boolean> processNodes = new HashMap<Node, Boolean>();
final Node[] nodes;
if (container instanceof CompositeNode) {
nodes = ((CompositeNode) container).internalGetNodes();
} else {
nodes = container.getNodes();
}
List<Node> eventNodes = new ArrayList<Node>();
List<CompositeNode> compositeNodes = new ArrayList<CompositeNode>();
for (int i = 0; i < nodes.length; i++) {
final Node node = nodes[i];
processNodes.put(node, Boolean.FALSE);
if (node instanceof EventNode) {
eventNodes.add(node);
}
if (node instanceof CompositeNode) {
compositeNodes.add((CompositeNode) node);
}
}
if (isDynamic) {
for (Node node : nodes) {
if (node.getIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE).isEmpty()) {
processNode(node, processNodes);
}
}
} else {
final List<Node> start = RuleFlowProcess.getStartNodes(nodes);
if (start != null) {
for (Node s : start) {
processNode(s, processNodes);
}
}
if (container instanceof CompositeNode) {
for (CompositeNode.NodeAndType nodeAndTypes : ((CompositeNode) container).getLinkedIncomingNodes().values()) {
processNode(nodeAndTypes.getNode(), processNodes);
}
}
}
for (Node eventNode : eventNodes) {
processNode(eventNode, processNodes);
}
for (CompositeNode compositeNode : compositeNodes) {
checkAllNodesConnectedToStart(compositeNode, compositeNode instanceof DynamicNode, errors, process);
}
for (final Iterator<Node> it = processNodes.keySet().iterator(); it.hasNext(); ) {
final Node node = it.next();
if (Boolean.FALSE.equals(processNodes.get(node)) && !(node instanceof StartNode) && !(node instanceof EventSubProcessNode)) {
addErrorMessage(process, node, errors, "Has no connection to the start node.");
}
}
}
use of org.jbpm.workflow.core.node.CompositeNode in project jbpm by kiegroup.
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 DroolsConsequenceAction) {
DroolsConsequenceAction action = (DroolsConsequenceAction) 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 org.jbpm.workflow.core.node.CompositeNode in project jbpm by kiegroup.
the class XmlBPMNProcessDumper method visitNodesDi.
private void visitNodesDi(Node[] nodes, StringBuilder xmlDump) {
for (Node node : nodes) {
Integer x = (Integer) node.getMetaData().get("x");
Integer y = (Integer) node.getMetaData().get("y");
Integer width = (Integer) node.getMetaData().get("width");
Integer height = (Integer) node.getMetaData().get("height");
if (x == null) {
x = 0;
}
if (y == null) {
y = 0;
}
if (width == null) {
width = 48;
}
if (height == null) {
height = 48;
}
if (node instanceof StartNode || node instanceof EndNode || node instanceof EventNode || node instanceof FaultNode) {
int offsetX = (int) ((width - 48) / 2);
width = 48;
x = x + offsetX;
int offsetY = (int) ((height - 48) / 2);
y = y + offsetY;
height = 48;
} else if (node instanceof Join || node instanceof Split) {
int offsetX = (int) ((width - 48) / 2);
width = 48;
x = x + offsetX;
int offsetY = (int) ((height - 48) / 2);
y = y + offsetY;
height = 48;
}
int parentOffsetX = 0;
int parentOffsetY = 0;
NodeContainer nodeContainer = node.getNodeContainer();
while (nodeContainer instanceof CompositeNode) {
CompositeNode parent = (CompositeNode) nodeContainer;
Integer parentX = (Integer) parent.getMetaData().get("x");
if (parentX != null) {
parentOffsetX += parentX;
}
Integer parentY = (Integer) parent.getMetaData().get("y");
if (parentY != null) {
parentOffsetY += (Integer) parent.getMetaData().get("y");
}
nodeContainer = parent.getNodeContainer();
}
x += parentOffsetX;
y += parentOffsetY;
xmlDump.append(" <bpmndi:BPMNShape bpmnElement=\"" + getUniqueNodeId(node) + "\" >" + EOL + " <dc:Bounds x=\"" + x + "\" " + "y=\"" + y + "\" " + "width=\"" + width + "\" " + "height=\"" + height + "\" />" + EOL + " </bpmndi:BPMNShape>" + EOL);
if (node instanceof CompositeNode) {
visitNodesDi(((CompositeNode) node).getNodes(), xmlDump);
}
}
}
use of org.jbpm.workflow.core.node.CompositeNode in project jbpm by kiegroup.
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