Search in sources :

Example 16 with StartNode

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

the class CompositeNodeInstance method internalTrigger.

public void internalTrigger(final org.kie.api.runtime.process.NodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
        return;
    }
    CompositeNode.NodeAndType nodeAndType = getCompositeNode().internalGetLinkedIncomingNode(type);
    if (nodeAndType != null) {
        List<Connection> connections = nodeAndType.getNode().getIncomingConnections(nodeAndType.getType());
        for (Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) {
            Connection connection = iterator.next();
            if ((connection.getFrom() instanceof CompositeNode.CompositeNodeStart) && (from == null || ((CompositeNode.CompositeNodeStart) connection.getFrom()).getInNode().getId() == from.getNodeId())) {
                NodeInstance nodeInstance = getNodeInstance(connection.getFrom());
                ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, nodeAndType.getType());
                return;
            }
        }
    } else {
        // try to search for start nodes
        boolean found = false;
        for (Node node : getCompositeNode().getNodes()) {
            if (node instanceof StartNode) {
                StartNode startNode = (StartNode) node;
                if (startNode.getTriggers() == null || startNode.getTriggers().isEmpty()) {
                    NodeInstance nodeInstance = getNodeInstance(startNode);
                    ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, null);
                    found = true;
                }
            }
        }
        if (found) {
            return;
        }
    }
    if (isLinkedIncomingNodeRequired()) {
        throw new IllegalArgumentException("Could not find start for composite node: " + type);
    }
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) 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) Connection(org.kie.api.definition.process.Connection) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) NodeInstance(org.jbpm.workflow.instance.NodeInstance)

Example 17 with StartNode

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

the class EventSubProcessNodeInstance method signalEvent.

@Override
public void signalEvent(String type, Object event) {
    if (getNodeInstanceContainer().getNodeInstances().contains(this) || type.startsWith("Error-") || type.equals("timerTriggered")) {
        StartNode startNode = getCompositeNode().findStartNode();
        if (resolveVariables(((EventSubProcessNode) getEventBasedNode()).getEvents()).contains(type) || type.equals("timerTriggered")) {
            NodeInstance nodeInstance = getNodeInstance(startNode);
            ((StartNodeInstance) nodeInstance).signalEvent(type, event);
        }
    }
    super.signalEvent(type, event);
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 18 with StartNode

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

the class EventSubProcessNodeInstance method nodeInstanceCompleted.

@Override
public void nodeInstanceCompleted(org.jbpm.workflow.instance.NodeInstance nodeInstance, String outType) {
    if (nodeInstance instanceof EndNodeInstance) {
        if (getCompositeNode().isKeepActive()) {
            StartNode startNode = getCompositeNode().findStartNode();
            triggerCompleted(true);
            if (startNode.isInterrupting()) {
                String faultName = getProcessInstance().getOutcome() == null ? "" : getProcessInstance().getOutcome();
                if (startNode.getMetaData("FaultCode") != null) {
                    faultName = (String) startNode.getMetaData("FaultCode");
                }
                if (getNodeInstanceContainer() instanceof ProcessInstance) {
                    ((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
                } else {
                    ((NodeInstanceContainer) getNodeInstanceContainer()).setState(ProcessInstance.STATE_ABORTED);
                }
            }
        }
    } else {
        throw new IllegalArgumentException("Completing a node instance that has no outgoing connection not supported.");
    }
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) ProcessInstance(org.jbpm.process.instance.ProcessInstance)

Example 19 with StartNode

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

the class SubProcessTest method testSynchronousSubProcess.

@Test
public void testSynchronousSubProcess() {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.process");
    process.setName("Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    EndNode endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(2);
    process.addNode(endNode);
    SubProcessNode subProcessNode = new SubProcessNode();
    subProcessNode.setName("SubProcessNode");
    subProcessNode.setId(3);
    subProcessNode.setProcessId("org.drools.core.process.subprocess");
    process.addNode(subProcessNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, subProcessNode, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(subProcessNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    RuleFlowProcess subprocess = new RuleFlowProcess();
    subprocess.setId("org.drools.core.process.subprocess");
    subprocess.setName("SubProcess");
    startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    subprocess.addNode(startNode);
    endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(2);
    subprocess.addNode(endNode);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Action");
    DroolsAction action = new DroolsConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            logger.info("Executed action");
            executed = true;
        }
    });
    actionNode.setAction(action);
    actionNode.setId(3);
    subprocess.addNode(actionNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    KieSession ksession = createKieSession(process, subprocess);
    TestProcessEventListener procEventListener = new TestProcessEventListener();
    ksession.addEventListener(procEventListener);
    ksession.startProcess("org.drools.core.process.process");
    assertTrue(executed);
    assertEquals(0, ksession.getProcessInstances().size());
    verifyEventHistory(syncEventorder, procEventListener.getEventHistory());
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Action(org.jbpm.process.instance.impl.Action) DroolsAction(org.jbpm.workflow.core.DroolsAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionNode(org.jbpm.workflow.core.node.ActionNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) ProcessContext(org.kie.api.runtime.process.ProcessContext) EndNode(org.jbpm.workflow.core.node.EndNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) KieSession(org.kie.api.runtime.KieSession) TestProcessEventListener(org.jbpm.process.test.TestProcessEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 20 with StartNode

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

the class SubProcessTest method testNonExistentSubProcess.

@Test
public void testNonExistentSubProcess() {
    String nonExistentSubProcessName = "nonexistent.process";
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.process");
    process.setName("Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    SubProcessNode subProcessNode = new SubProcessNode();
    subProcessNode.setName("SubProcessNode");
    subProcessNode.setId(2);
    subProcessNode.setProcessId(nonExistentSubProcessName);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, subProcessNode);
    connect(subProcessNode, endNode);
    process.addNode(startNode);
    process.addNode(subProcessNode);
    process.addNode(endNode);
    KieSession ksession = createKieSession(process);
    try {
        ksession.startProcess("org.drools.core.process.process");
        fail("should throw exception");
    } catch (RuntimeException re) {
        assertTrue(re.getMessage().contains(nonExistentSubProcessName));
    }
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) EndNode(org.jbpm.workflow.core.node.EndNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

StartNode (org.jbpm.workflow.core.node.StartNode)47 EndNode (org.jbpm.workflow.core.node.EndNode)34 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)32 ActionNode (org.jbpm.workflow.core.node.ActionNode)30 ArrayList (java.util.ArrayList)25 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)24 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)19 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)18 Test (org.junit.Test)18 DroolsAction (org.jbpm.workflow.core.DroolsAction)17 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)17 Action (org.jbpm.process.instance.impl.Action)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)16 EventNode (org.jbpm.workflow.core.node.EventNode)16 KieSession (org.kie.api.runtime.KieSession)16 ProcessContext (org.kie.api.runtime.process.ProcessContext)16 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)15 Variable (org.jbpm.process.core.context.variable.Variable)14 Work (org.jbpm.process.core.Work)11 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)11