如题,网上搜了一段生成流程图的代码,却找不到ProcessDiagramGenerator类。
搜了下,是说,ProcessDiagramGenerator这个类已经移出来了,单独是一个依赖。
在此: http://mvnrepository.com/artifact/org.activiti/activiti-image-generator
那么,在Pom.xml中增加
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-image-generator</artifactId> <version>5.19.0.2</version> </dependency>
即可。
写法也有点变化,原来是静态方法调用,现在得new一个了。
代码大概是这样:
@RequestMapping("getPiImage") public void xx(String processInstanceId, HttpServletResponse response) throws IOException { if (processInstanceId == null) { throw new ActivitiIllegalArgumentException( "No process instance id provided"); }
ExecutionEntity pi = (ExecutionEntity) runtimeService .createProcessInstanceQuery() .processInstanceId(processInstanceId).singleResult();
if (pi == null) { throw new ActivitiObjectNotFoundException( "Process instance with id" + processInstanceId + " could not be found", ProcessInstance.class); }
ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) .getDeployedProcessDefinition(pi.getProcessDefinitionId());
if (pde != null && pde.isGraphicalNotationDefined()) { BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId()); ProcessDiagramGenerator ge = new DefaultProcessDiagramGenerator(); InputStream resource = ge.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstanceId), new ArrayList<String>(), "宋体", "宋体", null, 1.0d);
int len = 0; byte[] b = new byte[1024]; while ((len = resource.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); }
} else { throw new ActivitiException("Process instance with id " + processInstanceId + " has no graphic description"); }
}
|