cancel
Showing results for 
Search instead for 
Did you mean: 

Get bpmn20.xml programmatically

tomdc
Champ in-the-making
Champ in-the-making
I would like to get a list of all possible usertasks from a specific workflow.

Since I couldn't find any function to do this out of the box, I would like to get the definition xml and parse it myself.
Is there a way to get the bpmn20.xml programmatically?
5 REPLIES 5

mhw
Champ in-the-making
Champ in-the-making
Hi,

I am not shure if I understand you right. If you have deployed your resources you can list all with:

   List<ProcessDefinition> processDefinitions = repositoryService
     .createProcessDefinitionQuery()
     .list();
  
  
   for (ProcessDefinition processDefinition : processDefinitions) {
    if (logger.isLoggable(Level.INFO)) {
     logger.info("Process "
       + processDefinition.getKey() + " is deployed and defined in "
       + processDefinition.getResourceName());
    }
   }
Best regards,
Michael

tomdc
Champ in-the-making
Champ in-the-making
Hi MHW,

I'll try to be a bit more clear.

After I deployed a process (with the *.bar file) I would like to get all the userTask of this process
Example:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:smileysurprised:mgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:smileysurprised:mgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="SimpleTask" name="SimpleTask">
    <documentation>Place documentation for the 'SimpleTask' process here.</documentation>
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="User Task" activiti:candidateGroups="management"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process> ….

In this example I would get only one userTask: "usertask1".

I don't think there is a function where I can get the list of all usertasks. The workaround for this would be that I parse the content of the process : file.bpmn20.xml. 

What I need is a way to extract the process file (file.bpmn20.xml

I hope this clarifies…

mhw
Champ in-the-making
Champ in-the-making
Hi,

ok, I understand. We work with plain .bpmn20.xml files. As far as I know, .bar files are zip files, too. So you could probably do this:
http://www.java-tips.org/java-se-tips/java.util.zip/how-to-extract-file-files-from-a-zip-file-3.html
Can't you?

Best regards,
Michael

tomdc
Champ in-the-making
Champ in-the-making
That's indeed a workaround

Thanks for the feedback

ingo_ri
Champ in-the-making
Champ in-the-making
Hi,

you can get the deployed process template out of the database:

org.activiti.engine.repository.Deployment myDeployment = repositoryService.createDeploymentQuery().deploymentName("TemplateAuslesenTest.testReadDeployment").singleResult();
InputStream is = repositoryService.getResourceAsStream(myDeployment.getId(), "de/ingo/activiti/beispiel/TemplateAuslesenTest.testReadDeployment.bpmn20.xml");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String processDefinitionXML = "";
String line;
do {
line = br.readLine();
        if (line != null) {
  processDefinitionXML = processDefinitionXML + line;
}
} while (line != null);

Maybe there is a shorter way to get the String out of the Stream, but this old fashioned code works fine 😉

Kind Regards,

Ingo