package com.jzsoft.jbpm;
import java.util.Iterator;
import java.util.List;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.exe.TaskInstance;
import junit.framework.TestCase;
public class Jbpm_08_NextNode extends TestCase {
static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
//从一个TaskNode出发,触发流程继续向下流转
public void testNextNode(){
//JbpmContext对象封装了hibernate session对象的功能,可以执行
//与数据库相关的操作
JbpmContext context = jbpmConfiguration.createJbpmContext();
try{
int docId = (Integer)Persistence.getVariable("docId");
//nextStep(context,"张三",docId);
//nextStep(context,"李四",docId);
nextStep(context,"王五",docId);
}catch(Exception e){
e.printStackTrace();
context.setRollbackOnly();
}finally{
context.close();
}
}
private void nextStep(JbpmContext context,String actorId,Integer _docId){
List taskInstances = context.getTaskMgmtSession().findTaskInstances(actorId);
for (Iterator iter = taskInstances.iterator(); iter.hasNext();) {
TaskInstance ti = (TaskInstance) iter.next();
Integer docId = (Integer)ti.getProcessInstance().getContextInstance().getVariable("document");
if(docId.equals(_docId)){
//参与者的任务已经处理完成,需要结束这个任务实例
//这个动作,在缺省的情况下,会触发对应的Token的signal动作,即流向下一个节点
ti.end();
String docTitle = (String)ti.getProcessInstance().getContextInstance().getVariable("documentTitle");
System.err.println("公文【"+docTitle+"】已经被【"+actorId+"】审批完成,已提交到下一个节点");
}
}
}
}