Import of XML with custom elements fails - some elements not getting drawn


#1

Hello,

I extended the metamodel of the bpmn with some new elements. Modeling and outputting xml works perfect. However, if I try to import a previously saved xml-file, some elements are not getting drawn.

My code is located here: https://github.com/koseduhemak/bpmn-js-clinical-pathways
The metamodel extension is located in the file “app/clinical-pathways/ext-metamodel/CPMetamodel.json”.

The problem occurs f.e. with “StructuredDocument”. That element can hold multiple sub elements of type “Segment” (which can hold other “Segment”-elements recursively). It should work as bpmn’s “SubProcess”-element, which can also hold sub-elements. During modeling everything seems to be working fine, even the xml output is correct. But if I import a saved diagram with nested elements like described above, only the first “StructuredDocument” (without sub elements) is drawn. I tried to derive it from “bpmn:FlowElementsContainer” (to match the “bpmn:SubProcess” definition), but had no luck.

But it also occurs with “CPResource”, if i derive it only from “bpmn:Resource”. If I derive it from “bpmn:Resource” AND “bpmn:FlowElement” it gets drawn correctly at the import.

My xml output of my test diagram: cp-import-problem.bpmn (3.5 KB)

My test diagram:

I digged a little further and recognized, that “bpmn-js/lib/import/BpmnTreeWalker.js” is responsible for importing elements… But it is very hard to understand that file… Maybe I have to write an custom TreeWalker which processes my elements and takes care of the sub-elements?

Do you have any tips how to solve this problem?

Thank you,
mfuesslin


#2

Quick answer before we dig into details:

If you want to stay BPMN 2.0 compliant, you must serialize custom eements outside the BPMN XML (i.e. via additional data you fetch from a web service). That data can be inlined, too. But that needs to happen as part of a BPMN extension point, i.e. bpmn:extensionElements (cf. commenting example).

Your XML looks like as if you’d like to replace BPMN with a custom modeling notation that supports cp natively. If that is the case you’d indeed need to

  • Extend the BPMN meta-model to support your extensions.
  • Override / Replace the BPMN tree walker to recognize these types, too.
  • Add additional rules to handle your types.

If you got some sort of minimal test case that showcases your issue, please point us to it and we may have a look.


#3

The tree walker makes sure elements are drawn in the right order during import. New elements that are outside the BPMN meta-model would need to get patched into it.