use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class EvaluationExample2 method getRuntimeManager.
private static RuntimeManager getRuntimeManager(String process) {
// load up the knowledge base
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(new UserGroupCallback() {
public List<String> getGroupsForUser(String userId) {
List<String> result = new ArrayList<String>();
if ("mary".equals(userId)) {
result.add("HR");
} else if ("john".equals(userId)) {
result.add("PM");
}
return result;
}
public boolean existsUser(String arg0) {
return true;
}
public boolean existsGroup(String arg0) {
return true;
}
}).addAsset(KieServices.Factory.get().getResources().newClassPathResource(process), ResourceType.BPMN2).get();
return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class HumanTaskExample method getRuntimeManager.
private static RuntimeManager getRuntimeManager(String process) {
// load up the knowledge base
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(new UserGroupCallback() {
public List<String> getGroupsForUser(String userId) {
List<String> result = new ArrayList<String>();
if ("sales-rep".equals(userId)) {
result.add("sales");
} else if ("john".equals(userId)) {
result.add("PM");
}
return result;
}
public boolean existsUser(String arg0) {
return true;
}
public boolean existsGroup(String arg0) {
return true;
}
}).addAsset(KieServices.Factory.get().getResources().newClassPathResource(process), ResourceType.BPMN2).get();
return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncModeWithParallelGateway.
@Test(timeout = 10000)
public void testAsyncModeWithParallelGateway() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("EndProcess", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncParallelGateway.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).addEnvironmentEntry("AsyncMode", "true").registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("Rest", new SystemOutWorkItemHandler());
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("TestProject.DemoProcess");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
assertNull(processInstance);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncParallelGateway.
@Test(timeout = 10000)
public void testAsyncParallelGateway() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("REST", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncParallelGateway.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("Rest", new SystemOutWorkItemHandler());
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("TestProject.DemoProcess");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
assertNull(processInstance);
// List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
// assertNotNull(logs);
// assertEquals(8, logs.size());
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncCallActivityTask.
@Test(timeout = 10000)
public void testAsyncCallActivityTask() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("CallActivity", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new SystemOutWorkItemHandler());
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("ParentProcess");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
assertNotNull(logs);
assertEquals(6, logs.size());
}
Aggregations