Does anyone know if there’s a relatively easy way to create and manage DMN tables programmatically?
For example, I create and deploy a DMN table as usual. I then want to add a rule to it without going through Modeler or the Cockpit GUI. In other words, I want to treat it sort of like a database table where I can add, insert, modify, etc. without having to point and click through a graphical interface or manually modify the underlying XML. I should emphasize that I want to do this in the Camunda server itself, not separately and then redeploy it.
The Java docs don’t make it clear if you can do this or not. I do realize that I could crack open the bpmn.io library as that obviously has the ability to hook into existing tables. But I was hoping there was an easier way.
Im looking into this myself. The approach Im taking is to get the DMN XML model via an API, use an XML library (eg Spin) to add rules to the model, then redeploy using an API.
Does this sound like it would work for you?
Yeah, I knew I could do that. If we break open something like the Excel to DMN converter, we would see how the tables are constructed and go from there. I suppose conceptually it wouldn’t matter.
Moreover, what would one do if the DMN table were scattered amongst disconnected Camunda instances? It’s probably better to pull a master, modify, validate, and push. If you automate all that, which isn’t terribly difficult, then from a user standpoint it wouldn’t matter whether you did it via a fancy, local Java API call or just rebuilt the thing in one place and deployed it via the REST interface.
We were speculating about what it would take to build a database to DMN dynamic interface where the DMN would be backed by a database which you could manipulate with all the available tools,but which the engine could use to do its evaluation. That’s probably a stupid idea given the caching and optimization Camunda have already done.
However, I told my boss I would investigate what could be done programmatically. Our challenge is that you can’t restrict a user to modification of individual rules through the Camunda authorization system. Therefore, we’d have to build a front end that allow them only to modify rules that they should have access to. And yes, I know, we could create separate tables and secure each resource, but then you have a “normalization” problem where you have 20 tables all containing the same type of data and rules, divided up just for access control.
My Java and EE knowledge isn’t anywhere near what yours is, but my intuition says something like this should be possible. I just wondered if Camunda had already done something to facilitate it.
Similar to BPMN and CMMN, there is the DMN model API for Java. It is undocumented at this time aside from Javadoc (follow https://app.camunda.com/jira/browse/CAM-5522). That is also what the Excel-to-DMN converter uses. The principles it works by are the same as in the BPMN and CMMN model APIs. There is no fluent builder, though. The entry class is org.camunda.bpm.model.dmn.Dmn.
Hello Michael and Rob,
to fill the gap from the missing documentation I attach and example I built a while ago: DmnModelCreator.java.txt (6.4 KB)
It’s a simple java main method and creates a decison table from scratch. In the end, the decision is evaluated.
Hope this helps,
Does the model support “on-the-fly” modification of existing, deployed, DMN table? Or, must we modify it separately and redeploy it? I suppose the there’s little difference here in terms of the effect it has.
You have to catch the table from the deployment, create a model from it (
Dmn.createModelFromInputStream()), change it and redeploy it to the engine.
There is no API to change to the model on the fly.
Das freut mich nicht! =-(
(Not sure I got the article correct here, it’s been 30 years since I’ve used my German daily).
Your German is correct.
To do this completely automatically, your can build a process that changes the dmn table (read it, change it, deploy it) and start this process either by a timer start event or by some message event, that gets fired if your database table changes (which would be much more work to do).
Yup, this is precisely what Im doing apart from I was using XML DOM manipulation over an API based model builder…
I’m working on a PHP solution:
Feel free to use it or improve it
We have code to programmatically alter a DMN table file via the Java API. However, as I learned, you cannot alter an active DMN table dynamically. You must download the table, modify it, then upload the new version.
Good luck with your PHP solution, however.
I know this is old post but wanted to get some help on how to modify the DMN decisions “on the fly”… I am looking for similar feature in Camunda cockpit to manage the DMN during the runtime without redeploying the whole process. Could you please provide some more details on how you are currently handling.
Unless things have changed, you cannot modify a DMN table dynamically. The only way I know of to update a DMN table is to modify a separate copy of that table and then deploy it “over” the existing DMN table file.
I believe the reason for this is that the DMN table is cached by Camunda to increase performance, and thus must be wholly replaced when updated. Other more knowledgeable than myself may correct me here.
Deployment of DMN tables is usually very fast. I don’t think you should be concerned about processes not being able to use the table.
Internally, we have created tools to manage DMN tables, but they all still require the resulting update to be deployed.
Got it. Thanks for your response.
I am looking for this ,could you please attach your full code here.
I followed your example and was able to programmatic create my DMN XML file. However, I have difficult to figure out how to add “InputData” and “informationRequirement” elements to my DMN model. The following is a simple example:
<inputData id="_id" name="name"> </inputData>
<decision id="Decision_T1" >
<informationRequirement> <requiredInput href="_id" /> </informationRequirement>
Can you post more sample code?
When I use the following code:
I get the following error message:
org.camunda.bpm.model.xml.ModelException: New child is not a valid child element type
Is it possible to share the code to programmatically alter a DMN table file via the Java API ?
I also have same requirement to dynamically update rules in DMN table and also update DRD flows.
Can someone share sample code for implementing this programmatically in Java API?