Java camunda model validation

Hi,
I am using bpmn.io to generate XML, I want to write java code to validate this XML against common issues in the diagram (missing start, missing end, disconnected nodes, …)
What I could find that BpmnModelInstance.validate(ModelElementValidator collection) should do this, but I can’t find any implementations of this interface to choose what I need from.
Are there any implementation of this validator interface implemented by camunda or the community than I can use to make diagram validation ?
Thanks

Might be easier to just use the Camunda Lint Plugin. Wouldn’t require you having to code anything.

Thanks for your recommendation.
This seems a Javascript library, is there a similar library in java part ?
I know that Camunda BPM Engine makes such validations before executing the process, but can’t find if there is a re-usable code that can do this ?

Hi @zmadel,

you can hook into the engine’s validation with a parse-listener.

Have a look at this example for further details: camunda-bpm-examples/process-engine-plugin/bpmn-parse-listener-on-user-task at master · camunda/camunda-bpm-examples · GitHub.

Hope this helps, Ingo

@zmadel Hey, did you manage to export such validator as an standalone component after all?

@vicmosin
Yes, I found a good way to validate this

try {
    BpmnModelInstance bpmnModel = Bpmn.readModelFromStream(new ByteArrayInputStream(bpmnXMLBytes));
    Bpmn.validateModel(bpmnModel);
} catch (Exception e){
//Handle invalid code exceptions
}
1 Like