Search in sources :

Example 1 with RuntimeEnvironment

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);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ArrayList(java.util.ArrayList) List(java.util.List) UserGroupCallback(org.kie.api.task.UserGroupCallback)

Example 2 with RuntimeEnvironment

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);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ArrayList(java.util.ArrayList) List(java.util.List) UserGroupCallback(org.kie.api.task.UserGroupCallback)

Example 3 with RuntimeEnvironment

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);
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 4 with RuntimeEnvironment

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());
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 5 with RuntimeEnvironment

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());
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Aggregations

RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)177 Test (org.junit.Test)163 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)148 KieSession (org.kie.api.runtime.KieSession)127 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)107 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)101 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)51 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)49 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)48 HashMap (java.util.HashMap)47 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)42 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)38 ArrayList (java.util.ArrayList)21 TaskSummary (org.kie.api.task.model.TaskSummary)21 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)20 AuditService (org.kie.api.runtime.manager.audit.AuditService)20 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)19 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)19 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)19 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)17