Activiti 并发实例流程图的显示


1.写在前面:
activiti中并发后的活动任务节点通过runtimeService.getActiveActivityIds(String proInstId)得到。
这个方法在Activiti的doc文档中介绍的不对,它错把参数写成了executionId,而事实上,一个流程实例(对应流程实例编号ProInstId)在运行中通过并发节点产生多个执行任务(对应执行编号executionId)。
2.关键代码:
ProcessInstanceAction.java

Java代码
public class ProcessInstanceAction extends BaseAction {
     private List<ActivityImpl> actImpls = new ArrayList<ActivityImpl>(); 
        public List<ActivityImpl> getActImpls() { 
          return actImpls;
       }
         public void setActImpls(List<ActivityImpl> actImpls) {
           this.actImpls = actImpls;
       }
     /** 
     * 显示流程图
      *
      * @return
      * @throws Exception
      */      
public String getProcessPic() throws Exception { 
          // String taskId =          // "2901";//getRequest().getParameter("taskId");3016,552,3020          
String procDefId = getRequest().getParameter("procDefId"); 
          ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
           String diagramResourceName = procDef.getDiagramResourceName(); 
          InputStream imageStream = repositoryService.getResourceAsStream(procDef.getDeploymentId(), diagramResourceName);
           getRequest().setAttribute("inputStream", imageStream);
           return SUCCESS; 
      }         
/**
      * 获取跟踪信息
      *
       * @return
      * @throws Exception
      */     
 public String getProcessMap() throws Exception {
           String procDefId = getRequest().getParameter("procDefId");  
           String proInstId = getRequest().getParameter("procInstId"); 
          ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery().processDefinitionId(procDefId) .singleResult(); 
            ProcessDefinitionImpl pdImpl = (ProcessDefinitionImpl) processDefinition;
           String processDefinitionId = pdImpl.getId();// 流程标识            ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(processDefinitionId); 
            List<ActivityImpl> activitiList = def.getActivities();// 获得当前任务的所有节点
            /****/         
 List<String> ActiveActivityIds = runtimeService.getActiveActivityIds(proInstId); 
          for (String activeId : ActiveActivityIds) {
                 for (ActivityImpl activityImpl : activitiList) { 
                  String id = activityImpl.getId();
                   if (activityImpl.isScope()) { 
                        if (activityImpl.getActivities().size() > 1) {
                           List<ActivityImpl> subAcList = activityImpl                                   .getActivities(); 
                          for (ActivityImpl subActImpl : subAcList) {                               String subid = subActImpl.getId(); 
                              System.out.println("subImpl:" + subid); 
                              if (activeId.equals(subid)) {// 获得执行到那个节点
                                  actImpls.add(subActImpl);
                                   break; 
                              }
                           } 
                      } 
                    }  
                 if (activeId.equals(id)) {// 获得执行到那个节点
                        actImpls.add(activityImpl); 
                      System.out.println(id);  
                 } 
              } 
          } 
          /****/  
            return SUCCESS;
       }
   }  




pic.jsp
Html代码

<%@page import="java.io.InputStream"%> 
 <%@page import="org.activiti.engine.impl.*"%>  
<%@page import="org.activiti.engine.impl.pvm.*"%> 
 <%@page import="org.activiti.engine.impl.pvm.process.*"%>
  <%@page import="org.activiti.engine.repository.*"%>  
<%@page import="org.activiti.engine.*"%>  
<%@ page language="java" contentType="text/html; charset=UTF-8"      pageEncoding="UTF-8"%>   
 <%              
      InputStream is = (InputStream)request.getAttribute("inputStream"); 
      byte[] b = new byte[1024]; 
      int len = -1; 
      while((len = is.read(b, 0, 1024)) != -1) {
           response.getOutputStream().write(b, 0, len);  
         // 防止异常:getOutputStream() has already been called for this response           out.clear();
           out = pageContext.pushBody();
       }        %> 

showImg.jsp
Html代码
<%@page import="java.io.InputStream"%>  
<%@page import="org.activiti.engine.impl.*"%> 
 <%@page import="org.activiti.engine.impl.pvm.*"%>
  <%@page import="org.activiti.engine.impl.pvm.process.*"%> 
 <%@page import="org.activiti.engine.repository.*"%>  
<%@page import="org.activiti.engine.*"%> 
 <%@ page language="java" pageEncoding="UTF-8"%> 
 <%@ taglib prefix="s" uri="/struts-tags"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html> 
 <head>
      <title>
</title> 
 </head> 
 <body> 
     <div > 
         <img src="getProcessPic.action?procDefId=${procDefId}" style="position:absolute; left:0px; top:0px;">
      <s:iterator value="actImpls"> 
     <%System.out.println("lala"); %> 
                  <!-- 给执行的节点加框 --> 
         <div style="position:absolute; border:2px solid red;left:${x-1 }px;top:${y-1 }px;width:${width }px;height:${height }px;"></div>
          </s:iterator> 
     </div> 
   </body>
  </html>  

另附:环境配置struts+activiti:
struts.xml


Xml代码

<?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE struts PUBLIC   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   "http://struts.apache.org/dtds/struts-2.0.dtd">  <struts> 
     <constant name="struts.objectFactory.spring.autoWire" value="name" />      <constant name="struts.objectFactory" value="spring" />      
<package name="default" extends="struts-default"> 
     <action name="getProcessPic" class="processInstanceAction" method="getProcessPic"> 
             <result name = "success" >/incident/pic.jsp</result>
          </action>
          <action name="getProcessMap" class="processInstanceAction" method="getProcessMap">
              <result name = "success" >/incident/showImg.jsp</result> 
         </action> 
 </package>
  </struts>  
 



你可能感兴趣的:(Activiti)