jbpm4.4学习笔记(3)

[html]  view plain copy
  1. <span style="font-family: Arial, Helvetica, sans-serif;">经过上一节的学习,我们已经将真整个请假流程的部署,发起以及执行分配都集成到web应用中,这里我们要做的新工作是为我们之前发布的请假流程实现流程图的跟踪。</span>  

1、流程定义图片生成

流程定义的图片生成很简单,这个工作jbpm4已经帮我们完成了,所以我们只需要将编辑好的流程定义保存即可,如下图6-1所示:


图6-1 自动生成流程定义png图片

2、更改流程定义发布方式

为了要在web应用中显示流程图片,我们要将流程图片和流程定义一并的发布。

首先将leave.jpdl.xml和leave.png打包成leave.zip压缩文件。然后更改流程定义的发布方式,主要是更改deploy.jsp的源码

[html]  view plain copy
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <%@ page import="java.util.*,org.jbpm.api.*,java.util.zip.*" %>  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  5. <html>  
  6. <head>  
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  8. <title>Insert title here</title>  
  9. </head>  
  10. <body>  
  11.     <%  
  12.     ProcessEngine processEngine=Configuration.getProcessEngine();  
  13.     RepositoryService repositoryService=processEngine.getRepositoryService();  
  14.     //repositoryService.createDeployment().addResourceFromClasspath("leave.jpdl.xml").deploy();  
  15.     ZipInputStream zis = new ZipInputStream(this.getClass()  
  16.             .getResourceAsStream("/leave.zip"));  
  17.     repositoryService.createDeployment()  
  18.             .addResourcesFromZipInputStream(zis).deploy();  
  19.     response.sendRedirect("index.jsp");  
  20.     %>  
  21. </body>  
  22. </html>  

可以看到,我们是通过生成ZipInputStream对象,然后调用RepositoryService对象的相应流程部署函数完成的流程部署。

3、获取当前活动的task任务

我们主要通过view.jsp实现获得当前正在活动的任务,view.jsp的代码如下:

[html]  view plain copy
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <%@page import="org.jbpm.api.*,java.util.*,org.jbpm.api.model.*" %>  
  4. <%  
  5.     String id = request.getParameter("id");  
  6.     ProcessEngine processEngine = Configuration.getProcessEngine();  
  7.     RepositoryService repositoryService = processEngine.getRepositoryService();  
  8.     ExecutionService executionService = processEngine.getExecutionService();  
  9.     ProcessInstance processInstance = executionService.findProcessInstanceById(id);  
  10.     Set<String> activityNames = processInstance.findActiveActivityNames();  
  11.       
  12.     ActivityCoordinates ac = repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(),activityNames.iterator().next());  
  13. %>  
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  15. <html>  
  16. <head>  
  17. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  18. <title>Insert title here</title>  
  19. </head>  
  20. <body>  
  21. <img src="pic.jsp?id=<%=id %>" style="position:absolute;left:0px;top:0px;">  
  22. <div style="position:absolute;border:1px solid red;left:<%=ac.getX()%>px;top:<%=ac.getY()%>px;width:<%=ac.getWidth()%>px;height:<%=ac.getHeight()%>px;"></div>  
  23. </body>  
  24. </html>  
对于这段代码,作如下解释:

1)活动任务的相关属性获得

[html]  view plain copy
  1. //获得当前id对应的流程实例  
  2. ProcessInstance processInstance = executionService.findProcessInstanceById(id);  
  3. //或等当前流程实例的活动任务名称   
  4. Set<String> activityNames = processInstance.findActiveActivityNames();  
  5. //获得当前流程实例活动任务的坐标属性  
  6. ActivityCoordinates ac = repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(),activityNames.iterator().next());  

2)整体流程定义图片的显示

[html]  view plain copy
  1. <img src="pic.jsp?id=<%=id %>" style="position:absolute;left:0px;top:0px;">  
这里我们调用了pic.jsp其代码如下:

[html]  view plain copy
  1. <%@page import="org.jbpm.api.*,java.io.*"%>  
  2. <%  
  3.     ProcessEngine processEngine = Configuration.getProcessEngine();  
  4.     RepositoryService repositoryService = processEngine  
  5.             .getRepositoryService();  
  6.     ExecutionService executionService = processEngine  
  7.             .getExecutionService();  
  8.     String id = request.getParameter("id");  
  9.     //获得当前id对应流程实例  
  10.     ProcessInstance processInstance = executionService  
  11.             .findProcessInstanceById(id);  
  12.     //获得当前流程实例对应流程定义id  
  13.     String processDefinitionId = processInstance  
  14.             .getProcessDefinitionId();  
  15.     //根据流程定义id最终获得当前流程实例id对应的流程定义  
  16.     ProcessDefinition processDefinition = repositoryService  
  17.             .createProcessDefinitionQuery().processDefinitionId(  
  18.                     processDefinitionId).uniqueResult();  
  19.     //由流程定义或等当前流程定义对应的图片,并生成inputStream流显示出来  
  20.     InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),"leave.png");  
  21.     byte[] b = new byte[1024];  
  22.     int len = -1;  
  23.     while ((len = inputStream.read(b, 0, 1024)) != -1) {  
  24.         response.getOutputStream().write(b, 0, len);  
  25.     }  
  26. %>  

3)标记当前活动任务
[html]  view plain copy
  1. <div style="position:absolute;border:1px solid red;left:<%=ac.getX()%>px;top:<%=ac.getY()%>px;width:<%=ac.getWidth()%>px;height:<%=ac.getHeight()%>px;"></div>  

即在之前获得的当前活动任务对应坐标处绘制一个红色标记框。

4、程序运行效果

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值