Deploying / Adding DMN in Modeler App Programmatically

Hi,

I used the below Java code to create and deploy the DMN Programmatically,
It is stored in ACT_DMN_DEPLOYMENT and ACT_DMN_DEPLOYMENT_RESOURCE table, Here I am able to execute and see it in “Admin App” also.

But I need the same in flowable UI, “Modeler App” ( For Decisions )
Is there any API to deploy / Add in DMN Modeler Programmatically (i,e ACT_DE_MODEL table ),

Can anyone please help me here ?

String jsonStr = "{\"key\":\"pravinTest\",\"name\":\"Pravin Test\",\"hitIndicator\":\"FIRST\",\"inputExpressions\":[{\"entries\":null,\"id\":\"input1\",\"label\":\"Input 1\",\"type\":\"string\",\"variableId\":\"input1\",\"variableType\":\"variable\"}],\"outputExpressions\":[{\"entries\":null,\"id\":\"user\",\"label\":\"User\",\"type\":\"string\",\"variableId\":\"user\",\"variableType\":\"variable\"}],\"rules\":[{\"input1\":\"A\",\"user\":\"pravin\"}]}";
JsonNode JsonNode = OBJECT_MAPPER.readTree(jsonStr);
DmnDefinition dmnDefinition = new DmnJsonConverter().convertToDmn(JsonNode, "pravinTest", 1, new Date());
DmnRepositoryService dmnRepositoryService = dmnEngine.getDmnRepositoryService();
DmnDeployment dmnDeploymentId = dmnRepositoryService.createDeployment().name("pravinTest")
				.category("Pravin-Test").addDmnModel("pravinTest.dmn", dmnDefinition).deploy();

So you need to import the DMN model to modeler. = Have a look on the model import code.

Regards
Martin

Hi @martin.grofcik ,

Are you suggesting to Import the DMN using Flowable UI ?

But my requirement is I have to deploy / Add the DMN in Flowable UI (Modeler App) using Java Code
and I have to view the the same using flowable UI (Modeler App).

Please share me if you have any references.

Thanks,
Pravin Kumar.

Hi @pravinpsa

What @martin.grofcik was referring to was the code.

Have a look here.

You basically convert the DMN Model to Json. Use that to create a (modeler) model and persist that.

Regards,

Yvo

Hi @yvo,

From that reference code you shared I have constructed the below code and it worked.

DmnDecision decision = dmnRepositoryService.createDecisionQuery()
		.decisionKey("pravinTest").latestVersion().singleResult();
DmnDefinition outputDmnDefinition = dmnRepositoryService.getDmnDefinition(decision.getId());
JsonNode outputJsonNode = new DmnJsonConverter().convertToJson(outputDmnDefinition);
String jsonEditor = OBJECT_MAPPER.writeValueAsString(outputJsonNode);
List<Model> filterModel = modelRepository.findByKeyAndType("pravinTest",
		AbstractModel.MODEL_TYPE_DECISION_TABLE);
if (null != filterModel && !filterModel.isEmpty()) {
	Model model = filterModel.get(0);
	model.setName("Pravin Test");
	model.setDescription("Test Descrption");
	model.setModelEditorJson(jsonEditor);
	model.setVersion( model.getVersion() + 1 );
	modelService.saveModel(model);
} 
else {
	ModelRepresentation modelRepresentation = new ModelRepresentation();
	modelRepresentation.setName("Pravin Test");
	modelRepresentation.setKey("pravinTest");
	modelRepresentation.setDescription("Test Descrption ");
	modelRepresentation.setModelType(AbstractModel.MODEL_TYPE_DECISION_TABLE);
	modelRepresentation.setTenantId("1");
	modelService.createModel(modelRepresentation, jsonEditor, "admin");
}

Thanks for your reference,

1 Like

Hi @pravinpsa

good to hear that!
And thanks for providing the feedback here…

Regards,

Yvo