JBPM4.4 使用非zip方式发布流程 实现流程图加载

时间:2022-01-07 18:07:03
JBPM4.4 显示流程图片,需要携带流程图发布;这样大多数是采用打包zip方式来部署流程,太过繁琐;所以我采用如下方式发布流程
RepositoryService repositoryService=  processEngine.getRepositoryService();
        NewDeployment deploy= repositoryService.createDeployment();
        deploy.addResourceFromClasspath("newSite.jpdl.xml")
        .addResourceFromClasspath("newSite.png");

action接收processInstanceId,(一般情况下processInstanceId与ExecutionId相同)得到流程图,并在当前activity上画框,来显示流程走到哪里。

public String showImage(){
		ProcessInstance processInstance = executionService  
				.findProcessInstanceById(pid);  
				  
				String processDefinitionId = processInstance.getProcessDefinitionId();  
				ProcessDefinition processDefinition = repositoryService  
				.createProcessDefinitionQuery().processDefinitionId(  
				processDefinitionId).uniqueResult();  
				  
				Set<String> activityNames = processInstance.findActiveActivityNames();  
				BufferedImage image = null;  
				  
				for (String activityName : activityNames) {  
				    ActivityCoordinates ac = repositoryService.getActivityCoordinates(  
				    processInstance.getProcessDefinitionId(), activityName);  
				  
				    InputStream is = repositoryService.getResourceAsStream(  
				    processDefinition.getDeploymentId(), processDefinition  
				    .getImageResourceName());  
				  
				    image = ImageIO.read(is);  
				    Graphics g = image.getGraphics();  
				    g.setColor(new Color(255, 0, 0));  
				  
				    g.drawRect(ac.getX(), ac.getY(), ac.getWidth(), ac.getHeight());  
				    g.dispose();  
				}  
				  
				ByteArrayOutputStream output = new ByteArrayOutputStream();  
				ImageIO.write(image, "PNG", output);  
				ByteArrayInputStream input = new ByteArrayInputStream(output  
				.toByteArray());  
				this.setInputStream(input);  
				return SUCCESS;
	}
structs里面配置result为stream类型,class交给spring处理没有集成的可以修改成原有路径

<action name="processImage" class="processImageAction">  
    <result type="stream">  
        <param name="contentType">image/png</param>  
        <param name="inputName">inputStream</param>  
    </result>  
</action>
jsp页面显示
<img src="processImage.action?pid=<s:property value='id'/>"/>