Search in sources :

Example 16 with NodeContainer

use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.

the class IntermediateThrowEventHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    ActionNode node = (ActionNode) parser.getCurrent();
    // 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 ("signalEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleSignalNode(node, element, uri, localName, parser);
            node.setMetaData("functionFlowContinue", "true");
            break;
        } else if ("messageEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleMessageNode(node, element, uri, localName, parser);
            node.setMetaData("functionFlowContinue", "true");
            break;
        } else if ("escalationEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            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;
        } else if ("linkEventDefinition".equals(nodeName)) {
            ThrowLinkNode linkNode = new ThrowLinkNode();
            linkNode.setId(node.getId());
            handleLinkNode(element, linkNode, xmlNode, parser);
            NodeContainer nodeContainer = (NodeContainer) parser.getParent();
            nodeContainer.addNode(linkNode);
            ((ProcessBuildData) parser.getData()).addNode(node);
            // we break the while and stop the execution of this method.
            return linkNode;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    // none event definition
    if (node.getAction() == null) {
        node.setAction(new ConsequenceAction("mvel", ""));
        node.setMetaData("NodeType", "IntermediateThrowEvent-None");
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    return node;
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ThrowLinkNode(io.automatiko.engine.workflow.process.core.node.ThrowLinkNode)

Example 17 with NodeContainer

use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.

the class IntermediateThrowEventHandler method handleLinkNode.

protected void handleLinkNode(Element element, Node node, org.w3c.dom.Node xmlLinkNode, ExtensibleXmlParser parser) {
    node.setName(element.getAttribute("name"));
    NamedNodeMap linkAttr = xmlLinkNode.getAttributes();
    String name = linkAttr.getNamedItem("name").getNodeValue();
    String id = element.getAttribute("id");
    node.setMetaData("UniqueId", id);
    node.setMetaData(LINK_NAME, name);
    org.w3c.dom.Node xmlNode = xmlLinkNode.getFirstChild();
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    IntermediateLink aLink = new IntermediateLink();
    aLink.setName(name);
    aLink.setUniqueId(id);
    while (null != xmlNode) {
        String nodeName = xmlNode.getNodeName();
        if (LINK_TARGET.equals(nodeName)) {
            String target = xmlNode.getTextContent();
            node.setMetaData(LINK_TARGET, target);
        }
        if (LINK_SOURCE.equals(nodeName)) {
            String source = xmlNode.getTextContent();
            ArrayList<String> sources = (ArrayList<String>) node.getMetaData().get(LINK_SOURCE);
            // if there is no list, create one
            if (null == sources) {
                sources = new ArrayList<String>();
            }
            // to connect nodes.
            aLink.addSource(source);
            // to do the xml dump
            sources.add(source);
            node.setMetaData(LINK_SOURCE, sources);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    aLink.configureThrow();
    if (nodeContainer instanceof ExecutableProcess) {
        ExecutableProcess process = (ExecutableProcess) nodeContainer;
        List<IntermediateLink> links = (List<IntermediateLink>) process.getMetaData().get(ProcessHandler.LINKS);
        if (null == links) {
            links = new ArrayList<IntermediateLink>();
        }
        links.add(aLink);
        process.setMetaData(ProcessHandler.LINKS, links);
    } else if (nodeContainer instanceof CompositeNode) {
        CompositeNode subprocess = (CompositeNode) nodeContainer;
        List<IntermediateLink> links = (List<IntermediateLink>) subprocess.getMetaData().get(ProcessHandler.LINKS);
        if (null == links) {
            links = new ArrayList<IntermediateLink>();
        }
        links.add(aLink);
        subprocess.setMetaData(ProcessHandler.LINKS, links);
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) ArrayList(java.util.ArrayList) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) IntermediateLink(io.automatiko.engine.workflow.bpmn2.core.IntermediateLink) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 18 with NodeContainer

use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.

the class CallActivityHandler method end.

@SuppressWarnings("unchecked")
@Override
public Object end(String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    handleNode(node, element, uri, localName, parser);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    int uniqueIdGen = 1;
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            String uniqueId = (String) node.getMetaData().get("UniqueId");
            forEachNode.setMetaData("UniqueId", uniqueId);
            node.setMetaData("UniqueId", uniqueId + ":" + uniqueIdGen++);
            node.setMetaData("hidden", true);
            forEachNode.addNode(node);
            forEachNode.linkIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE, node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.linkOutgoingConnections(node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE, NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.setSequential(Boolean.parseBoolean(((Element) xmlNode).getAttribute("isSequential")));
            Node orignalNode = node;
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser);
            // running in variable strict mode
            if (orignalNode instanceof SubProcessNode) {
                adjustNodeConfiguration(orignalNode, forEachNode);
            }
            Map<String, String> dataInputs = (Map<String, String>) orignalNode.getMetaData().remove("DataInputs");
            Map<String, String> dataOutputs = (Map<String, String>) orignalNode.getMetaData().remove("DataOutputs");
            orignalNode.setMetaData("MICollectionOutput", dataOutputs.get(((ForEachNode) node).getMetaData("MICollectionOutput")));
            orignalNode.setMetaData("MICollectionInput", dataInputs.get(((ForEachNode) node).getMetaData("MICollectionInput")));
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : Element(org.w3c.dom.Element) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) Node(io.automatiko.engine.workflow.process.core.Node) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with NodeContainer

use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.

the class DefinitionsHandler method postProcessInterfaces.

private void postProcessInterfaces(NodeContainer nodeContainer, List<Interface> interfaces) {
    for (Node node : nodeContainer.getNodes()) {
        if (node instanceof NodeContainer) {
            postProcessInterfaces((NodeContainer) node, interfaces);
        }
        if (node instanceof WorkItemNode && "Service Task".equals(((WorkItemNode) node).getMetaData("Type"))) {
            WorkItemNode workItemNode = (WorkItemNode) node;
            if (interfaces == null) {
                throw new IllegalArgumentException("No interfaces found");
            }
            String operationRef = (String) workItemNode.getMetaData("OperationRef");
            String implementation = (String) workItemNode.getMetaData("Implementation");
            Operation operation = null;
            for (Interface i : interfaces) {
                operation = i.getOperation(operationRef);
                if (operation != null) {
                    break;
                }
            }
            if (operation == null) {
                throw new IllegalArgumentException("Could not find operation " + operationRef);
            }
            // avoid overriding parameters set by data input associations
            if (workItemNode.getWork().getParameter("Interface") == null) {
                workItemNode.getWork().setParameter("Interface", operation.getInterface().getName());
            }
            if (workItemNode.getWork().getParameter("Operation") == null) {
                workItemNode.getWork().setParameter("Operation", operation.getName());
            }
            if (workItemNode.getWork().getParameter("ParameterType") == null && operation.getMessage() != null) {
                workItemNode.getWork().setParameter("ParameterType", operation.getMessage().getType());
            }
            // parameters to support web service invocation
            if (implementation != null) {
                workItemNode.getWork().setParameter("interfaceImplementationRef", operation.getInterface().getImplementationRef());
                workItemNode.getWork().setParameter("operationImplementationRef", operation.getImplementationRef());
                workItemNode.getWork().setParameter("implementation", implementation);
            }
        }
    }
}
Also used : Node(io.automatiko.engine.api.definition.process.Node) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) Operation(io.automatiko.engine.workflow.bpmn2.core.Interface.Operation) Interface(io.automatiko.engine.workflow.bpmn2.core.Interface)

Example 20 with NodeContainer

use of io.automatiko.engine.workflow.process.core.NodeContainer in project automatiko-engine by automatiko-io.

the class BoundaryEventHandler method handleCompensationNode.

protected void handleCompensationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    BoundaryEventNode eventNode = (BoundaryEventNode) parser.getCurrent();
    super.handleNode(node, element, uri, localName, parser);
    NodeList childs = element.getChildNodes();
    for (int i = 0; i < childs.getLength(); i++) {
        if (childs.item(i) instanceof Element) {
            Element el = (Element) childs.item(i);
            if ("compensateEventDefinition".equalsIgnoreCase(el.getNodeName())) {
                String activityRef = el.getAttribute("activityRef");
                if (activityRef != null && activityRef.length() > 0) {
                    logger.warn("activityRef value [" + activityRef + "] on Boundary Event '" + eventNode.getMetaData("UniqueId") + "' ignored per the BPMN2 specification.");
                }
            }
        }
    }
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setAttachedToNodeId(attachedTo);
    // 1. Find the parent (sub-)process
    NodeContainer parentContainer = (NodeContainer) parser.getParent();
    // 2. Add the event filter (never fires, purely for dumping purposes)
    EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
    eventFilter.setType("Compensation");
    List<EventFilter> eventFilters = new ArrayList<EventFilter>();
    eventNode.setEventFilters(eventFilters);
    eventFilters.add(eventFilter);
    // 3. Add compensation scope (with key/id: attachedTo)
    ProcessHandler.addCompensationScope((ExecutableProcess) parser.getParent(ExecutableProcess.class), eventNode, parentContainer, attachedTo);
}
Also used : NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

Aggregations

NodeContainer (io.automatiko.engine.workflow.process.core.NodeContainer)25 Node (io.automatiko.engine.workflow.process.core.Node)12 List (java.util.List)11 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)10 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)10 ArrayList (java.util.ArrayList)10 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)9 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)8 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)8 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)8 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)8 Element (org.w3c.dom.Element)8 Node (io.automatiko.engine.api.definition.process.Node)7 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)7 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)7 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)7 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)6 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)6 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)6 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)6