Search in sources :

Example 26 with Node

use of org.jbpm.workflow.core.Node in project jbpm by kiegroup.

the class AbstractNodeHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    final Node node = createNode();
    final String id = attrs.getValue("id");
    node.setId(new Long(id));
    final String name = attrs.getValue("name");
    node.setName(name);
    nodeContainer.addNode(node);
    return node;
}
Also used : Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Example 27 with Node

use of org.jbpm.workflow.core.Node 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);
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Node(org.jbpm.workflow.core.Node) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) Connection(org.kie.api.definition.process.Connection) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) Map(java.util.Map) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 28 with Node

use of org.jbpm.workflow.core.Node in project jbpm by kiegroup.

the class StartEventHandler method handleNode.

@SuppressWarnings("unchecked")
protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    StartNode startNode = (StartNode) node;
    // TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between the schema default and the actual set value
    // However, while the schema says the "isInterrupting" attr should default to true
    // The spec says that Escalation start events should default to not interrupting..
    startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            readDataOutput(xmlNode, startNode);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, startNode);
        } else if ("outputSet".equals(nodeName)) {
            // p. 225, BPMN2 spec (2011-01-03)
            // InputSet and OutputSet elements imply that process execution should wait for them to be filled
            // and are therefore not applicable to catch events
            String message = "Ignoring <" + nodeName + "> element: " + "<" + nodeName + "> elements should not be used on start or other catch events.";
            SAXParseException saxpe = new SAXParseException(message, parser.getLocator());
            parser.warning(saxpe);
        // no exception thrown for backwards compatibility (we used to ignore these elements)
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            String constraint = null;
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode != null) {
                String subnodeName = subNode.getNodeName();
                if ("condition".equals(subnodeName)) {
                    constraint = xmlNode.getTextContent();
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            ConstraintTrigger trigger = new ConstraintTrigger();
            trigger.setConstraint(constraint);
            startNode.addTrigger(trigger);
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            String type = ((Element) xmlNode).getAttribute("signalRef");
            type = checkSignalAndConvertToRealSignalNam(parser, type);
            if (type != null && type.trim().length() > 0) {
                addTriggerWithInMappings(startNode, type);
            }
        } 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);
            }
            startNode.setMetaData("MessageType", message.getType());
            addTriggerWithInMappings(startNode, "Message-" + messageRef);
        } else if ("timerEventDefinition".equals(nodeName)) {
            handleTimerNode(startNode, element, uri, localName, parser);
        // following event definitions are only for event sub process and will be validated to not be included in top process definitions
        } else if ("errorEventDefinition".equals(nodeName)) {
            if (!startNode.isInterrupting()) {
                // BPMN2 spec (p.245-246, (2011-01-03)) implies that
                // - a <startEvent> in an Event Sub-Process
                // - *without* the 'isInterupting' attribute always interrupts (containing process)
                String errorMsg = "Error Start Events in an Event Sub-Process always interrupt the containing (sub)process(es).";
                throw new IllegalArgumentException(errorMsg);
            }
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
            }
        } else if ("escalationEventDefinition".equals(nodeName)) {
            String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
            if (escalationRef != null && escalationRef.trim().length() > 0) {
                Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
                if (escalations == null) {
                    throw new IllegalArgumentException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new IllegalArgumentException("Could not find escalation " + escalationRef);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, element, xmlNode, parser);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) Message(org.jbpm.bpmn2.core.Message) StartNode(org.jbpm.workflow.core.node.StartNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Node(org.jbpm.workflow.core.Node) Element(org.w3c.dom.Element) Escalation(org.jbpm.bpmn2.core.Escalation) Error(org.jbpm.bpmn2.core.Error) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 29 with Node

use of org.jbpm.workflow.core.Node 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 30 with Node

use of org.jbpm.workflow.core.Node 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)

Aggregations

Node (org.jbpm.workflow.core.Node)30 ActionNode (org.jbpm.workflow.core.node.ActionNode)16 EndNode (org.jbpm.workflow.core.node.EndNode)16 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)14 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)13 StartNode (org.jbpm.workflow.core.node.StartNode)13 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)13 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)12 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)11 ArrayList (java.util.ArrayList)10 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)10 Test (org.junit.Test)10 NodeContainer (org.jbpm.workflow.core.NodeContainer)9 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)9 Element (org.w3c.dom.Element)9 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)8 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)8 EventNode (org.jbpm.workflow.core.node.EventNode)7 Variable (org.jbpm.process.core.context.variable.Variable)4 Map (java.util.Map)3