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);
}
}
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);
}
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.");
}
}
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());
}
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));
}
}
Aggregations