activiti根据流程实例id查询资源文件(xml、image)

本文介绍了一个基于部署ID读取流程定义资源的方法,包括XML配置文件和流程图图像资源。通过ProcessDefinitionId参数指定流程定义,resourceType参数选择资源类型(xml或image),最终将资源内容输出到客户端。
/**
 * 读取资源,通过部署ID
 *
 * @param processDefinitionId
 *            流程定义
 * @param resourceType
 *            资源类型(xml|image)
 * @throws Exception
 */
@RequestMapping(value = "/resource/read")
public void loadByDeployment(@RequestParam("processDefinitionId") String processDefinitionId,
        @RequestParam("resourceType") String resourceType, HttpServletResponse response){
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId).singleResult();

    String resourceName = "";
    if (resourceType.equals("image")) {
        resourceName = processDefinition.getDiagramResourceName();
    } else if (resourceType.equals("xml")) {
        resourceName = processDefinition.getResourceName();
    }
    InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
            resourceName);
    byte[] b = new byte[1024];
    int len = -1;
    try {
        while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
            response.getOutputStream().write(b, 0, len);
        }
    } catch (IOException e) {
        log.error("查询流程资源失败", e);
    }
}
Activiti7 中获取当前流程图,通常需要结合流程实例的信息动态生成流程图,这可以通过 `BpmnModel` 和 `ProcessDiagramGenerator` 类实现。以下是获取当前流程图的步骤和方法: 1. 获取流程实例信息 通过流程实例 ID 获取流程定义信息和当前活动节点信息。流程实例信息可以通过 `RuntimeService` 或 `HistoryService` 查询获取。 2. 获取 BpmnModel 通过 `RepositoryService` 获取流程定义相关的 `BpmnModel` 对象,该对象描述了 BPMN 文件的结构。 ```java BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId); ``` 3. 获取当前流程节点信息 查询当前流程实例的运行时信息,包括当前活动的节点 ID。可以通过 `RuntimeService` 获取当前流程实例的上下文信息。 4. 生成流程图 使用 `ProcessDiagramGenerator` 类生成流程图。在 Activiti7 中,`ProcessDiagramGenerator` 类已经被移出核心模块,需引入 `activiti-image-generator` 依赖: ```xml <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-image-generator</artifactId> <version>5.19.0.2</version> </dependency> ``` 生成流程图的核心代码如下: ```java ProcessDiagramGenerator diagramGenerator = new DefaultProcessDiagramGenerator(); InputStream imageStream = diagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds, Collections.emptyList(), "宋体", "宋体", "宋体", null, 1.0, false); ``` 其中: - `bpmnModel` 是从 `RepositoryService` 获取流程模型。 - `"png"` 表示生成的图片格式。 - `activeActivityIds` 是当前流程实例中尚未完成的节点列表。 - `Collections.emptyList()` 表示已完成的节点列表。 - 字体参数用于指定流程图中的字体。 - 最后两个参数控制缩放比例和是否高亮当前节点。 5. 返回流程图数据 将生成的流程图以 `InputStream` 形式返回,通常可以将其写入 HTTP 响应流中,以便前端展示。 通过上述步骤,可以动态生成当前流程实例流程图,帮助用户直观了解流程的执行状态[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值