Search in sources :

Example 11 with ForEachNode

use of org.jbpm.workflow.core.node.ForEachNode in project jbpm by kiegroup.

the class SubProcessHandler 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
    boolean found = false;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            Boolean isAsync = Boolean.parseBoolean((String) node.getMetaData().get("customAsync"));
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            forEachNode.setName(node.getName());
            forEachNode.setAutoComplete(((CompositeContextNode) node).isAutoComplete());
            for (org.kie.api.definition.process.Node subNode : ((CompositeContextNode) node).getNodes()) {
                forEachNode.addNode(subNode);
            }
            forEachNode.setMetaData("UniqueId", ((CompositeContextNode) node).getMetaData("UniqueId"));
            forEachNode.setMetaData(ProcessHandler.CONNECTIONS, ((CompositeContextNode) node).getMetaData(ProcessHandler.CONNECTIONS));
            VariableScope v = (VariableScope) ((CompositeContextNode) node).getDefaultContext(VariableScope.VARIABLE_SCOPE);
            ((VariableScope) ((CompositeContextNode) forEachNode.internalGetNode(2)).getDefaultContext(VariableScope.VARIABLE_SCOPE)).setVariables(v.getVariables());
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser, isAsync);
            found = true;
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (!found) {
        handleCompositeContextNode(node, element, uri, localName, parser);
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Element(org.w3c.dom.Element) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 12 with ForEachNode

use of org.jbpm.workflow.core.node.ForEachNode in project jbpm by kiegroup.

the class TaskHandler 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
    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++);
            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);
            Node orignalNode = node;
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser);
            // remove output collection data output of for each to avoid problems when running in variable strict mode
            if (orignalNode instanceof WorkItemNode) {
                ((WorkItemNode) orignalNode).adjustOutMapping(forEachNode.getOutputCollectionExpression());
            }
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    // replace node in case it's milestone
    if (node instanceof WorkItemNode && ((WorkItemNode) node).getWork().getName().equals("Milestone")) {
        WorkItemNode workItemNode = (WorkItemNode) node;
        String milestoneCondition = (String) ((WorkItemNode) node).getWork().getParameter("Condition");
        if (milestoneCondition == null) {
            // if not given that means once activated it's achieved
            milestoneCondition = "";
        }
        MilestoneNode milestoneNode = new MilestoneNode();
        milestoneNode.setId(workItemNode.getId());
        milestoneNode.setConstraint(milestoneCondition);
        milestoneNode.setMetaData(workItemNode.getMetaData());
        milestoneNode.setName(workItemNode.getName());
        milestoneNode.setNodeContainer(workItemNode.getNodeContainer());
        node = milestoneNode;
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Node(org.jbpm.workflow.core.Node) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode)

Example 13 with ForEachNode

use of org.jbpm.workflow.core.node.ForEachNode in project jbpm by kiegroup.

the class TaskHandler method handleForEachNode.

protected void handleForEachNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ForEachNode forEachNode = (ForEachNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, inputAssociation);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, outputAssociation);
        } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ForEachNode(org.jbpm.workflow.core.node.ForEachNode)

Example 14 with ForEachNode

use of org.jbpm.workflow.core.node.ForEachNode 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);
        }
    }
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ActionNode(org.jbpm.workflow.core.node.ActionNode) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) EndNode(org.jbpm.workflow.core.node.EndNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) List(java.util.List) ArrayList(java.util.ArrayList) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Aggregations

ForEachNode (org.jbpm.workflow.core.node.ForEachNode)14 Node (org.jbpm.workflow.core.Node)6 ActionNode (org.jbpm.workflow.core.node.ActionNode)6 StartNode (org.jbpm.workflow.core.node.StartNode)6 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)6 EndNode (org.jbpm.workflow.core.node.EndNode)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 FaultNode (org.jbpm.workflow.core.node.FaultNode)4 MilestoneNode (org.jbpm.workflow.core.node.MilestoneNode)4 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)4 List (java.util.List)3 Work (org.jbpm.process.core.Work)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)3 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)3 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)3 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)3