如何在jBPM6 maven的Hello World Project中添加用户和用户任务

时间:2016-03-06 13:13:33

标签: java jboss jbpm

我是jBPM的新手,我正在使用jBPM-6.3.0-Final。

我开始了一个新的jBPM maven项目,它会创建一些像这样的默认内容。 enter image description here

enter image description here

我想添加一个新的用户任务,并将其分配给名为jack的用户。enter image description here

enter image description here

然后我在主类中添加了代码以运行任务3。

package com.sample;

import java.util.List;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.jbpm.test.JBPMHelper;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.manager.RuntimeEngine;
import org.kie.api.runtime.manager.RuntimeEnvironmentBuilder;
import org.kie.api.runtime.manager.RuntimeManager;
import org.kie.api.runtime.manager.RuntimeManagerFactory;
import org.kie.api.task.TaskService;
import org.kie.api.task.model.TaskSummary;

public class ProcessMain {

    public static void main(String[] args) {
        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();
        KieBase kbase = kContainer.getKieBase("kbase");

        RuntimeManager manager = createRuntimeManager(kbase);
        RuntimeEngine engine = manager.getRuntimeEngine(null);
        KieSession ksession = engine.getKieSession();
        TaskService taskService = engine.getTaskService();

        ksession.startProcess("com.sample.bpmn.hello");

        // let john execute Task 1
        List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        TaskSummary task = list.get(0);
        System.out.println("John is executing task " + task.getName());
        taskService.start(task.getId(), "john");
        taskService.complete(task.getId(), "john", null);

        // let mary execute Task 2
        list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
        task = list.get(0);
        System.out.println("Mary is executing task " + task.getName());
        taskService.start(task.getId(), "mary");
        taskService.complete(task.getId(), "mary", null);

        // let jack execute Task 3
        list = taskService.getTasksAssignedAsPotentialOwner("jack", "en-UK");
        task = list.get(0);
        System.out.println("Jack is executing task " + task.getName());
        taskService.start(task.getId(), "jack");
        taskService.complete(task.getId(), "jack", null);

        manager.disposeRuntimeEngine(engine);
        System.exit(0);
    }

    private static RuntimeManager createRuntimeManager(KieBase kbase) {
        JBPMHelper.startH2Server();
        JBPMHelper.setupDataSource();
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
        RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder()
                .entityManagerFactory(emf).knowledgeBase(kbase);
        return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get(), "com.sample:example:1.0");
    }

}

这段代码如何才能运行任务1和任务2.当涉及到任务3时,它会显示以下错误:

John is executing task Task 1
Mary is executing task Task 2
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)
    at java.util.ArrayList.get(ArrayList.java:429)
    at com.sample.ProcessMain.main(ProcessMain.java:50)

所以如何添加用户以及如何正确添加用户任务。

0 个答案:

没有答案