cancel
Showing results for 
Search instead for 
Did you mean: 

Process image

franklin
Champ in-the-making
Champ in-the-making
Hi all,

Is it possible to get the process image with current situation of the process?
I mean, get the image process showing the current task with diferent color?

I know that is possible to get the process imagem by this code:

ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                                                  .processDefinitionKey(processDefinitionName).singleResult();

      String diagramResourceName = processDefinition.getDiagramResourceName();
      InputStream  imageStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);

But it always bring me the image without show the current task with diferent color.

Thank you all.
18 REPLIES 18

trademak
Star Contributor
Star Contributor
Sure,

ProcessDiagramGenerator.generateDiagram(pde, "png", getRuntimeService().getActiveActivityIds(processInstanceId));

Best regards,

franklin
Champ in-the-making
Champ in-the-making
Thank you trademak.

Let me ask you one more thing…
How can I get the pde object? I search inside documentation and I don't find anything about it.

Thanks again.

gant
Champ in-the-making
Champ in-the-making
Hi,

Trying the same with:

String processDefinitionId = taskService.createTaskQuery().taskId(getCurrentTaskId()).singleResult().getProcessDefinitionId();
  String executionId = taskService.createTaskQuery().taskId(getCurrentTaskId()).singleResult().getExecutionId();
  
  InputStream imageStream = ProcessDiagramGenerator.generateDiagram((ProcessDefinitionEntity)repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult(), "png", runtimeService.getActiveActivityIds(executionId));

This ends up with the following Exception:

Caused by: java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(IntegerInterleavedRaster.java:450)
at java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1156)
at org.activiti.engine.impl.bpmn.diagram.ProcessDiagramCanvas.generateImage(ProcessDiagramCanvas.java:164)
at org.activiti.engine.impl.bpmn.diagram.ProcessDiagramGenerator.generateDiagram(ProcessDiagramGenerator.java:220)
at ch.itartis.engine.ui.ApproveRequestBean.getProcessImage(ApproveRequestBean.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:246)
at javax.faces.component.UIGraphic.getValue(UIGraphic.java:105)
at org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:39)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:672)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1483)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:281)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
… 13 more

Then I tried this (to make sure, that it's nothing to do with the 'AcitveActivities':

InputStream imageStream = ProcessDiagramGenerator.generatePngDiagram((ProcessDefinitionEntity)repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult());
and received:

java.awt.image.RasterFormatException: (x + width) is outside raster
at sun.awt.image.IntegerInterleavedRaster.createWritableChild(IntegerInterleavedRaster.java:450)
at java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1156)
at org.activiti.engine.impl.bpmn.diagram.ProcessDiagramCanvas.generateImage(ProcessDiagramCanvas.java:164)
at org.activiti.engine.impl.bpmn.diagram.ProcessDiagramGenerator.generateDiagram(ProcessDiagramGenerator.java:220)
at org.activiti.engine.impl.bpmn.diagram.ProcessDiagramGenerator.generatePngDiagram(ProcessDiagramGenerator.java:199)
at ch.itartis.engine.ui.ApproveRequestBean.getProcessImage(ApproveRequestBean.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:246)
at javax.faces.component.UIGraphic.getValue(UIGraphic.java:105)
at org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:39)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:672)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:668)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1483)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:281)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
… 13 more

I defined my process model with Activiti Designer 5.7, created the deployment artifacts there and deployed the BAR programmatically (engine-version 5.6). It all works, except the image.

Checked my xml-file (according to this: http://forums.activiti.org/en/viewtopic.php?f=6&t=1045&hilit=java.awt.image.RasterFormatException%3A...). I have named all elements, including the edges. All shapes have coords and width/hight, the edges have all the waypoints needed.

Find the XML attached.

Regards,
michael

gant
Champ in-the-making
Champ in-the-making
Hi,

I debuged on this and found out:

The processDiagramCanvas returned from ProcessDiagramGenerator.generateDiagram() has canvasWidth & canvasHeight of 10. This is beacause ProcessDefinitionEntity.getActivities() returns an empty list.

Any suggestions?

Regards,
michael

trademak
Star Contributor
Star Contributor
Hi,

The code should be something like:

String processDefinitionId = taskService.createTaskQuery().taskId(getCurrentTaskId()).singleResult().getProcessDefinitionId();
String processInstanceId = taskService.createTaskQuery().taskId(getCurrentTaskId()).singleResult().getProcessInstanceId();
        
InputStream imageStream = ProcessDiagramGenerator.generateDiagram((ProcessDefinitionEntity)repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult(), "png", runtimeService.getActiveActivityIds(processInstanceId));

Best regards,

gant
Champ in-the-making
Champ in-the-making
Hi,

this is exactely the Code I have, tried it also with copy&paste of yours, it still is the same problem. While debugging, I saw, my process has 20 activities while parsing, but the ProcessDefinitionEntity I recieve here has an empty list.

Regards,
michael

rmbiplob
Champ in-the-making
Champ in-the-making
Really nice…

dgr0me
Champ in-the-making
Champ in-the-making
With workaround, I managed to get image. Problem is when repositoryService is queried for processDefinition, processDefinitionEntity don't have initialized activities.

'Solution':
final ReadOnlyProcessDefinition processDefinitionEntity =
          ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(historicProcessInstance.getProcessDefinitionId());
      in = ProcessDiagramGenerator.generateDiagram(
          (ProcessDefinitionEntity)processDefinitionEntity,
          "png",
          runtimeService.getActiveActivityIds(processId));

gant
Champ in-the-making
Champ in-the-making
Hi,

I have this working now using code similar to dGr0me. But the image is not rendered correctly:
- The business rules task is missing (there is just some empty space, the sequences are drawn correctly
- Some of the sequence flows do not connect to the correct anchor. They connect to the center of the bottom of the shape instead to the center of the left side.

I'm using version 5.7 of the engine and 5.7.1 of the designer.

regards,
michael