jpdl文件:
<?xml version="1.0" encoding="UTF-8"?>
<process-definition
xmlns="urn:jbpm.org:jpdl-3.2" name="firstdoc">
<start-state name="startFirstdoc">
<transition name="提交给sam初审" to="sam审批"></transition>
</start-state>
<task-node name="sam审批">
<task name="初审请假单">
<assignment actor-id="sam2011" />
</task>
<transition name="提交给lam核实" to="lam审批"></transition>
</task-node>
<task-node name="lam审批">
<task name="核实请假单">
<assignment actor-id="lam2011" />
</task>
<transition name="提交给evan批准" to="evan审批"></transition>
</task-node>
<task-node name="evan审批">
<task name="批准请假单">
<assignment actor-id="eavn2011" />
</task>
<transition name="完成审批" to="endFirstdoc"></transition>
</task-node>
<end-state name="endFirstdoc"></end-state>
</process-definition>
图片:
hibernate配置文件:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- hibernate dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- JDBC connection properties (begin) -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpmsam</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<!-- JDBC connection properties (end) -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/rs/model/Document.hbm.xml" />
<!-- DataSource properties (begin) ===
<property name="hibernate.connection.datasource">java:/JbpmDS</property>
==== DataSource properties (end) -->
<!-- JTA transaction properties (begin) ===
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
==== JTA transaction properties (end) -->
<!-- CMT transaction properties (begin) ===
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
==== CMT transaction properties (end) -->
<!-- logging properties (begin) ===
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
==== logging properties (end) -->
<!-- ############################################ -->
<!-- # mapping files with external dependencies # -->
<!-- ############################################ -->
<!-- following mapping file has a dependendy on -->
<!-- 'bsh-{version}.jar'. -->
<!-- uncomment this if you don't have bsh on your -->
<!-- classpath. you won't be able to use the -->
<!-- script element in process definition files -->
<mapping resource="org/jbpm/graph/action/Script.hbm.xml"/>
<!-- following mapping files have a dependendy on -->
<!-- 'jbpm-identity.jar', mapping files -->
<!-- of the pluggable jbpm identity component. -->
<!-- Uncomment the following 3 lines if you -->
<!-- want to use the jBPM identity mgmgt -->
<!-- component. -->
<!-- identity mappings (begin) -->
<mapping resource="org/jbpm/identity/User.hbm.xml"/>
<mapping resource="org/jbpm/identity/Group.hbm.xml"/>
<mapping resource="org/jbpm/identity/Membership.hbm.xml"/>
<!-- identity mappings (end) -->
<!-- following mapping files have a dependendy on -->
<!-- the JCR API -->
<!-- jcr mappings (begin) ===
<mapping resource="org/jbpm/context/exe/variableinstance/JcrNodeInstance.hbm.xml"/>
==== jcr mappings (end) -->
<!-- ###################### -->
<!-- # jbpm mapping files # -->
<!-- ###################### -->
<!-- hql queries and type defs -->
<mapping resource="org/jbpm/db/hibernate.queries.hbm.xml" />
<!-- graph.def mapping files -->
<mapping resource="org/jbpm/graph/def/ProcessDefinition.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Node.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Transition.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Event.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/Action.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/SuperState.hbm.xml"/>
<mapping resource="org/jbpm/graph/def/ExceptionHandler.hbm.xml"/>
<mapping resource="org/jbpm/instantiation/Delegation.hbm.xml"/>
<!-- graph.node mapping files -->
<mapping resource="org/jbpm/graph/node/StartState.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/EndState.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/ProcessState.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/Decision.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/Fork.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/Join.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/State.hbm.xml"/>
<mapping resource="org/jbpm/graph/node/TaskNode.hbm.xml"/>
<!-- context.def mapping files -->
<mapping resource="org/jbpm/context/def/ContextDefinition.hbm.xml"/>
<mapping resource="org/jbpm/context/def/VariableAccess.hbm.xml"/>
<!-- taskmgmt.def mapping files -->
<mapping resource="org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/def/Swimlane.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/def/Task.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/def/TaskController.hbm.xml"/>
<!-- module.def mapping files -->
<mapping resource="org/jbpm/module/def/ModuleDefinition.hbm.xml"/>
<!-- bytes mapping files -->
<mapping resource="org/jbpm/bytes/ByteArray.hbm.xml"/>
<!-- file.def mapping files -->
<mapping resource="org/jbpm/file/def/FileDefinition.hbm.xml"/>
<!-- scheduler.def mapping files -->
<mapping resource="org/jbpm/scheduler/def/CreateTimerAction.hbm.xml"/>
<mapping resource="org/jbpm/scheduler/def/CancelTimerAction.hbm.xml"/>
<!-- graph.exe mapping files -->
<mapping resource="org/jbpm/graph/exe/Comment.hbm.xml"/>
<mapping resource="org/jbpm/graph/exe/ProcessInstance.hbm.xml"/>
<mapping resource="org/jbpm/graph/exe/Token.hbm.xml"/>
<mapping resource="org/jbpm/graph/exe/RuntimeAction.hbm.xml"/>
<!-- module.exe mapping files -->
<mapping resource="org/jbpm/module/exe/ModuleInstance.hbm.xml"/>
<!-- context.exe mapping files -->
<mapping resource="org/jbpm/context/exe/ContextInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/TokenVariableMap.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/VariableInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/NullInstance.hbm.xml"/>
<mapping resource="org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml"/>
<!-- job mapping files -->
<mapping resource="org/jbpm/job/Job.hbm.xml"/>
<mapping resource="org/jbpm/job/Timer.hbm.xml"/>
<mapping resource="org/jbpm/job/ExecuteNodeJob.hbm.xml"/>
<mapping resource="org/jbpm/job/ExecuteActionJob.hbm.xml"/>
<!-- taskmgmt.exe mapping files -->
<mapping resource="org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/exe/PooledActor.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml"/>
<!-- logging mapping files -->
<mapping resource="org/jbpm/logging/log/ProcessLog.hbm.xml"/>
<mapping resource="org/jbpm/logging/log/MessageLog.hbm.xml"/>
<mapping resource="org/jbpm/logging/log/CompositeLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ActionLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/NodeLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/ProcessStateLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/SignalLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/TokenCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/TokenEndLog.hbm.xml"/>
<mapping resource="org/jbpm/graph/log/TransitionLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableDeleteLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/VariableUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml"/>
<mapping resource="org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml"/>
</session-factory>
</hibernate-configuration>
model类:
package com.rs.model;
public class Document{
private int id;
private String title;
private String content;
private long processInstanceId;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getProcessInstanceId() {
return processInstanceId;
}
public void setProcessInstanceId(long processInstanceId) {
this.processInstanceId = processInstanceId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
model对应的配置表:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.rs.model.Document" table="T_Document" >
<id name="id">
<generator class="native"/>
</id>
<property name="title" />
<property name="content" />
<property name="processInstanceId" />
</class>
</hibernate-mapping>
数据库管理类,创建数据库表:
package com.rs.jbpm;
import org.jbpm.JbpmConfiguration;
import junit.framework.TestCase;
public class JbpmDatabase extends TestCase {
/**
* 创建数据库表
*/
public void testCreateDB() {
JbpmConfiguration.getInstance().createSchema();
}
}
jbpm例子:
package com.rs.jbpm;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import junit.framework.TestCase;
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 com.rs.model.Document;
public class JbpmTools extends TestCase {
static JbpmConfiguration jbpmConfig = JbpmConfiguration.getInstance();
// JbpmContext对象封装了hibernate session 对象的功能,可以执行与数据库持久化相关的操作
static JbpmContext jcontext = jbpmConfig.createJbpmContext();
/**
* 部署流程定义:根据流程定义,解释得到流程定义对象,把流程定义持久化到数据库
*/
public void testDeployProcessDefinition() {
//读取流程定义文件,得到流程定义对象
ProcessDefinition pdef = ProcessDefinition.parseXmlResource("firstdoc/processdefinition.xml");
try {
jcontext.deployProcessDefinition(pdef);
} catch (Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();//关闭流程
}
}
/**
* 创建公文,流程实例
*/
public void testCreateDocument() {
try {
//创建公文对象
Document doc = new Document();
int rd = new Random().nextInt(10000);
doc.setTitle("公文编号" + rd);
doc.setContent("这是地球上第"+rd+"号红色文件!");
jcontext.getSession().save(doc);
//创建流程实例
//1.从数据库加载ProcessDefinition对象,GraphSession流程操作API
ProcessDefinition pdef = jcontext.getGraphSession().findLatestProcessDefinition("firstdoc");
//2.创建流程实例对象
ProcessInstance instance = new ProcessInstance(pdef);
jcontext.save(instance);
//3.公文对象和流程实例对象绑定
doc.setProcessInstanceId(instance.getId());
instance.getContextInstance().setVariable("docId", new Integer(doc.getId()));
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
/**
* 提交公文
*/
public void testSubmitDocument() {
try {
//获取公文id
int docId = 2;
Document doc = (Document)jcontext.getSession().load(Document.class, new Integer(docId));
//得到公文流程实例
long processInstanceId = doc.getProcessInstanceId();
ProcessInstance instance = jcontext.getProcessInstance(processInstanceId);
//只能执行一次,提交到下一节点
instance.signal();
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
/**
* 当前节点
*/
public void testCurrentNode() {
try {
//获取公文id
int docId = 2;
Document doc = (Document)jcontext.getSession().load(Document.class, new Integer(docId));
//得到公文流程实例
long processInstanceId = doc.getProcessInstanceId();
ProcessInstance instance = jcontext.getProcessInstance(processInstanceId);
System.err.println("公文 < Title:" + doc.getTitle() + "| Content: '" + doc.getContent() + "' >所处位置: " + instance.getRootToken().getNode().getName());
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
/**
* 查询用户的任务
*/
public void testTastList() {
try {
//已知用户
printTask(jcontext, "sam2011");
printTask(jcontext, "lam2011");
printTask(jcontext, "eavn2011");
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
private void printTask(JbpmContext jc, String uid) {
List tasks = jc.getTaskMgmtSession().findTaskInstances(uid);
for(Iterator iter = tasks.iterator(); iter.hasNext();) {
TaskInstance ti = (TaskInstance) iter.next();
Integer docId = new Integer(ti.getProcessInstance().getContextInstance().getVariable("docId").toString());
Document doc = (Document)jcontext.getSession().load(Document.class, docId);
System.err.println("公文 < Title:" + doc.getTitle() + "| Content: '" + doc.getContent() + "' > 对应用户: " + uid);
}
}
/**
* 提交任务
*/
public void testNextNode() {
try {
//已知用户
int docId = 2;
//nextNode(jcontext, "sam2011", docId);
//nextNode(jcontext, "lam2011", docId);
nextNode(jcontext, "eavn2011", docId);
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
private void nextNode(JbpmContext jc, String uid, int dId) {
List tasks = jc.getTaskMgmtSession().findTaskInstances(uid);
for(Iterator iter = tasks.iterator(); iter.hasNext();) {
TaskInstance ti = (TaskInstance) iter.next();
Integer docId = new Integer(ti.getProcessInstance().getContextInstance().getVariable("docId").toString());
if(docId.equals(new Integer(dId))) {
ti.end();//结束这个任务实例;触发对应的Token的signal()方法,即流向下一个环节
Document doc = (Document)jcontext.getSession().load(Document.class, docId);
System.err.println("公文 < Title:" + doc.getTitle() + "| Content: '" + doc.getContent() + "' > 已被用户: " + uid + "处理,提交到下一个环节");
}
}
}
}
******************************************************************************************************************************
加入暂存类Persistence.java:
package com.rs.jbpm;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
public class Persistence {//辅助类--暂存器
private static Map variables = null;
//默认的临时文件路径
private static String temFile = System.getProperty("java.io.tmpdir") + "/temp.object";
static {//加载文件
try {
if(new File(temFile).exists()) {
FileInputStream fis = new FileInputStream(temFile);
ObjectInputStream ois = new ObjectInputStream(fis);
variables = (Map)ois.readObject();
}
if(variables == null) {
variables = new HashMap();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 设置变量值
* @param name
* @param obj
*/
public static void setVariable(String name, Object obj) {
if(variables != null) {
variables.put(name, obj);
}
try {
FileOutputStream fos = new FileOutputStream(temFile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(variables);
oos.flush();
oos.close();
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取变量值
* @param name
* @return Serializable
*/
public static Serializable getVariable(String name) {
if(variables != null) {
return (Serializable)variables.get(name);
}
return null;
}
}
JbpmTools.java改为:
package com.rs.jbpm;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import junit.framework.TestCase;
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 com.rs.model.Document;
public class JbpmTools extends TestCase {
static JbpmConfiguration jbpmConfig = JbpmConfiguration.getInstance();
// JbpmContext对象封装了hibernate session 对象的功能,可以执行与数据库持久化相关的操作
static JbpmContext jcontext = jbpmConfig.createJbpmContext();
/**
* 部署流程定义:根据流程定义,解释得到流程定义对象,把流程定义持久化到数据库
*/
public void testDeployProcessDefinition() {
//读取流程定义文件,得到流程定义对象
ProcessDefinition pdef = ProcessDefinition.parseXmlResource("firstdoc/processdefinition.xml");
Persistence.setVariable("pdName", pdef.getName());//暂存‘流程定义’的名称
try {
jcontext.deployProcessDefinition(pdef);
} catch (Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();//关闭流程
}
}
/**
* 创建公文,流程实例
*/
public void testCreateDocument() {
try {
//创建公文对象
Document doc = new Document();
int rd = new Random().nextInt(10000);
doc.setTitle("公文编号" + rd);
doc.setContent("这是地球上第"+rd+"号红色文件!");
jcontext.getSession().save(doc);
Persistence.setVariable("docId", new Integer(doc.getId()));//暂存‘公文’id
//创建流程实例
//1.从数据库加载ProcessDefinition对象,GraphSession流程操作API
String pdName = (String)Persistence.getVariable("pdName");//从暂存读出
ProcessDefinition pdef = jcontext.getGraphSession().findLatestProcessDefinition(pdName);
//2.创建流程实例对象
ProcessInstance instance = new ProcessInstance(pdef);
jcontext.save(instance);
//3.公文对象和流程实例对象绑定
doc.setProcessInstanceId(instance.getId());
instance.getContextInstance().setVariable("docId", new Integer(doc.getId()));
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
/**
* 提交公文
*/
public void testSubmitDocument() {
try {
//获取公文id
Integer docId = (Integer)Persistence.getVariable("docId");
Document doc = (Document)jcontext.getSession().load(Document.class, docId);
//得到公文流程实例
long processInstanceId = doc.getProcessInstanceId();
ProcessInstance instance = jcontext.getProcessInstance(processInstanceId);
//只能执行一次,提交到下一节点
instance.signal();
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
/**
* 当前节点
*/
public void testCurrentNode() {
try {
//获取公文id
Integer docId = (Integer)Persistence.getVariable("docId");
Document doc = (Document)jcontext.getSession().load(Document.class, docId);
//得到公文流程实例
long processInstanceId = doc.getProcessInstanceId();
ProcessInstance instance = jcontext.getProcessInstance(processInstanceId);
System.err.println("公文 < Title:" + doc.getTitle() + "| Content: '" + doc.getContent() + "' >所处位置: " + instance.getRootToken().getNode().getName());
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
/**
* 查询用户的任务
*/
public void testTastList() {
try {
//已知用户
printTask(jcontext, "sam2011");
printTask(jcontext, "lam2011");
printTask(jcontext, "eavn2011");
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
private void printTask(JbpmContext jc, String uid) {
List tasks = jc.getTaskMgmtSession().findTaskInstances(uid);
for(Iterator iter = tasks.iterator(); iter.hasNext();) {
TaskInstance ti = (TaskInstance) iter.next();
Integer docId = new Integer(ti.getProcessInstance().getContextInstance().getVariable("docId").toString());
Document doc = (Document)jcontext.getSession().load(Document.class, docId);
System.err.println("公文 < Title:" + doc.getTitle() + "| Content: '" + doc.getContent() + "' > 对应用户: " + uid);
}
}
/**
* 提交任务
*/
public void testNextNode() {
try {
//已知用户
Integer docId = (Integer)Persistence.getVariable("docId");
//nextNode(jcontext, "sam2011", docId);
//nextNode(jcontext, "lam2011", docId);
nextNode(jcontext, "eavn2011", docId);
} catch(Exception e) {
e.printStackTrace();
jcontext.setRollbackOnly();//抛异常时,执行回滚;
} finally {
jcontext.close();
}
}
private void nextNode(JbpmContext jc, String uid, Integer dId) {
List tasks = jc.getTaskMgmtSession().findTaskInstances(uid);
for(Iterator iter = tasks.iterator(); iter.hasNext();) {
TaskInstance ti = (TaskInstance) iter.next();
Integer docId = new Integer(ti.getProcessInstance().getContextInstance().getVariable("docId").toString());
if(docId.equals(dId)) {
ti.end();//结束这个任务实例;触发对应的Token的signal()方法,即流向下一个环节
Document doc = (Document)jcontext.getSession().load(Document.class, docId);
System.err.println("公文 < Title:" + doc.getTitle() + "| Content: '" + doc.getContent() + "' > 已被用户: " + uid + "处理,提交到下一个环节");
}
}
}
}