Search in sources :

Example 96 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class ChecklistExample method main.

public static void main(String[] args) {
    try {
        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 ("actor4".equals(userId)) {
                    result.add("group1");
                }
                return result;
            }

            public boolean existsUser(String arg0) {
                return true;
            }

            public boolean existsGroup(String arg0) {
                return true;
            }
        }).addAsset(KieServices.Factory.get().getResources().newClassPathResource("checklist/SampleChecklistProcess.bpmn"), ResourceType.BPMN2).get();
        ChecklistManager checklistManager = new DefaultChecklistManager(environment);
        long c1 = checklistManager.createContext("org.jbpm.examples.checklist.sample1", "actor1");
        List<ChecklistItem> items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task1");
        ChecklistItem item1 = findChecklistItem(items, "Task1");
        checklistManager.completeTask("actor1", item1.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Adding Extra Task");
        String[] actorIds = new String[] { "actor5" };
        ChecklistItem itemExtra = checklistManager.addTask("actor5", actorIds, new String[0], "TaskExtra", "2+", c1);
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task2");
        ChecklistItem item2 = findChecklistItem(items, "Task2");
        checklistManager.claimTask("actor4", item2.getTaskId());
        checklistManager.completeTask("actor4", item2.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task3b");
        ChecklistItem item3b = findChecklistItem(items, "Task3b");
        checklistManager.claimTask("actor3", item3b.getTaskId());
        checklistManager.completeTask("actor3", item3b.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task3a");
        ChecklistItem item3a = findChecklistItem(items, "Task3a");
        checklistManager.completeTask("actor1", item3a.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Extra Task");
        itemExtra = findChecklistItem(items, "TaskExtra");
        checklistManager.completeTask("actor5", itemExtra.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
        System.out.println("Completing Task4");
        ChecklistItem item4 = findChecklistItem(items, "Task4");
        checklistManager.completeTask("actor1", item4.getTaskId());
        items = checklistManager.getTasks(c1, null);
        printChecklistItems(items, c1);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ChecklistManager(org.jbpm.examples.checklist.ChecklistManager) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) List(java.util.List) ArrayList(java.util.ArrayList) UserGroupCallback(org.kie.api.task.UserGroupCallback)

Example 97 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class EvaluationExample method getRuntimeManager.

private static RuntimeManager getRuntimeManager(String process) {
    // load up the knowledge base
    JBPMHelper.startH2Server();
    JBPMHelper.setupDataSource();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().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)

Example 98 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class MultipleInstanceExample method getRuntimeManager.

private static RuntimeManager getRuntimeManager(String process) {
    // load up the knowledge base
    JBPMHelper.startH2Server();
    JBPMHelper.setupDataSource();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().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)

Example 99 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm-work-items by kiegroup.

the class JPAWorkItemHandlerTest method startJPAWIHProcess.

private void startJPAWIHProcess(String action, Product prod) throws Exception {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
    RuntimeEnvironment env = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addEnvironmentEntry("org.kie.internal.runtime.manager.TaskServiceFactory", new TaskServiceFactory() {

        @Override
        public TaskService newTaskService() {
            return null;
        }

        @Override
        public void close() {
        }
    }).addAsset(ResourceFactory.newClassPathResource("JPAWIH.bpmn2"), ResourceType.BPMN2).get();
    RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(env);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    KieSession kSession = engine.getKieSession();
    JPAWorkItemHandler jpaWih = new JPAWorkItemHandler(P_UNIT, this.getClass().getClassLoader());
    kSession.getWorkItemManager().registerWorkItemHandler("JPAWIH", jpaWih);
    HashMap<String, Object> params = new HashMap<>();
    params.put("action", action);
    params.put("obj", prod);
    params.put("id", prod.getId());
    kSession.startProcess("org.jbpm.JPA_WIH", params);
    manager.disposeRuntimeEngine(engine);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskServiceFactory(org.kie.internal.runtime.manager.TaskServiceFactory) EntityManagerFactory(javax.persistence.EntityManagerFactory) KieSession(org.kie.api.runtime.KieSession)

Example 100 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class AsyncContinuationSupportTest method testAsyncScriptTask.

@Test(timeout = 10000)
public void testAsyncScriptTask() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncScriptTask.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("AsyncScriptTask");
    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)

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