jBPM-jPDL学习笔记 - 流程设计与控制- jBPM3.1.4 下载本文

内容发布更新时间 : 2024/12/22 20:50:46星期一 下面是文章的全部内容请认真阅读。

ti.getToken().getNode().getLeavingTransitions();//获取任务在当前节点上的所有转向。

这里我们要特别指出的是ti.end(\部门经理审批通过\和ti.end(\部门经理驳回\这实际上调用token.signal(transition);来完成任务的转向,从而使流程继续。

5. 总经理审批申请 Java代码

1. /**

2. * 总经理审批 3. * @param pass 4. */

5. @SuppressWarnings(\

6. protected void approveByPresident(boolean pass){

7. System.out.println(\President()==\

8. Iterator it = pi.getTaskMgmtInstance().getTaskInstances().iterator(); 9.

10. for( ;it.hasNext(); ){

11. TaskInstance ti = it.next(); 12. if(ti.getActorId().equals(\13. List transitions = ti.getToken().getNode().getLeavingTransitions();

14. for(Transition t : transitions){

15. System.out.println(\.getName());

16. }

17. assertEquals(\

18. if(pass){

19. ti.end(\总经理审批通过\20. }else{

21. ti.end(\总经理驳回\22. }

23. return; 24. } 25. } 26.}

代码说明:

此步代码同“部门经理审批”代码相似,不作更多说明。

标准流程测试案例

该案例模拟了标准运行环境中,基于关系型数据库的jBPM系统是如何执行流程的。

测试案例类:FirstFlowProcessDBTest.java Java代码

1. public class FirstFlowProcessDBTest { 2. /*

3. * 初始化jBPM配置

4. * 包含对Hibernate的数据库初始化 5. */

6. static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();

7. public static void main(String[] args){

8. FirstFlowProcessDBTest test = new FirstFlowProcessDBTest();

9. test.test4000YuanApplication(); 10. test.test6000YuanApplication(); 11. test.test7000YuanApplication(); 12. } 13.

14. public void test4000YuanApplication(){

15. ProcessInstance pi = createProcessInstance(\16. submitApplication(\4000); 17. approveByManager(true); 18. checkTasks(pi); 19. }

20. public void test6000YuanApplication() {

21. ProcessInstance pi = createProcessInstance(\22. submitApplication(\6000); 23. approveByManager(true); 24. approveByPresident(true); 25. checkTasks(pi); 26. }

27. public void test7000YuanApplication() {

28. ProcessInstance pi = createProcessInstance(\29. submitApplication(\7000); 30. approveByManager(true); 31. approveByPresident(false); 32. checkTasks(pi); 33. } 34. /**

35. * 生成流程实例 36. */

37. protected ProcessInstance createProcessInstance(String user){

38. System.out.println(\sInstance()==\

39. JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); 40. try {

41. GraphSession graphSession = jbpmContext.getGraphSession();

42. /*

43. * 从数据库获取指定的流程定义 44. */

45. ProcessDefinition pdf = graphSession.findLatestProcessDefinition(\46. //生成流程实例

47. ProcessInstance pi = pdf.createProcessInstance();

48. //设置流程发起人

49. pi.getContextInstance().createVariable(\, user);

50. //触发流程转向 51. pi.signal(); 52. /*

53. * 保存流程实例 54. */

55. jbpmContext.save(pi); 56. return pi; 57. }finally{

58. jbpmContext.close(); 59. } 60. } 61. 62. /**

63. * 填写提交申请单 64. * @param money 65. */

66. @SuppressWarnings(\

67. protected void submitApplication(String actorId , int money){

68. System.out.println(\ation()==\

69. JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();

70. try { 71. /*

72. *根据操作者ID,获取属于该操作者的任务集 73. */

74. List taskInstances = jbpmContext.getTaskList(actorId);

75. for(TaskInstance ti : taskInstances){

76. System.out.println(\;

77. System.out.println(\d());

78. ContextInstance ci = ti.getContextInstance();

79. ci.setVariable(\80. ti.end(); 81. } 82. }finally{

83. jbpmContext.close(); 84. } 85. } 86. 87. /**

88. * 部门经理审批 89. * @param pass 90. */

91. @SuppressWarnings(\

92. protected void approveByManager(boolean pass){ 93. System.out.println(\ager()==\

94. JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); 95. try{

96. List taskInstances = jbpmContext.getTaskList(\

97. for(TaskInstance ti : taskInstances){ 98. System.out.println(\;

99. System.out.println(\d());

100. if(pass){

101. ti.end(\部门经理审批通过\

102. }else{

103. ti.end(\部门经理驳回\104. } 105. }

106. }finally{

107. jbpmContext.close(); 108. } 109. } 110. 111. /**

112. * 总经理审批 113. * @param pass 114. */

115. @SuppressWarnings(\

116. protected void approveByPresident(boolean pass){ 117. System.out.println(\ByPresident()==\

118. JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); 119. try{

120. List taskInstances = jbpmContext.getTaskList(\

121. for(TaskInstance ti : taskInstances){

122. System.out.println(\me());

123. System.out.println(\ctorId());

124. if(pass){

125. ti.end(\总经理审批通过\126. }else{

127. ti.end(\总经理驳回\128. } 129. }

130. }finally{

131. jbpmContext.close(); 132. } 133. } 134. 135. /**

136. * 打印任务记录 137. */

138. @SuppressWarnings(\

139. protected void checkTasks(ProcessInstance pi){