JBPM4.4显示流程图片

阅读更多
发布流程,网上几乎都是用zip来部署流程,太过繁琐,其实只要添加流程图片的Resource就可以了。
repositoryService.createDeployment()
    .addResourceFromClasspath("process/recruiment.jpdl.xml")
    .addResourceFromClasspath("process/recruiment.png")
    .deploy();

action接收processInstance的Id,得到流程图,并在当前activity上画框,来显示流程走到哪里。
ProcessInstance processInstance = executionService
.findProcessInstanceById(pid);

String processDefinitionId = processInstance.getProcessDefinitionId();
ProcessDefinition processDefinition = repositoryService
.createProcessDefinitionQuery().processDefinitionId(
processDefinitionId).uniqueResult();

Set 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处理没有集成的可以修改成原有路径

	
		image/png
		inputStream
	


调用起来就很简单了


运行结果:
JBPM4.4显示流程图片_第1张图片
  • JBPM4.4显示流程图片_第2张图片
  • 大小: 26.2 KB
  • 查看图片附件

你可能感兴趣的:(jbpm4.4,java,流程图)