最近初学jBPM4,当学到task时遇到一点小问题,问题如下:
一个简单的jpdl.xml:
<process name="task" xmlns="http://jbpm.org/4.3/jpdl">
<start name="start1" g="141,88,48,48">
<transition name="to task1" to="task1" g="-44,-18"/>
</start>
<task name="task1" g="119,165,92,52" assignee="yknife">
<transition name="to end1" to="end1" g="-42,-18"/>
</task>
<end name="end1" g="132,248,48,48"/>
</process>
按部就班的获得taskService,通过findPersonalTasks("yknife")得到task1的taskId以后,我想完成这个任务并走向“end1”节点以结束流程,
于是taskService.complete(taskId,"to end1")
结果我用processInstance.findActiveActivityNames()发现活动节点依然停滞在task1,未向下流转。且processInstance.isEnded()为false。
这让我很是疑惑!希望有遇到类似问题的前辈能指条明路啊~
一直感觉我的流程和任务好像是分开在流转的!!!
------解决方案--------------------
不好意思,一天没登陆,没发现。
- Java code
package com.yknife;import java.util.Iterator;import java.util.List;import java.util.Set;import junit.framework.TestCase;import org.jbpm.api.*;import org.jbpm.api.history.HistoryProcessInstance;import org.jbpm.api.task.Task;public class MyTask extends TestCase { ProcessEngine processEngine; public MyTask(){ processEngine = Configuration.getProcessEngine(); } public void setUp(){ RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.createDeployment().addResourceFromClasspath("task.jpdl.xml").deploy(); } public void testTask(){ ExecutionService es = processEngine.getExecutionService(); HistoryService hs = processEngine.getHistoryService(); ProcessInstance pi = es.startProcessInstanceByKey("task"); TaskService ts = processEngine.getTaskService(); List<Task> list = ts.findPersonalTasks("yknife"); Task task = list.get(0); String taskId = task.getId(); ts.completeTask(taskId); //查看历史流程表,可以断言流程已经结束了 HistoryProcessInstance hpi = hs.createHistoryProcessInstanceQuery().processInstanceId(pi.getId()).uniqueResult(); assertTrue("ended".equals(hpi.getState())); //查看任务表任务,可以通过任务不存在了 List<Task> taskList = ts.createTaskQuery().processInstanceId(pi.getId()).list(); assertTrue(taskList.size()==0); }}
------解决方案--------------------
findActiveActivityNames()的结果依然是task1
对于这个问题,你需要建2个任务,完成一个任务后,再试试下面的代码,需要重查一下流程。
- Java code
pi = es.findProcessInstanceById(pi.getId());Set set = pi.findActiveActivityNames(); Iterator it = set.iterator(); while(it.hasNext()){ System.out.println(it.next()); }