package com.jzsoft.jbpm; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import junit.framework.TestCase; public class Jbpm_05_SubmitDocument extends TestCase { static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); //将公文提交到第一个环节 public void testSubmitDocument(){ //JbpmContext对象封装了hibernate session对象的功能,可以执行 //与数据库相关的操作 JbpmContext context = jbpmConfiguration.createJbpmContext(); try{ int docId = (Integer)Persistence.getVariable("docId"); Document doc = (Document)context.getSession().load(Document.class, docId); long processInstanceId = doc.getProcessInstanceId(); ProcessInstance processInstance = context.getProcessInstance(processInstanceId); //触发流程流向下一个节点 processInstance.signal(); }catch(Exception e){ e.printStackTrace(); context.setRollbackOnly(); }finally{ context.close(); } } } package com.jzsoft.jbpm; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; import junit.framework.TestCase; public class Jbpm_06_CurrentNode extends TestCase { static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); //获得公文当前所处的节点 public void testCurrentNode(){ //JbpmContext对象封装了hibernate session对象的功能,可以执行 //与数据库相关的操作 JbpmContext context = jbpmConfiguration.createJbpmContext(); try{ int docId = (Integer)Persistence.getVariable("docId"); Document doc = (Document)context.getSession().load(Document.class, docId); long processInstanceId = doc.getProcessInstanceId(); ProcessInstance processInstance = context.getProcessInstance(processInstanceId); System.err.println( "公文【"+doc.getTitle()+"】当前处在节点:"+ processInstance.getRootToken().getNode().getName() + ",流程实例是否已经结束?" + processInstance.hasEnded() ); }catch(Exception e){ e.printStackTrace(); context.setRollbackOnly(); }finally{ context.close(); } } } 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_07_SearchMyTaskList extends TestCase { static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); //查询当前登录人员的任务列表 public void testSearchMyTaskList(){ //JbpmContext对象封装了hibernate session对象的功能,可以执行 //与数据库相关的操作 JbpmContext context = jbpmConfiguration.createJbpmContext(); try{ printTask(context,"张三"); printTask(context,"李四"); printTask(context,"王五"); }catch(Exception e){ e.printStackTrace(); context.setRollbackOnly(); }finally{ context.close(); } } private void printTask(JbpmContext context,String actorId){ 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"); String docTitle = (String)ti.getProcessInstance().getContextInstance().getVariable("documentTitle"); System.err.println("正在等待【"+actorId+"】审批的公文是:"+docTitle); } } }