Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/opencdd/exporters/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ def visit_list_of_unit(lou)
# omitted (payload still has all the entity's own fields).
# ─────────────────────────────────────────────────────────────
PAYLOAD_BUILDERS = {
Opencdd::Klass => :class_node,
Opencdd::Property => :property_node,
Opencdd::Unit => :unit_node,
Opencdd::ValueList => :value_list_node,
Opencdd::ValueTerm => :value_term_node,
Opencdd::Relation => :relation_node,
Opencdd::ViewControl => :view_control_node,
Opencdd::ListUnit => :list_of_unit_node,
Opencdd::Klass => :class_node,
Opencdd::Property => :property_node,
Opencdd::Unit => :unit_node,
Opencdd::ValueList => :value_list_node,
Opencdd::ValueTerm => :value_term_node,
Opencdd::Relation => :relation_node,
Opencdd::ViewControl => :view_control_node,
Opencdd::ListUnit => :list_of_unit_node,
Opencdd::DetClassification => :det_classification_node,
}.freeze

def payload_for(entity, database: nil)
Expand Down Expand Up @@ -134,6 +135,10 @@ def list_of_unit_node(lou)
entity_payload(lou).merge(type: "list_of_unit").compact
end

def det_classification_node(det)
entity_payload(det).merge(type: "det_classification").compact
end

private

# Iterates every declared field on the entity's class (walking
Expand Down
15 changes: 9 additions & 6 deletions lib/opencdd/parcel/sheet_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ class SheetSchema
# project-specific column IDs (C0001 = code, C0002.<lang> = name)
# rather than the standard MDC codes. Without these mappings,
# every DET classification entity would have nil code + name.
#
# C0002 maps to MDC_P004 (preferred_name), not MDC_P004_1
# (preferred_name_localized), because canonical_id splits the
# language suffix off and reapplies it after the base lookup —
# so the per-language entries (C0002.en, C0002.fr, etc.) below
# would be dead code. The base entry alone produces
# MDC_P004.<lang>, which is what the preferred_name field DSL
# reads via FieldRegistry.
"IECCDD_001_C0001" => "MDC_P001_5",
"IECCDD_001_C0002" => "MDC_P004_1",
"IECCDD_001_C0002.en" => "MDC_P004_1.en",
"IECCDD_001_C0002.fr" => "MDC_P004_1.fr",
"IECCDD_001_C0002.de" => "MDC_P004_1.de",
"IECCDD_001_C0002.ja" => "MDC_P004_1.ja",
"IECCDD_001_C0002.zh" => "MDC_P004_1.zh",
"IECCDD_001_C0002" => "MDC_P004",
}.freeze

# Canonicalize a Parcel column ID. Splits language tags
Expand Down
22 changes: 22 additions & 0 deletions spec/exporters/per_entity_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@
it { is_expected.to include(type: "value_list") }
end

context "with a det_classification entity" do
let(:entity) do
Opencdd::DetClassification.new(
irdi: Opencdd::IRDI.parse("0112/2///IECCDD_001#A11"),
properties: {
"MDC_P001_5" => "A11",
"MDC_P004.en" => "geographical unit (greater than a place)",
},
meta_class_irdi: Opencdd::IRDI.parse("MDC_C0101"),
)
end
subject(:payload) { exporter.payload_for(entity) }

it { is_expected.to include(type: "det_classification") }
it { is_expected.to include(irdi: "0112/2///IECCDD_001#A11") }
it { is_expected.to include(code: "A11") }

it "includes the preferred name" do
expect(payload["preferred_name"]).to eq("geographical unit (greater than a place)")
end
end

context "without a database (no cross-link resolution)" do
let(:entity) { database.properties.first }
subject(:payload) { exporter.payload_for(entity) }
Expand Down
Loading