use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class StartNodeInstanceTest method testStartNode.
@Test
public void testStartNode() {
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
MockNode mockNode = new MockNode();
MockNodeInstanceFactory mockNodeFactory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), mockNodeFactory);
RuleFlowProcess process = new RuleFlowProcess();
StartNode startNode = new StartNode();
startNode.setId(1);
startNode.setName("start node");
mockNode.setId(2);
new ConnectionImpl(startNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, mockNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
process.addNode(startNode);
process.addNode(mockNode);
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setProcess(process);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
processInstance.start();
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
MockNodeInstance mockNodeInstance = mockNodeFactory.getMockNodeInstance();
List<NodeInstance> triggeredBy = mockNodeInstance.getTriggers().get(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
assertNotNull(triggeredBy);
assertEquals(1, triggeredBy.size());
assertSame(startNode.getId(), triggeredBy.get(0).getNodeId());
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class CancelNodeInstanceCommand method execute.
public Void execute(Context context) {
logger.debug("About to cancel node instance with id {} on process instance {}", nodeInstanceId, processInstanceId);
KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, false);
if (wfp == null) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " not found");
}
NodeInstance nodeInstance = wfp.getNodeInstances(true).stream().filter(ni -> ni.getId() == nodeInstanceId).findFirst().orElse(null);
if (nodeInstance == null) {
throw new NodeInstanceNotFoundException("Node instance with id " + nodeInstanceId + " not found");
}
logger.debug("Found node instance {} to be canceled", nodeInstance);
((NodeInstanceImpl) nodeInstance).cancel();
logger.debug("Node instance {} canceled successfully", nodeInstance);
return null;
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class ListNodesCommand method execute.
public List<ProcessNode> execute(Context context) {
List<ProcessNode> nodes = null;
KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
RuleFlowProcessInstance wfp = (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId, true);
if (wfp == null) {
throw new ProcessInstanceNotFoundException("No process instance can be found for id " + processInstanceId);
}
String processId = wfp.getProcessId();
nodes = wfp.getRuleFlowProcess().getNodesRecursively().stream().map(n -> new ProcessNodeImpl(n.getName(), n.getId(), n.getClass().getSimpleName(), processId)).collect(Collectors.toList());
return nodes;
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class GetProcessInstancesTest method createProcessInstanceAndGetStartDate.
@Test
public void createProcessInstanceAndGetStartDate() throws Exception {
StatefulKnowledgeSession ksession = reloadKnowledgeSession();
long processId = ksession.createProcessInstance("org.jbpm.processinstance.helloworld", null).getId();
assertEquals(0, ksession.getProcessInstances().size());
RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) ksession.getProcessInstance(processId);
assertNotNull("Process " + processId + " exist!", processInstance);
assertNotNull("Process start at " + processInstance.getStartDate(), processInstance.getStartDate());
ksession.dispose();
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class SingleSessionCommandServiceTest method testPersistenceSubProcess.
@Test
public void testPersistenceSubProcess() {
setUp();
Properties properties = new Properties();
properties.setProperty("drools.commandService", PersistableRunner.class.getName());
properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
SessionConfiguration config = SessionConfiguration.newInstance(properties);
InternalKnowledgeBase ruleBase = KnowledgeBaseFactory.newKnowledgeBase();
KiePackage pkg = getProcessSubProcess();
ruleBase.addPackages((Collection) Arrays.asList(pkg));
PersistableRunner service = new PersistableRunner(ruleBase, config, env);
Long sessionId = service.getSessionId();
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) service.execute(startProcessCommand);
logger.info("Started process instance {}", processInstance.getId());
long processInstanceId = processInstance.getId();
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, ruleBase, config, env);
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
Collection<NodeInstance> nodeInstances = processInstance.getNodeInstances();
assertEquals(1, nodeInstances.size());
SubProcessNodeInstance subProcessNodeInstance = (SubProcessNodeInstance) nodeInstances.iterator().next();
long subProcessInstanceId = subProcessNodeInstance.getProcessInstanceId();
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
RuleFlowProcessInstance subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
assertNotNull(subProcessInstance);
service.dispose();
service = new PersistableRunner(sessionId, ruleBase, config, env);
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
service.dispose();
service = new PersistableRunner(sessionId, ruleBase, config, env);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
assertNull(subProcessInstance);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
assertNull(processInstance);
service.dispose();
}
Aggregations