use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.
the class EndEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
EndNode endNode = (EndNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInputAssociation".equals(nodeName)) {
readEndDataInputAssociation(xmlNode, endNode);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
String variable = (String) endNode.getMetaData("MappingVariable");
endNode.setMetaData("MessageType", message.getType());
endNode.setMetaData("TriggerType", "ProduceMessage");
endNode.setMetaData("TriggerRef", message.getName());
for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
endNode.setMetaData(entry.getKey(), entry.getValue());
}
List<ProcessAction> actions = new ArrayList<ProcessAction>();
ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable));
actions.add(action);
endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.
the class EndEventHandler method handleSignalNode.
public void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
EndNode endNode = (EndNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInput".equals(nodeName)) {
String id = ((Element) xmlNode).getAttribute("id");
String inputName = ((Element) xmlNode).getAttribute("name");
dataInputs.put(id, inputName);
} else if ("dataInputAssociation".equals(nodeName)) {
readEndDataInputAssociation(xmlNode, endNode);
} else if ("signalEventDefinition".equals(nodeName)) {
String signalName = ((Element) xmlNode).getAttribute("signalRef");
String variable = (String) endNode.getMetaData("MappingVariable");
signalName = checkSignalAndConvertToRealSignalNam(parser, signalName);
endNode.setMetaData("EventType", "signal");
endNode.setMetaData("Ref", signalName);
endNode.setMetaData("Variable", variable);
// check if signal should be send async
if (dataInputs.containsValue("async")) {
signalName = "ASYNC-" + signalName;
}
ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction(signalName, variable, (String) endNode.getMetaData("customScope"), (Transformation) endNode.getMetaData().get("Transformation")));
List<ProcessAction> actions = new ArrayList<ProcessAction>();
actions.add(action);
endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.
the class EndEventHandler 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();
// determine type of event definition, so the correct type of node
// can be generated
super.handleNode(node, element, uri, localName, parser);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("terminateEventDefinition".equals(nodeName)) {
// reuse already created EndNode
handleTerminateNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
break;
} else if ("signalEventDefinition".equals(nodeName)) {
handleSignalNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
} else if ("messageEventDefinition".equals(nodeName)) {
handleMessageNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
} else if ("errorEventDefinition".equals(nodeName)) {
// create new faultNode
FaultNode faultNode = new FaultNode();
faultNode.setId(node.getId());
faultNode.setName(node.getName());
faultNode.setTerminateParent(true);
faultNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
node = faultNode;
super.handleNode(node, element, uri, localName, parser);
handleErrorNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
break;
} else if ("escalationEventDefinition".equals(nodeName)) {
// create new faultNode
FaultNode faultNode = new FaultNode();
faultNode.setId(node.getId());
faultNode.setName(node.getName());
faultNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
node = faultNode;
super.handleNode(node, element, uri, localName, parser);
handleEscalationNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
break;
} else if ("compensateEventDefinition".equals(nodeName)) {
// reuse already created ActionNode
handleThrowCompensationEventNode(node, element, uri, localName, parser);
node.setMetaData("functionFlowContinue", "true");
break;
}
xmlNode = xmlNode.getNextSibling();
}
NodeContainer nodeContainer = (NodeContainer) parser.getParent();
nodeContainer.addNode(node);
((ProcessBuildData) parser.getData()).addNode(node);
return node;
}
use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.
the class EndNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
EndNode endNode = (EndNode) node;
String eventType = (String) endNode.getMetaData("EventType");
String ref = (String) endNode.getMetaData("Ref");
String variableRef = (String) endNode.getMetaData("Variable");
writeNode("endEvent", endNode, xmlDump, metaDataType);
if (endNode.isTerminate()) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
xmlDump.append(" <terminateEventDefinition " + (endNode.getScope() == EndNode.PROCESS_SCOPE ? "tns:scope=\"process\"" : "") + "/>" + EOL);
endNode("endEvent", xmlDump);
} else {
String scope = (String) endNode.getMetaData("customScope");
List<ProcessAction> actions = endNode.getActions(EndNode.EVENT_NODE_ENTER);
if (actions != null && !actions.isEmpty()) {
if (actions.size() == 1) {
ConsequenceAction action = (ConsequenceAction) actions.get(0);
String s = action.getConsequence();
if (s.startsWith("org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();")) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
String variable = (String) endNode.getMetaData("MappingVariable");
if (variable != null) {
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <messageEventDefinition messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Message\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if ("signal".equals(eventType)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
if (!s.startsWith("null")) {
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variableRef) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(ref) + "\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if (s.startsWith(RUNTIME_SIGNAL_EVENT)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
s = s.substring(44);
String type = s.substring(0, s.indexOf("\""));
s = s.substring(s.indexOf(",") + 2);
String variable = null;
if (!s.startsWith("null")) {
variable = s.substring(0, s.indexOf(")"));
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT) && "processInstance".equals(scope)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
s = s.substring(43);
String type = s.substring(0, s.indexOf("\""));
s = s.substring(s.indexOf(",") + 2);
String variable = null;
if (!s.startsWith("null")) {
variable = s.substring(0, s.indexOf(")"));
xmlDump.append(" <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + " <dataInputAssociation>" + EOL + " <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + " <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + " </dataInputAssociation>" + EOL + " <inputSet>" + EOL + " <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + " </inputSet>" + EOL);
}
xmlDump.append(" <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
endNode("endEvent", xmlDump);
} else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT)) {
xmlDump.append(">" + EOL);
writeExtensionElements(endNode, xmlDump);
int begin = (PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", ").length() - 2;
int end = s.length() - 3;
String compensationEvent = s.substring(begin, end);
String activityRef = "";
if (!compensationEvent.startsWith(CompensationScope.IMPLICIT_COMPENSATION_PREFIX)) {
// specific
activityRef = "activityRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(activityRef) + "\" ";
}
// else general: activityRef = "" (above)
xmlDump.append(" <compensateEventDefinition " + activityRef + "/>" + EOL);
endNode("endEvent", xmlDump);
} else {
throw new IllegalArgumentException("Unknown action " + s);
}
}
} else {
endNode(xmlDump);
}
}
}
use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.
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.getParentContainer();
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.getParentContainer();
}
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);
}
}
}
Aggregations