Discover Camunda BPMN using Go

Salvatore Gonda
5 min readJan 26, 2021

I wrote about, which tools I explored in my first story at the beginning of my journey through the world of BPMN. From the developer perspective, it is important writing down his own thoughts, to find out which way leaded to the solution. As a plus, it keeps me updated and I’ve learned something new, some valuable functionalities, data structures, worthy patterns and so on.

Introduction

I wanted to build a simple .bpmn file in Go and take the Camunda Modeler XML as my master copy. This file describes the document structure and is ready to use for the Camunda Modeler (or other). At the end of this article you’ll find a link to my Github repository. It can have changes, which aren’t documented in this article.

Camunda Modeler XML

The Camunda Modeler is based on bpmn.io (https://bpmn.io), a single web-based tooling for BPMN, DMN and CMMN. And bpmn.io is brought to you by Camunda. The Modeler is the integrated modeling solution for BPMN, DMN and CMMN. I took their informations from their Twitter- and Github Account, the site as self was not reachable at the moment I’ve written this article. So far, I took a look at their repositories on Github and recognized, that the Camunda Modeler was written in React and uses Electron for their Desktop UI.

DMN and CMMN is actually not in my focus. I want to know more about BPMN from the technical perspective. I chose that form of learning, because while I’m writing I commit it to my memory. Integrating graphical elements is a nice way to build workflows fast, but to do it with a better understanding, it’s always a good idea to expose the technique behind. When I open the Camunda Modeler I’ve got a prototype of a diagram, which is in a tab. I can switch to the XML Schema by pushing the other tab and see the whole document structure. First I realize were the XSD elements and self-closing tags and thought:

“Go has a build-in XML package, but not for XSD”

I searched for packages, who had build all the functionalities I need for my study, but I couldn’t find anyone, who fits in my code actually. And I was at the beginning. It was clear to me to build the ground structure from scratch using structs. A look at the given XML file:

That looks quite simple to reproduce and so build for each element a struct to model it with their setter methods. I have one main model, which I named “Definitions” and represents the “bpmn:definitions” element. The “Definitions”-model contains to other models, the “Diagram”-model contains the “Plane”-model. Some attributes having “omitempty” in their tag declaration. That’s, because they weren’t set when I start the application. The “Xsd”-field, which represent the namespace element “XML Schema”, wasn’t defined by the Camunda Modeler. I implemented it, just in case I’ll need in the future.

Definitions Model:

Process Model:

“Name” and “CamundaVersionTag” attributes were set explicit to the “Process”-struct, but they can be set implicit by the Modeler, if I fill them with values directly in the application. Both are also tagged with “omitempty”, because the first roll out in the Modeler doesn’t have them. “IsExecutable” is always set to true, when I open the app, so I insert a static value in the setter method.

Diagram Model:

Plane Model:

Some of the setters have a suffix as string, others have just integers, which I typed as 64bit. For the suffixes, I copied a hash generator out of a “StackOverflow” thread (tbh), who creates a 32-bit FNV-1a hash. I copied the code into utils directory in a file with the name “generator.go” and changed the sum of byte slices. I realized, that the id attribute in the “bpnm:process” has the same suffix like in the “bpmndi:BPMNPlane” tag, the “element”-attribute. Another suffix int the first element represents his own hash suffix for the attribute “id”.

Hash Generator

Pretty neat. That went fast and it does, what it should. Now I need a repository to fetch all the setter methods and to create the .bpmn-file with the values of choice. I created a directory with the name “repository” and insert a file, which I named “bpmnf.go”.

The first is a global variable for a counter, then a struct literal, which I composite with the field “Def”, typed as“Definitions”-model. Then I created a constructor, who points to the struct literal. When initialized, the constructor counts the files in the dir and assigned it to “counter”.

There is only one way to pass by value in Go, which is determined in the “Set”-method. The “Create”-method then marshal the “Def”-field into XML, adds a header, creating the file with the counter as suffix and writes the byte slice to the file. If no error, the method returns <nil>. “cVersionTag” represents the Camunda Version Tag for this element, which is empty (and not set as a attribute in the “diagram_*.bpmn”-file. Also the name attribute stays empty at first and isn’t set in the Modeler, when you start with it.

At least, I can execute my package right in my VSCode Terminal with “go run main.go”. To do this, I created the “main.go”-file in the root of the repository at Github. I defined the go routine “main” and called the “BPMNF”-repository.

Working with VSCode

Red Hat Company maintains a BPMN extension, which you can install here:

When I created the file, I tried to open it directly in VSCode, which resulted directly to this view:

So, you can also start to model here your workflow, which I didn’t test.

Summary

I build a package, just to create a file, but had a lot of impact for my knowledge. It’s not about making the perfect package, it’s about the journey I will take. BPMN is a wide field to discover. It’s more than a diagram to build for marketing options.

Conclusion

My second story is about the same theme like in the first, but now I added some Go to prove myself. Just with a simple command, I can create a diagram file out of my repository. I have some more ideas to implement in the future, like more options for the shell. You can find more thoughts and documentary in the “README.md”-file at Github. More PDF-files to read are in the “docs”-directory.

Check my repository at Github, leave a star and follow me:
https://github.com/deemount/gobpmn

--

--