1、发布流程:流程定义文件+流程图,打成zip包一起发布
ProcessEngine processEngine=Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); ZipInputStream zis=new ZipInputStream(this.getClass().getResourceAsStream("/leave.zip"));
repositoryService.createDeployment().addResourcesFromZipInputStream(zis).deploy();
2、从流程实例中获取流程图生成显示(pic.jsp)
<%@ page import="org.jbpm.api.*,java.io.*" %> <% ProcessEngine processEngine=Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); ExecutionService executionService=processEngine.getExecutionService(); String id=request.getParameter("id"); ProcessInstance processInstance=executionService.findProcessInstanceById(id); String processDefinitionId=processInstance.getProcessDefinitionId(); ProcessDefinition processDefinition=repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).uniqueResult(); InputStream inputStream=repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), "leave.png"); byte[] b=new byte[1024]; int len=-1; while((len=inputStream.read(b,0,1024)) != -1) { response.getOutputStream().write(b, 0, len); } %>
3、显示流程图,当前活动环节用绿色方框框住,如最上面的图所示
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.util.*,org.jbpm.api.*,org.jbpm.api.task.*,org.jbpm.api.model.*" %> <% String id=request.getParameter("id"); ProcessEngine processEngine=Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); ExecutionService executionService=processEngine.getExecutionService(); ProcessInstance processInstance=executionService.findProcessInstanceById(id); Set<String> activityName=processInstance.findActiveActivityNames(); ActivityCoordinates ac=repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(), activityName.iterator().next()); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>查看流程图</title> </head> <body style="background-color:red;"> <img src="pic.jsp?id=<%=id %>" style="position:absolute;left:0px;top:0px;"/> <div style="z-index:2;position:absolute;border:1px solid green;left:<%=ac.getX() %>px;top:<%=ac.getY() %>px;width:<%=ac.getWidth() %>px;height:<%=ac.getHeight() %>px;"></div> </body> </html>