How to get the process definition diagram and process instance diagram via JAVA API?


#1

Hi,
I like to know how to get the process definition diagram and process instance diagram via JAVA API.

I tried getProcessDiagram in RepositoryService, but I got null. The doc says ‘null when the diagram resource name of a ProcessDefinition is null’, but what diagram resource name is? Where I can config the value for it?

I just wanted to display a diagram on the web page, then user can understand the process and current progress. No interaction is needed at this moment.

I also noticed that REST API can get the BPMN xml file and display it via bpmn.io with fully interaction features. But can I use JAVA API instead?

Thanks in advance for any help.


How to get diagram image through java api
#2

Hi @GhostFox,

Please see the post linked below. Although it talks about the rest API for getting the diagram, the explanations apply to the Java API you mention as well.

In general, we recommend retrieving the XML and rendering it with bpmn.io since it is much more powerful.

Cheers,
Thorben


#3

Thanks for the quick response.

  1. Retrieving the XML and rendering it with bpmn.io to display the diagram of process definition, is it correct?
  2. Is there any JAVA API to retrieve the XML file? Or I have to implement my own method? We don’t wanna mix the JAVA API and REST API usages.
  3. How to display the diagram of the process instance? Not the process definition. Process instance diagram is supposed to display the current progress, am I correct?

Thanks again for previous help.


#4

Hi @GhostFox,

  1. Yes, that is the way to go. In the bpmn-io context, bpmn-js is the library to look at.
  2. You can use RepositoryService#getProcessModel. In general, every REST API method is backed by a Java API method.
  3. There is no single API endpoint for that but you can render the XML returned by RepositoryService#getProcessModel and display process instance state returned by RuntimeService#getActivityInstance by using overlays on the process diagram. That is the way how we do this in Camunda Cockpit. If you have any questions on how to create overlays with bpmn-js, I recommend asking that on the bpmn-io forums

Cheers,
Thorben


#5

Thanks a lot for your supper quick and great answer. Really appreciated.