cancel
Showing results for 
Search instead for 
Did you mean: 

Display current task within a process instance

mikepoole
Champ in-the-making
Champ in-the-making
I think this question has been asked before but I have never managed to track down an answer

Is there any way to display the process diagram AND show which task the user is currently on. I have seen mention of the ProcessDiagramImageGenerator API but cannot find anything that shows the way to show the current task

Any help would be very much appreciated

Many thanks

Mike
11 REPLIES 11

frederikherema1
Star Contributor
Star Contributor
Use this:


public static InputStream generateDiagram(ProcessDefinitionEntity processDefinition, String imageType, List<String> highLightedActivities) {

Example usage in activiti-explorer code:


ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstance
            .getProcessDefinitionId());

    if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
     
      InputStream definitionImageStream = ProcessDiagramGenerator.generateDiagram(processDefinition, "png",
        runtimeService.getActiveActivityIds(processInstance.getId()));

The Example is working fine…

Can we export the active task diagram
ie. i have a large process diagram, so don't want to export the whole diagram, instead i wish if it is possible to export the cropped digram that shows only active task with surrounding tasks only…

Thank you

mikepoole
Champ in-the-making
Champ in-the-making
Thanks Frederik

When I attempt to run this code…

ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  RepositoryService repositoryService = processEngine.getRepositoryService();
  ProcessDefinitionQuery processDefQ = repositoryService.createProcessDefinitionQuery().processDefinitionKey("ProcessDEADLINE");

  System.out.println("Count: " + processDefQ.count());

  for(ProcessDefinition p: processDefQ.list()){
   if(p.getVersion() == processDefQ.count()){
    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processDefinitionId(p.getId()).singleResult();

    InputStream is = ProcessDiagramGenerator.generateDiagram((ProcessDefinitionEntity) p, "png", runtimeService.getActiveActivityIds(pi.getId()));
    OutputStream out = new FileOutputStream(new File("C:\\Mike data\\Diagram.png"));

    int read = 0;
    byte[] bytes = new byte[1024];
    while ((read = is.read(bytes)) != -1) {
     out.write(bytes, 0, read);
    }

    is.close();
    out.flush();
    out.close();

   }
  }

I get the following error…

Exception in thread "main" 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:166)
at org.activiti.engine.impl.bpmn.diagram.ProcessDiagramGenerator.generateDiagram(ProcessDiagramGenerator.java:236)
at org.iop.production.ProcessDiagramImageGenerator.main(ProcessDiagramImageGenerator.java:38)

I have checked my XML file (created via the Eclipse plugin) and it appears that all elements have a name and x and y co-ordinates and the XML has all the DI information

What am I doing wrong?

Many thanks

Mike

frederikherema1
Star Contributor
Star Contributor
Please use the code I gave you, not sure this is causing the issue you mention, but it's the way you should use it:


ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstance
            .getProcessDefinitionId());

Using the query to obtain a processDefinition doesn't initialize in internal activity-structure, rather it's just a entity representing database-row…

how I can set variable processInstance? ProcessInstance processInstance = ???

mikepoole
Champ in-the-making
Champ in-the-making
Frederik,

That is absolutely superb!!!! Works like a dream

(I was trying to also find my way round the Engine API and whole relationships so I seemed to just cherry pick the bits I thought I needed from your code! Won't make that mistake again!)

Many many thanks

Mike

fchatzia
Champ in-the-making
Champ in-the-making
Frederic i tried to use this* code but RepositoryServiceImpl is not recognized as a class what am i missing?


ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstance
            .getProcessDefinitionId());

frederikherema1
Star Contributor
Star Contributor
This class is part of activiti-engine, otherwise it wouldn't work.. What import are you using? the class is in org.activiti.engine.impl.RepositoryServiceImpl

fchatzia
Champ in-the-making
Champ in-the-making
Thank you very much frederik for the 
immediate answer, i suppose that eclipse has a bad day and doesn't make suggestions. When i import the class you wrote the problem was solved.