Search in sources :

Example 31 with EndNode

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();
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Message(io.automatiko.engine.workflow.bpmn2.core.Message) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) HandleMessageAction(io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction) Entry(java.util.Map.Entry) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 32 with EndNode

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();
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ArrayList(java.util.ArrayList)

Example 33 with EndNode

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;
}
Also used : FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) Node(io.automatiko.engine.workflow.process.core.Node) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer)

Example 34 with EndNode

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);
        }
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)

Example 35 with EndNode

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);
        }
    }
}
Also used : FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Join(io.automatiko.engine.workflow.process.core.node.Join) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) Split(io.automatiko.engine.workflow.process.core.node.Split) Constraint(io.automatiko.engine.workflow.process.core.Constraint)

Aggregations

EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)36 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)23 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)19 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)19 ArrayList (java.util.ArrayList)19 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)14 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)13 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)12 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)11 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)10 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)9 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)9 List (java.util.List)9 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)8 Action (io.automatiko.engine.workflow.base.instance.impl.Action)8 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)8 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)8 Test (org.junit.jupiter.api.Test)8 Node (io.automatiko.engine.api.definition.process.Node)7 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)7