首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

activiti 范例流程图的显示方法

2012-07-04 
activiti 实例流程图的显示方法所谓实例流程图的显示,就是显示流程图的同时,高亮显示正在执行的节点。有两

activiti 实例流程图的显示方法
所谓实例流程图的显示,就是显示流程图的同时,高亮显示正在执行的节点。有两种方法
直接生成带老亮节点的图片:

        try{//            ProcessDefinitionEntity pde = (ProcessDefinitionEntity) RepositoryService//            .getDeployedProcessDefinition(procDefId);         InputStream imageStream =         ProcessDiagramGenerator.generateDiagram(         def, "png",         runtimeService.getActiveActivityIds(executionId));         List<Task> list = taskService.createTaskQuery().processInstanceId(executionId).orderByTaskId().desc().list();         int size = list.size();         getRequest().setAttribute("inputStream", imageStream);        }catch(RasterFormatException e){            e.printStackTrace();        }

img.jsp
<%@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 responseout.clear();out = pageContext.pushBody();}%>

方法2: 图片和高亮节点圈分别产生
/** * 显示流程图 * @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 executionId = getRequest().getParameter("executionId");        ProcessDefinition processDefinition = repositoryService                .createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();        ProcessDefinitionImpl pdImpl = (ProcessDefinitionImpl) processDefinition;        String processDefinitionId = pdImpl.getId();// 流程标识        ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)                .getDeployedProcessDefinition(processDefinitionId);        ActivityImpl actImpl = null;        ExecutionEntity execution = (ExecutionEntity) runtimeService                .createExecutionQuery().executionId(executionId).singleResult();// 执行实例        String activitiId = execution.getActivityId();// 当前实例的执行到哪个节点//        List<String>activitiIds = runtimeService.getActiveActivityIds(executionId);                List<ActivityImpl> activitiList = def.getActivities();// 获得当前任务的所有节点//        for(String activitiId : activitiIds){        for (ActivityImpl activityImpl : activitiList) {            String id = activityImpl.getId();            if (id.equals(activitiId)) {// 获得执行到那个节点                actImpl = activityImpl;                break;            }        }//        }        getRequest().setAttribute("coordinateObj", actImpl);        getRequest().setAttribute("procDefId",procDefId );        return SUCCESS;    }

pic.jsp
<%@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 responseout.clear();out = pageContext.pushBody();}%>

showImg.jsp
<%@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"%><!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;"> <!-- 给执行的节点加框 --> <div style="position:absolute; border:2px solid red;left:${coordinateObj.x-1 }px;top:${coordinateObj.y-1 }px;width:${coordinateObj.width }px;height:${coordinateObj.height }px;"></div> </div></body></html>

struts.xml
<action name="getProcessPic" method="getProcessPic"><result name = "success" >/incident/pic.jsp</result></action><action name="getProcessMap" method="getProcessMap"><result name = "success" >/incident/showImg.jsp</result></action>

需要注意的是,当你的流程图中存在并发节点时需要用到runtimeService.getActiveActivityIds(proInstId)得到多个活动节点。


这个方法可以在activiti的帮助文档中找到,但它的原文中是getActiveActivityIds(String executionId)(执行ID)这是错的,因为在数据库的_ru_task表(运行任务表)中,执行ID与任务记录一一对应,但可以存在多个流程实例Id相同的任务记录。


鉴于第一种方法形成的流程图太丑,采用第二种方法最好!
*********************格叽格叽*******************************
孔雀东南飞…有情人还是共饮一江水的吧!

热点排行