Search in sources :

Example 16 with Node

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

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);
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            handleSignalNode(node, element, uri, localName, parser);
        } else if ("messageEventDefinition".equals(nodeName)) {
            handleMessageNode(node, element, uri, localName, parser);
        } 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);
            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);
            break;
        } else if ("compensateEventDefinition".equals(nodeName)) {
            // reuse already created ActionNode
            handleThrowCompensationEventNode(node, element, uri, localName, parser);
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : FaultNode(org.jbpm.workflow.core.node.FaultNode) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) EndNode(org.jbpm.workflow.core.node.EndNode) Node(org.jbpm.workflow.core.Node) FaultNode(org.jbpm.workflow.core.node.FaultNode) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Example 17 with Node

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

the class IntermediateCatchEventHandler 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
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("signalEventDefinition".equals(nodeName)) {
            // reuse already created EventNode
            handleSignalNode(node, element, uri, localName, parser);
            break;
        } else if ("messageEventDefinition".equals(nodeName)) {
            // reuse already created EventNode
            handleMessageNode(node, element, uri, localName, parser);
            break;
        } else if ("timerEventDefinition".equals(nodeName)) {
            // create new timerNode
            TimerNode timerNode = new TimerNode();
            timerNode.setId(node.getId());
            timerNode.setName(node.getName());
            timerNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
            node = timerNode;
            handleTimerNode(node, element, uri, localName, parser);
            break;
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            // create new stateNode
            StateNode stateNode = new StateNode();
            stateNode.setId(node.getId());
            stateNode.setName(node.getName());
            stateNode.setMetaData("UniqueId", node.getMetaData().get("UniqueId"));
            node = stateNode;
            handleStateNode(node, element, uri, localName, parser);
            break;
        } else if ("linkEventDefinition".equals(nodeName)) {
            CatchLinkNode linkNode = new CatchLinkNode();
            linkNode.setId(node.getId());
            node = linkNode;
            handleLinkNode(element, node, xmlNode, parser);
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) TimerNode(org.jbpm.workflow.core.node.TimerNode) StateNode(org.jbpm.workflow.core.node.StateNode) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.jbpm.workflow.core.Node) StateNode(org.jbpm.workflow.core.node.StateNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) TimerNode(org.jbpm.workflow.core.node.TimerNode)

Example 18 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);
    final Node node = createNode(attrs);
    String id = attrs.getValue("id");
    node.setMetaData("UniqueId", id);
    final String name = attrs.getValue("name");
    node.setName(name);
    if ("true".equalsIgnoreCase(System.getProperty("jbpm.v5.id.strategy"))) {
        try {
            // remove starting _
            id = id.substring(1);
            // remove ids of parent nodes
            id = id.substring(id.lastIndexOf("-") + 1);
            node.setId(Integer.parseInt(id));
        } catch (NumberFormatException e) {
            // id is not in the expected format, generating a new one
            long newId = 0;
            NodeContainer nodeContainer = (NodeContainer) parser.getParent();
            for (org.kie.api.definition.process.Node n : nodeContainer.getNodes()) {
                if (n.getId() > newId) {
                    newId = n.getId();
                }
            }
            ((org.jbpm.workflow.core.Node) node).setId(++newId);
        }
    } else {
        AtomicInteger idGen = (AtomicInteger) parser.getMetaData().get("idGen");
        node.setId(idGen.getAndIncrement());
    }
    return node;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.jbpm.workflow.core.NodeContainer)

Example 19 with Node

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

the class EndNodeInstanceTest method testEndNode.

@Test
public void testEndNode() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory factory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), factory);
    WorkflowProcessImpl process = new WorkflowProcessImpl();
    Node endNode = new EndNode();
    endNode.setId(1);
    endNode.setName("end node");
    mockNode.setId(2);
    new ConnectionImpl(mockNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(mockNode);
    process.addNode(endNode);
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setState(ProcessInstance.STATE_ACTIVE);
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    MockNodeInstance mockNodeInstance = (MockNodeInstance) processInstance.getNodeInstance(mockNode);
    mockNodeInstance.triggerCompleted();
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) EndNode(org.jbpm.workflow.core.node.EndNode) KieBase(org.kie.api.KieBase) EndNode(org.jbpm.workflow.core.node.EndNode) Node(org.jbpm.workflow.core.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 20 with Node

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

the class CompensationTest method findNode.

private Node findNode(RuleFlowProcess process, String nodeName) {
    Node found = null;
    Queue<org.kie.api.definition.process.Node> nodes = new LinkedList<org.kie.api.definition.process.Node>();
    nodes.addAll(Arrays.asList(process.getNodes()));
    while (!nodes.isEmpty()) {
        org.kie.api.definition.process.Node node = nodes.poll();
        if (node.getName().equals(nodeName)) {
            found = (Node) node;
        }
        if (node instanceof NodeContainer) {
            nodes.addAll(Arrays.asList(((NodeContainer) node).getNodes()));
        }
    }
    assertNotNull("Could not find node (" + nodeName + ").", found);
    return found;
}
Also used : BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) Node(org.jbpm.workflow.core.Node) NodeContainer(org.kie.api.definition.process.NodeContainer) LinkedList(java.util.LinkedList)

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