DMN 1.2:从另一个ItemDefinition引用ItemDefinitions导致错误

时间:2019-11-20 19:53:45

标签: drools decision-model-notation

我加载了这个DMN文件(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>

像这样:

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

我收到以下错误消息的异常:

[消息[id = 1,kieBase = defaultKieBase,级别=错误,路径= C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn,行= 4,列= -1    text = DMN:无法解析节点“ MyItemDefinition”上的类型引用“ {http://www.omg.org/spec/DMN/20180521/MODEL/} NumberDefinition” (资源:C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn ,DMN ID:_29d92e98-3c97-67a3-22f1-d342622424f7,未找到列出的类型定义)]]

带有前缀(“ ns:NumberDefinition”)的类型引用会导致以下错误消息:

[消息[id = 1,kieBase = defaultKieBase,级别=错误,路径= C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn,行= 4,列= -1    text = DMN:无法解析节点“ MyItemDefinition”上的类型引用“ {http://www.omg.org/spec/DMN/20180521/MODEL/} ns:NumberDefinition” (资源:C:/Users/AppData/Local/Temp/tmpBA10.tmp .dmn,DMN ID:_29d92e98-3c97-67a3-22f1-d342622424f7,未找到列出的类型定义)]]

我该怎么办?

在使用DMN 1.1(xmlns =“ http://www.omg.org/spec/DMN/20151101/dmn.xsd”)并将类型引用作为QName(带有前缀)时,我得到了预期的结果。

1 个答案:

答案 0 :(得分:1)

从DMNv1.2开始,引用的惯用方式是ns.<itemDef>

在您原始的DMN xml文件中,此操作发生在第7行和第14行。

总而言之,惯用的DMNv1.2格式的文件应为:

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

也就是说,在您的报告中,我们发现了DMN xml文件使用DMN命名空间作为默认命名空间时要解决的错误。 DROOLS-4797

感谢您的举报!

有一种方法可以避免被迫使用ns.<itemDef>并简单地使用<itemDef>,即通过将DMN xml中的默认名称空间设置为模型的名称空间,并仅在DMN前面添加前缀具有以DMN名称空间为目标的名称空间前缀的xml元素。

换句话说,文件可以使用<itemDef>引用,而不必ns.加上前缀:

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

在另一个变体中,xml中的默认名称空间是DMN模型的名称空间,因此任何itemDef引用都不需要任何前缀。

因为xml中的默认名称空间是DMN模型的名称空间,所以xml元素需要以现在面向DMN名称空间的名称空间前缀为前缀。

希望这可以澄清并提供深刻的解释!