use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project drools by kiegroup.
the class CommandBasedStatefulKnowledgeSession method getProcessInstance.
public ProcessInstance getProcessInstance(long id) {
GetProcessInstanceCommand command = new GetProcessInstanceCommand();
command.setProcessInstanceId(id);
return runner.execute(command);
}
use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project jbpm by kiegroup.
the class SingleSessionCommandServiceTest method testPersistenceTimer.
@Test
public void testPersistenceTimer() throws Exception {
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());
SessionConfiguration config = SessionConfiguration.newInstance(properties);
config.setOption(TimerJobFactoryOption.get(TimerJobFactoryType.JPA.getId()));
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Collection<KiePackage> kpkgs = getProcessTimer();
kbase.addPackages(kpkgs);
PersistableRunner service = new PersistableRunner(kbase, config, env);
Long sessionId = service.getSessionId();
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
ProcessInstance processInstance = service.execute(startProcessCommand);
logger.info("Started process instance {}", processInstance.getId());
Thread.sleep(500);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
Thread.sleep(5000);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
assertNull(processInstance);
}
use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project jbpm by kiegroup.
the class SingleSessionCommandServiceTest method testPersistenceWorkItemsUserTransaction.
@Test
public void testPersistenceWorkItemsUserTransaction() throws Exception {
setUp();
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Collection<KiePackage> kpkgs = getProcessWorkItems();
kbase.addPackages(kpkgs);
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);
PersistableRunner service = new PersistableRunner(kbase, config, env);
Long sessionId = service.getSessionId();
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
ut.begin();
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
ProcessInstance processInstance = service.execute(startProcessCommand);
logger.info("Started process instance {}", processInstance.getId());
ut.commit();
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
ut.begin();
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
ut.commit();
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
ut.begin();
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
ut.commit();
workItem = handler.getWorkItem();
assertNotNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
ut.begin();
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
ut.commit();
assertNotNull(processInstance);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
ut.begin();
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
ut.commit();
workItem = handler.getWorkItem();
assertNotNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
ut.begin();
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
ut.commit();
assertNotNull(processInstance);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
ut.begin();
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
ut.commit();
workItem = handler.getWorkItem();
assertNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
ut.begin();
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
ut.commit();
assertNull(processInstance);
service.dispose();
}
use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project jbpm by kiegroup.
the class SingleSessionCommandServiceTest method testPersistenceWorkItems.
@Test
public void testPersistenceWorkItems() throws Exception {
setUp();
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Collection<KiePackage> kpkgs = getProcessWorkItems();
kbase.addPackages(kpkgs);
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);
PersistableRunner service = new PersistableRunner(kbase, config, env);
Long sessionId = service.getSessionId();
StartProcessCommand startProcessCommand = new StartProcessCommand();
startProcessCommand.setProcessId("org.drools.test.TestProcess");
ProcessInstance processInstance = service.execute(startProcessCommand);
logger.info("Started process instance {}", processInstance.getId());
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
workItem = handler.getWorkItem();
assertNotNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
workItem = handler.getWorkItem();
assertNotNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
assertNotNull(processInstance);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
completeWorkItemCommand = new CompleteWorkItemCommand();
completeWorkItemCommand.setWorkItemId(workItem.getId());
service.execute(completeWorkItemCommand);
workItem = handler.getWorkItem();
assertNull(workItem);
service.dispose();
service = new PersistableRunner(sessionId, kbase, config, env);
getProcessInstanceCommand = new GetProcessInstanceCommand();
getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
processInstance = service.execute(getProcessInstanceCommand);
assertNull(processInstance);
service.dispose();
}
use of org.drools.core.command.runtime.process.GetProcessInstanceCommand 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