# Deploying / Adding DMN in Modeler App Programmatically

**URL:** https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518
**Category:** Flowable Engine
**Created:** [July 11, 2022, 3:10pm UTC](https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518 "2022-07-11T15:10:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pravinpsa](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@pravinpsa](https://forum.flowable.org/u/pravinpsa)
#### Post date: [July 11, 2022, 3:10pm UTC](https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518/1 "2022-07-11T15:10:11Z")

</div>

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 ),

 ![Flowable UI - DMN](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/a/a42df5350f369578aa6cf3f0e80d428af7fa37db.png)

Can anyone please help me here ?

```auto
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();

```

---

<div class="post-metadata">

### Author: ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)
#### Post date: [July 13, 2022, 1:27pm UTC](https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518/2 "2022-07-13T13:27:35Z")

</div>

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

Regards  
Martin

---

<div class="post-metadata">

### Author: ![pravinpsa](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@pravinpsa](https://forum.flowable.org/u/pravinpsa)
#### Post date: [July 13, 2022, 2:40pm UTC](https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518/3 "2022-07-13T14:40:53Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [July 13, 2022, 3:19pm UTC](https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518/4 "2022-07-13T15:19:11Z")

</div>

Hi @pravinpsa

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

Have a look [here](https://github.com/flowable/flowable-engine/blob/main/modules/flowable-ui/flowable-ui-modeler-logic/src/main/java/org/flowable/ui/modeler/service/AppDefinitionImportService.java#L315).

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

Regards,

Yvo

---

<div class="post-metadata">

### Author: ![pravinpsa](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@pravinpsa](https://forum.flowable.org/u/pravinpsa)
#### Post date: [July 20, 2022, 1:11pm UTC](https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518/5 "2022-07-20T13:11:25Z")

</div>

Hi @yvo,

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

```auto
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,

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [July 20, 2022, 1:22pm UTC](https://forum.flowable.org/t/deploying-adding-dmn-in-modeler-app-programmatically/9518/6 "2022-07-20T13:22:43Z")

</div>

Hi @pravinpsa

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

Regards,

Yvo
