Module: DecisionAgent::Web::DmnEditor::XmlBuilder

Included in:
DecisionAgent::Web::DmnEditor
Defined in:
lib/decision_agent/web/dmn_editor/xml_builder.rb

Instance Method Summary collapse

Instance Method Details

#build_decision_table_xml(xml, table) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/decision_agent/web/dmn_editor/xml_builder.rb', line 38

def build_decision_table_xml(xml, table)
  xml.decisionTable(
    id: table.id,
    hitPolicy: table.hit_policy || "FIRST",
    outputLabel: "output"
  ) do
    build_inputs_xml(xml, table)
    build_outputs_xml(xml, table)
    build_rules_xml(xml, table)
  end
end

#generate_dmn_xml(model) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/decision_agent/web/dmn_editor/xml_builder.rb', line 7

def generate_dmn_xml(model)
  require "nokogiri"

  builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
    xml.definitions(
      "xmlns" => "https://www.omg.org/spec/DMN/20191111/MODEL/",
      "xmlns:dmndi" => "https://www.omg.org/spec/DMN/20191111/DMNDI/",
      "xmlns:dc" => "http://www.omg.org/spec/DMN/20180521/DC/",
      "id" => "definitions_#{model.id}",
      "name" => model.name,
      "namespace" => model.namespace || "http://decision_agent.local"
    ) do
      model.decisions.each do |decision|
        xml.decision(id: decision.id, name: decision.name) do
          if decision.decision_table
            build_decision_table_xml(xml, decision.decision_table)
          elsif decision.decision_tree
            xml.comment "Decision Tree (not fully supported in DMN XML export yet)"
          elsif decision.instance_variable_get(:@literal_expression)
            xml.literalExpression do
              xml.text decision.instance_variable_get(:@literal_expression)
            end
          end
        end
      end
    end
  end

  builder.to_xml
end