@Test public void testConvertJsonToDmn_no_rules() throws Exception { JsonNode testJsonResource = parseJson(JSON_RESOURCE_2); DmnDefinition dmnDefinition = new DmnJsonConverter().convertToDmn(testJsonResource, "xyz", 1, new Date()); Assert.assertNotNull(dmnDefinition); Assert.assertEquals(DmnJsonConverter.MODEL_NAMESPACE, dmnDefinition.getNamespace()); Assert.assertEquals("definition_xyz", dmnDefinition.getId()); Assert.assertEquals("decisionTableRule1", dmnDefinition.getName()); Assert.assertEquals(DmnJsonConverter.URI_JSON, dmnDefinition.getTypeLanguage()); Assert.assertNotNull(dmnDefinition.getDecisions()); Assert.assertEquals(1, dmnDefinition.getDecisions().size()); Decision decision = dmnDefinition.getDecisions().get(0); Assert.assertNotNull(decision); Assert.assertEquals("decTable1", decision.getId()); DecisionTable decisionTable = (DecisionTable) decision.getExpression(); Assert.assertNotNull(decisionTable); Assert.assertEquals("decisionTable_11", decisionTable.getId()); Assert.assertEquals(HitPolicy.ANY, decisionTable.getHitPolicy()); Assert.assertEquals(DecisionTableOrientation.RULE_AS_ROW, decisionTable.getPreferredOrientation()); List<InputClause> inputClauses = decisionTable.getInputs(); Assert.assertNotNull(inputClauses); Assert.assertEquals(2, inputClauses.size()); LiteralExpression inputExpression11 = inputClauses.get(0).getInputExpression(); Assert.assertNotNull(inputExpression11); Assert.assertEquals("Order Size", inputExpression11.getLabel()); Assert.assertEquals("inputExpression_1", inputExpression11.getId()); Assert.assertEquals("number", inputExpression11.getTypeRef()); Assert.assertEquals("ordersize", inputExpression11.getText()); LiteralExpression inputExpression12 = inputClauses.get(1).getInputExpression(); Assert.assertNotNull(inputExpression12); Assert.assertEquals("Registered On", inputExpression12.getLabel()); Assert.assertEquals("inputExpression_2", inputExpression12.getId()); Assert.assertEquals("date", inputExpression12.getTypeRef()); Assert.assertEquals("registered", inputExpression12.getText()); List<OutputClause> outputClauses = decisionTable.getOutputs(); Assert.assertNotNull(outputClauses); Assert.assertEquals(1, outputClauses.size()); OutputClause outputClause1 = outputClauses.get(0); Assert.assertNotNull(outputClause1); Assert.assertEquals("Has discount", outputClause1.getLabel()); Assert.assertEquals("outputExpression_3", outputClause1.getId()); Assert.assertEquals("newVariable1", outputClause1.getName()); Assert.assertEquals("boolean", outputClause1.getTypeRef()); }
public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; } }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }  }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }  DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated); ObjectNode convertToJson(DmnDefinition definition); }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }  DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated); ObjectNode convertToJson(DmnDefinition definition); final static String MODEL_NAMESPACE; final static String URI_JSON; }