Programmically transform subProcess into Process

Hello
I have a process which includes a subProcess which demonstrates a loop.
As camunda cannot deal with loop pattern of subProcess i need to transform the whole subProcess to a loop pattern like its mentioned in the docs. (XOR Gateway before , XOR Gateway After)

From this:

To this:

I want to do it programically so a java program reads in the input process and the output process should look like the example above.

Is there a simple way to transform a subprocess into the actual process?

For now i am saving the subProcess body into a list and then i delete everything and build it up newly from the referenced list but this very tricky when dealing with nested gateways.

I thought of a approach like only deleting the line “subProcess” within the xml file and then simply add a XOR before and after and connect it with incoming and outgoing flow of the subProcess. But i didn’t found a easy solution.

Anybody has an advice for me?
Best Regards
Sebastian

Hi Sebastian,

There are many ways to do this. Please help me to understand your question better:

You have an expanded subprocess and want to wrap it in a loop?
Why do you want to delete the subprocess?

Camunda’s BPMN Model library provides you with everything that you need to alter a model programmatically.

Here is a straightforward way of adding the loop:

  1. Find the Subprocess
  2. Find the incoming sequence flow
  3. Delete the sequence flow
  4. Add a XOR gateway (MERGE)
  5. Connect the predecessor(s) of the subprocess with the MERGE
  6. Connect the MERGE to the subprocess
  7. Find the subprocesse’s outgoing sequence flow
  8. Delete the sequence flow
  9. Add a XOR gateway (SPLIT)
  10. Connect the subprocess to the SPLIT
  11. Connect the SPLIT to the successor of the subprocess
  12. Connect the SPLIT to the MERGE.

The BPMN Model API places new elements to the right of the last element. So, you may want to do some simple auto layouting.

Layouting of a process (event with nested gateways) is easy if the process is block-structured, i.e., every opening gateway has a corresponding closing gateway. I can write some more about it, if this is of interest for you.

1 Like

Thanks for your answer.

I want to delete the subprocess because there is now way to represent a loop. It is only used to indicate that at this point there should be a loop so i have to delete and rebuild the structure.

Hm ok i have a block structured process so no worries here.
Ok i will try to go along this path.

I have one more question.
Can you explain best practise on how i can make layouting of a process (nested gateways) when its block structured. So, what would you say are the steps.

For now, i just copy all elements in a list and when i re build the process i go through each node and build it up. I have a second list which holds all split gateways followers and all join gateway previous nodes. So in each iteration i check if the actual node is a follower in this list and then i know that i have to form a new branch (e.g. when i have parallel gateways). The same for join gateways so here i check if the actual node is in the list of the previous nodes, if it is then attach it to the join gateway. Then i have a full block created… next iteration if needed. …

How would you do that?

Thanks i found a way.
I take the subprocess and run through each element and simply add the elements to the (parent) process, also flows are no problem.
Now, only have to change the start and event or just replacing it with my desired gateways to form a loop,
Thanks anyway for you help, really appreciate. :slight_smile:

1 Like