首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

JBPM4失去所有已经完成节点的主数据类以及数据记录信息(转)

2013-07-08 
JBPM4得到所有已经完成节点的主数据类以及数据记录信息(转)转自http://pdd7531.iteye.com/blog/1392305找

JBPM4得到所有已经完成节点的主数据类以及数据记录信息(转)

转自http://pdd7531.iteye.com/blog/1392305

找了好久的得到流程中所有已完成ActivityInstance信息的实现方式,结果没找到相关的思路,就试着自己实现了下,发现有点复杂,一个下午才搞定。。。诶,啥时候才能达到如丝袜般顺滑的写代码。。。?

????? 为了完成得到流程中所有已经完成的ActivityInstance的信息,主要思路为先寻找所有父流程的所有ActivityInstance的信息,再寻找兄弟节点的ActivityInstance的信息,最后寻找所有子流程的ActivityInstance的信息。?

Java代码??JBPM4失去所有已经完成节点的主数据类以及数据记录信息(转)
  1. /**?
  2. ????*?<p>Description:?当前节点外键与已经执行完毕的节点自动关联.</p>?
  3. ????*?<p>Author:?PanDuanDuan</p>?
  4. ????*?@param?relationColumns?所有外键?
  5. ????*?@param?piId?当前流程Id?
  6. ????*?@param?processInstanceService?流程实例操作Service?
  7. ????*?@param?processEngine?流程引擎?
  8. ????*?@param?formReader?流程表单控制?
  9. ????*?<p>Date:?2012-2-3</p>?
  10. ????*/??
  11. ????public?void?autoMakeContent(List<Column>?relationColumns,?String?executionId,??
  12. ????????????ProcessInstanceService?processInstanceService,??
  13. ????????????ProcessEngine?processEngine,?XmlFormReader?formReader)?{??
  14. ????????Map<String,String>?result?=?new?HashMap<String,String>();??
  15. ????????//向上寻找??找到所有父类的节点?信息??
  16. ????????result?=?getParentTableIdAndDataId(executionId,processInstanceService,processEngine,result);??
  17. ????????//得到流程历史Service??
  18. ????????HistoryService?historyService?=?processEngine.getHistoryService();??
  19. ????????//得到Excution的Service??
  20. ????????ExecutionService?executionService?=?processEngine.getExecutionService();??
  21. ????????//得到已经完成的所有节点??
  22. ????????List<HistoryActivityInstance>?historyActivityInstances?=?historyService.createHistoryActivityInstanceQuery().executionId(executionId).list();??
  23. ????????//得到当前的Execution??
  24. ????????Execution?execution?=?executionService.findExecutionById(executionId);??
  25. ????????//递归寻找父Execution直至主流程??
  26. ????????Execution?parentExecution?=?execution.getParent();??
  27. ????????String?tempExecutionId?=?executionId;??
  28. ????????while(null?!=?parentExecution)??
  29. ????????{??
  30. ????????????//找到当前节点的兄弟节点??
  31. ????????????Collection<??extends?Execution>?sons?=?parentExecution.getExecutions();??
  32. ????????????if(sons.size()?>?1)??
  33. ????????????{??
  34. ????????????????for(Execution?son?:?sons)??
  35. ????????????????{??
  36. ????????????????????String?sonExecutionId?=?son.getId();??
  37. ????????????????????if(!tempExecutionId.equals(sonExecutionId))??
  38. ????????????????????{??
  39. ????????????????????????historyActivityInstances.addAll(historyService.createHistoryActivityInstanceQuery().executionId(sonExecutionId).list());??
  40. ????????????????????}??
  41. ????????????????}??
  42. ????????????}??
  43. ????????????historyActivityInstances.addAll(historyService.createHistoryActivityInstanceQuery().executionId(parentExecution.getId()).list());??
  44. ????????????tempExecutionId?=?parentExecution.getId();??
  45. ????????????parentExecution?=?parentExecution.getParent();??
  46. ????????}??
  47. ??????????
  48. ????????HistoryActivityInstanceImpl?haiImpl?=?null;??
  49. ????????//遍历所有节点??找出tableId??以及??dataId??
  50. ????????for(HistoryActivityInstance?historyActivityInstance?:?historyActivityInstances)??
  51. ????????{??
  52. ????????????haiImpl?=?(HistoryActivityInstanceImpl)historyActivityInstance;??
  53. ????????????String?type?=?haiImpl.getType();??
  54. ????????????if("task".equals(type))??
  55. ????????????{??
  56. ????????????????String?taskName?=?haiImpl.getActivityName();??
  57. ????????????????XmlForm?xmlForm?=?formReader.getFormByName(taskName);??
  58. ????????????????String?tableId?=?xmlForm.getTableid();??
  59. ????????????????ProcessInstance?proIns?=?(ProcessInstance)?executionService.findExecutionById(haiImpl.getExecutionId()).getProcessInstance();??
  60. ????????????????String?dataId?=?CommonTools.Obj2String(executionService.getVariable(proIns.getId(),?tableId));??
  61. ????????????????if(!result.containsKey(tableId)?&&?!"".equals(dataId))??
  62. ????????????????{??
  63. ????????????????????result.put(tableId,?dataId);??
  64. ????????????????}??
  65. ????????????}else?if("sub-process".equals(type))??
  66. ????????????{??
  67. ????????????????String?subName?=?haiImpl.getActivityName();??
  68. ????????????????String?acExecutionId?=?haiImpl.getExecutionId();??
  69. ????????????????ProcessInstance?proIns?=?(ProcessInstance)?executionService.findExecutionById(acExecutionId).getProcessInstance();??
  70. ????????????????String?subPiId?=?processInstanceService.getSubPiId(proIns.getId(),?subName);??
  71. ????????????????//向下寻找??找到所有子流程的节点信息??
  72. ????????????????result?=?getSubTableIdAndDataId(subPiId,processInstanceService,processEngine,result);??
  73. ????????????}??
  74. ????????}??
  75. ??????????
  76. ????}??
  77. ??????
  78. ????/**?
  79. ????*?<p>Description:?得到所有子流程的tableId??以及??dataId.</p>?
  80. ????*?<p>Author:?PanDuanDuan</p>?
  81. ????*?@param?subPiId?
  82. ????*?@param?processInstanceService?
  83. ????*?@param?processEngine?
  84. ????*?@param?result?
  85. ????*?@return?
  86. ????*?<p>Date:?2012-2-3</p>?
  87. ????*/??
  88. ????private?Map<String,?String>?getSubTableIdAndDataId(String?subPiId,??
  89. ????????????ProcessInstanceService?processInstanceService,??
  90. ????????????ProcessEngine?processEngine,?Map<String,?String>?result)?{??
  91. ????????try{??
  92. ????????????//得到流程历史Service??
  93. ????????????HistoryService?historyService?=?processEngine.getHistoryService();??
  94. ????????????//得到executionService??
  95. ????????????ExecutionService?executionService?=?processEngine.getExecutionService();??
  96. ????????????//得到流程定义ID??
  97. ????????????String?pdId?=?executionService.findProcessInstanceById(subPiId).getProcessDefinitionId();??
  98. ????????????//得到FormReader??
  99. ????????????RepositoryService?repositoryService?=?processEngine.getRepositoryService();??
  100. ????????????//?得到流程定义??
  101. ????????????ProcessDefinition?processDefinition?=?repositoryService.createProcessDefinitionQuery().processDefinitionId(pdId)??
  102. ????????????????????.uniqueResult();??
  103. ????????????String?deploymentId?=?repositoryService.createProcessDefinitionQuery().processDefinitionId(pdId).list().get(0)??
  104. ????????????????????.getDeploymentId();??
  105. ????????????//?通过图片名获得form.xml文件名??
  106. ????????????String?imageName?=?processDefinition.getImageResourceName();??
  107. ????????????String?fileName?=?imageName.replace(".png",?"_form.xml");??
  108. ????????????//?得到文件输入流??
  109. ????????????InputStream?in?=?repositoryService.getResourceAsStream(deploymentId,?fileName);??
  110. ????????????//?解析xml文档??
  111. ????????????XmlFormReader?formReader?=?new?XmlFormReader(in);??
  112. ????????????//得到已经完成的所有节点??
  113. ????????????List<HistoryActivityInstance>?historyActivityInstances?=?historyService.createHistoryActivityInstanceQuery().processInstanceId((subPiId)).list();??
  114. ????????????HistoryActivityInstanceImpl?haiImpl?=?null;??
  115. ????????????//遍历所有节点??找出tableId??以及??dataId??
  116. ????????????for(HistoryActivityInstance?historyActivityInstance?:?historyActivityInstances)??
  117. ????????????{??
  118. ????????????????haiImpl?=?(HistoryActivityInstanceImpl)historyActivityInstance;??
  119. ????????????????String?type?=?haiImpl.getType();??
  120. ????????????????if("task".equals(type))??
  121. ????????????????{??
  122. ????????????????????String?taskName?=?haiImpl.getActivityName();??
  123. ????????????????????XmlForm?xmlForm?=?formReader.getFormByName(taskName);??
  124. ????????????????????String?tableId?=?xmlForm.getTableid();??
  125. ????????????????????String?dataId?=?CommonTools.Obj2String(executionService.getVariable(haiImpl.getExecutionId(),?tableId));??
  126. ????????????????????if(!result.containsKey(tableId)?&&?!"".equals(dataId))??
  127. ????????????????????{??
  128. ????????????????????????result.put(tableId,?dataId);??
  129. ????????????????????}??
  130. ????????????????}else?if("sub-process".equals(type))??
  131. ????????????????{??
  132. ????????????????????String?subName?=?haiImpl.getActivityName();??
  133. ????????????????????String?acExecutionId?=?haiImpl.getExecutionId();??
  134. ????????????????????ProcessInstance?proIns?=?(ProcessInstance)?executionService.findExecutionById(acExecutionId).getProcessInstance();??
  135. ????????????????????String?subSubPiId?=?processInstanceService.getSubPiId(proIns.getId(),?subName);??
  136. ????????????????????//向下寻找??找到所有子流程的节点信息??
  137. ????????????????????result?=?getSubTableIdAndDataId(subSubPiId,processInstanceService,processEngine,result);??
  138. ????????????????}??
  139. ????????????}??
  140. ????????}catch?(Exception?e)?{??
  141. ????????????e.printStackTrace();??
  142. ????????}??
  143. ????????return?result;??
  144. ????}??
  145. ??
  146. ????/**?
  147. ????*?<p>Description:?得到所有父流程的tableId??以及??dataId.</p>?
  148. ????*?<p>Author:?PanDuanDuan</p>?
  149. ????*?@param?executionId?
  150. ????*?@param?processInstanceService?
  151. ????*?@param?processEngine?
  152. ????*?@param?result?
  153. ????*?@return?
  154. ????*?<p>Date:?2012-2-3</p>?
  155. ????*/??
  156. ????public?Map<String,String>?getParentTableIdAndDataId(String?executionId,?ProcessInstanceService?processInstanceService,?ProcessEngine?processEngine,?Map<String,String>?result)??
  157. ????{??
  158. ????????//得到Excution的Service??
  159. ????????ExecutionService?executionService?=?processEngine.getExecutionService();??
  160. ????????Execution?execution?=?executionService.findExecutionById(executionId);??
  161. ????????//递归寻找父Execution直至主流程??
  162. ????????Execution?parentExecution?=?execution.getParent();??
  163. ????????while(null?!=?parentExecution)??
  164. ????????{??
  165. ????????????if(null?!=?parentExecution.getParent())??
  166. ????????????{??
  167. ????????????????parentExecution?=?parentExecution.getParent();??
  168. ????????????}else??
  169. ????????????????break;??
  170. ????????}??
  171. ????????//主的执行Id??防止分支??
  172. ????????String?mainExecutionId?=?null==parentExecution?executionId:parentExecution.getId();??
  173. ????????//存放所有父流程??
  174. ????????List<ProcessInstance>?fatherProcessInstances?=?new?ArrayList<ProcessInstance>();??
  175. ????????ProcessInstance?fatherProcessInstance?=?processInstanceService.getParentProcessInstance(mainExecutionId);??
  176. ????????//循环查找所有父流程??
  177. ????????while(null?!=?fatherProcessInstance)??
  178. ????????{??
  179. ????????????fatherProcessInstances.add(fatherProcessInstance);??
  180. ????????????fatherProcessInstance?=?processInstanceService.getParentProcessInstance(fatherProcessInstance.getId());??
  181. ????????}??
  182. ????????//如果存在父流程??
  183. ????????if(fatherProcessInstances.size()>0)??
  184. ????????{??
  185. ????????????for(ProcessInstance?processInstance?:?fatherProcessInstances)??
  186. ????????????{??
  187. ????????????????result.putAll(getTableIdAndDataIdByProcessInstance(processInstance,processInstanceService,processEngine));??
  188. ????????????}??
  189. ????????}??
  190. ????????return?result;??
  191. ????}??
  192. ??????
  193. ????/**?
  194. ????*?<p>Description:?根据流程实例??得到所有的tableId??以及??dataId.</p>?
  195. ????*?<p>Author:?PanDuanDuan</p>?
  196. ????*?@param?processInstance?
  197. ????*?@param?processInstanceService?
  198. ????*?@param?processEngine?
  199. ????*?@return?Map<tableId,dataId>?
  200. ????*?<p>Date:?2012-2-3</p>?
  201. ????*/??
  202. ????public?Map<String,String>?getTableIdAndDataIdByProcessInstance(ProcessInstance?processInstance,?ProcessInstanceService?processInstanceService,?ProcessEngine?processEngine)??
  203. ????{??
  204. ????????Map<String,String>?result?=?new?HashMap<String,String>();??
  205. ????????try{??
  206. ????????????String?pdId?=?processInstance.getProcessDefinitionId();??
  207. ????????????//得到流程历史Service??
  208. ????????????HistoryService?historyService?=?processEngine.getHistoryService();??
  209. ????????????//得到Excution的Service??
  210. ????????????ExecutionService?executionService?=?processEngine.getExecutionService();??
  211. ????????????//得到已经完成的所有节点??
  212. ????????????List<HistoryActivityInstance>?historyActivityInstances?=?historyService.createHistoryActivityInstanceQuery().processInstanceId(processInstance.getId()).list();??
  213. ????????????//得到FormReader??
  214. ????????????RepositoryService?repositoryService?=?processEngine.getRepositoryService();??
  215. ????????????//?得到流程定义??
  216. ????????????ProcessDefinition?processDefinition?=?repositoryService.createProcessDefinitionQuery().processDefinitionId(pdId)??
  217. ????????????????????.uniqueResult();??
  218. ????????????String?deploymentId?=?repositoryService.createProcessDefinitionQuery().processDefinitionId(pdId).list().get(0)??
  219. ????????????????????.getDeploymentId();??
  220. ????????????//?通过图片名获得form.xml文件名??
  221. ????????????String?imageName?=?processDefinition.getImageResourceName();??
  222. ????????????String?fileName?=?imageName.replace(".png",?"_form.xml");??
  223. ????????????//?得到文件输入流??
  224. ????????????InputStream?in?=?repositoryService.getResourceAsStream(deploymentId,?fileName);??
  225. ????????????//?解析xml文档??
  226. ????????????XmlFormReader?formReader?=?new?XmlFormReader(in);??
  227. ????????????//遍历所有节点??找出tableId??以及??dataId??
  228. ????????????HistoryActivityInstanceImpl?haiImpl?=?null;??
  229. ????????????for(HistoryActivityInstance?historyActivityInstance?:?historyActivityInstances)??
  230. ????????????{??
  231. ????????????????haiImpl?=?(HistoryActivityInstanceImpl)historyActivityInstance;??
  232. ????????????????String?type?=?haiImpl.getType();??
  233. ????????????????//只有是任务的节点??才读取tableId??以及??dataId??
  234. ????????????????if("task".equals(type))??
  235. ????????????????{??
  236. ????????????????????String?taskName?=?haiImpl.getActivityName();??
  237. ????????????????????XmlForm?xmlForm?=?formReader.getFormByName(taskName);??
  238. ????????????????????String?tableId?=?xmlForm.getTableid();??
  239. ????????????????????ProcessInstance?proIns?=?(ProcessInstance)?executionService.findExecutionById(haiImpl.getExecutionId()).getProcessInstance();??
  240. ????????????????????String?dataId?=?CommonTools.Obj2String(executionService.getVariable(proIns.getId(),?tableId));??
  241. ????????????????????if(!result.containsKey(tableId))??
  242. ????????????????????{??
  243. ????????????????????????result.put(tableId,?dataId);??
  244. ????????????????????}??
  245. ????????????????}??
  246. ????????????}??
  247. ????????}catch?(Exception?e)?{??
  248. ????????????e.printStackTrace();??
  249. ????????}??
  250. ????????return?result;??
  251. ????}??

?

热点排行