简体   繁体   中英

DMN 1.2: Referencing ItemDefinitions from another ItemDefinition results in an error

I load this DMN file (dmnFile):

<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc" 
             xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
             xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
             xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
  <itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
    <itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
      <typeRef>NumberDefinition</typeRef>
    </itemComponent>
  </itemDefinition>
  <itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
    <typeRef>number</typeRef>
  </itemDefinition>
  <inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
    <variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
  </inputData>
  <decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
    <variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
    <informationRequirement>
      <requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
    </informationRequirement>
    <context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
      <contextEntry>
        <variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
        <literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
          <text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
        </literalExpression>
      </contextEntry>
      <contextEntry>
        <literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
          <text>containsMyNumber</text>
        </literalExpression>
      </contextEntry>
    </context>
  </decision>
</definitions>

like this:

KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.2"), ks.getResources().newFileSystemResource(dmnFile));

and I get an exception with the following error message:

[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1 text= DMN: Unable to resolve type reference '{ http://www.omg.org/spec/DMN/20180521/MODEL/ }NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found ) ]]

Type reference with prefix ("ns:NumberDefinition") results in the following error message:

[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1 text= DMN: Unable to resolve type reference '{ http://www.omg.org/spec/DMN/20180521/MODEL/ }ns:NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found) ]]

What do I do wrong?

When using DMN 1.1 (xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd") and type references as QNames (with prefixes) I get the expected result.

Since DMNv1.2, the idiomatic way to reference is ns.<itemDef> .

In your original DMN xml file this happens on line 7 and 14.

In summary the file in the idiomatic DMNv1.2 form should be:

<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc" 
             xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
             xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
             xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
  <itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
    <itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
      <typeRef>ns.NumberDefinition</typeRef>
    </itemComponent>
  </itemDefinition>
  <itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
    <typeRef>number</typeRef>
  </itemDefinition>
  <inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
    <variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="ns.MyItemDefinition" />
  </inputData>
  <decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
    <variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
    <informationRequirement>
      <requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
    </informationRequirement>
    <context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
      <contextEntry>
        <variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
        <literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
          <text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
        </literalExpression>
      </contextEntry>
      <contextEntry>
        <literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
          <text>containsMyNumber</text>
        </literalExpression>
      </contextEntry>
    </context>
  </decision>
</definitions>

That said, with your report we uncovered a bug when the DMN xml file is using the DMN namespace as the default namespace, which we are addressing with DROOLS-4797 .

Thank you for the report !

There is a way to avoid being forced to use ns.<itemDef> and simply use <itemDef> , and that is by setting the default namespace in the DMN xml to be the model's namespace, and just prefixing the DMN xml element with the namespace prefix targeting the DMN namespace.

In other words, the file can make use of <itemDef> reference without having to ns. prefix them:

<semantic:definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc" 
             xmlns="http://sample.dmn" namespace="http://sample.dmn"
             xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
             xmlns:semantic="http://www.omg.org/spec/DMN/20180521/MODEL/">
  <semantic:itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
    <semantic:itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
      <semantic:typeRef>NumberDefinition</semantic:typeRef>
    </semantic:itemComponent>
  </semantic:itemDefinition>
  <semantic:itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
    <semantic:typeRef>number</semantic:typeRef>
  </semantic:itemDefinition>
  <semantic:inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
    <semantic:variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
  </semantic:inputData>
  <semantic:decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
    <semantic:variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
    <semantic:informationRequirement>
      <semantic:requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
    </semantic:informationRequirement>
    <semantic:context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
      <semantic:contextEntry>
        <semantic:variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
        <semantic:literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
          <semantic:text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</semantic:text>
        </semantic:literalExpression>
      </semantic:contextEntry>
      <semantic:contextEntry>
        <semantic:literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
          <semantic:text>containsMyNumber</semantic:text>
        </semantic:literalExpression>
      </semantic:contextEntry>
    </semantic:context>
  </semantic:decision>
</semantic:definitions>

In this other variant, the default namespace in the xml is the DMN model's namespace, so any itemDef reference does not need any prefix.

Because the default namespace in the xml is the DMN model's namespace, the xml element need to be prefixed with the namespace prefix targeting now the DMN namespace.

Hope this clarifies and provide an insightful explanation!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM