Creating decision table from json in java and deploying it

I have created decision table in java using Decision Table (dmn.model.DecisionTable). But couldn’t figure out how to convert this decision table to xml (.dmn) or inputstream so that it can be deployed with dmnRepositoryService. Can you help on how to achieve this?

Hi,

If you want to create the model programmatically you need to create a DmnDefinition.
You can then deploy that directly using the dmnRepositoryService;

repositoryService.createDeployment()
    .name("Deployment of DMN definition")
    .addDmnModel(dmnDefinition)
    .deploy();

Hope this helps.

Regards,

Yvo

Hi,

But how to add the decision table to dmnDefinition ?

Regards,

Madhu

I assume that when you’re creating a DecisionTable in Java you have knowledge of the DMN Model.
Otherwise I suggest you use the Decision Table editor in Flowable Modeler to create the table and export it to DMN (model) XML. You can use that to deploy it to the engine.

Regards,

Yvo

Hi,

What i was trying to achieve is, handling creating the decision table in the UI and saving that table as json in DB. When there are any new decision table created I will get JSON and create decision table in the backend and try to deploy it. I have tried to create dmnDefinition using DmnXMLConverter().convertToDmnModel() but it asking for inputstreamprovider or XMLstreamReader as an input. I have no idea on how to pass decision table here.

Regards,
Madhu

When you have the editor JSON you can convert that DMN model using the DmnJsonConverter

DmnDefinition DmnJsonConverter.convertToDmn(JsonNode modelNode)

You can then deploy the DMN model.
The DmnJsonConverter is for converting between DMN model (/DmnDefinition) and editor JSON model.
The DmnXMLConverter is for converting between DMN XML en DMN model

Perhaps looking at some unit test code for these 2 projects will help you on how to use these apis.

Yvo

Hi,
Thanks for the suggestion, is there a proper format for the JsonNode which it accepts?

Thanks,
Madhu

Not sure I understand your question correctly; but the JsonNode represents the JSON structure of the decision table in the decision table editor in Flowable Modeler.
For example;

Regards,

Yvo

1 Like

Hi Yvo,

Thanks for the help, this works fine

Regards,
Madhu