diff --git a/lib/opencdd/exporters/json.rb b/lib/opencdd/exporters/json.rb index 464ae65..6637cbc 100644 --- a/lib/opencdd/exporters/json.rb +++ b/lib/opencdd/exporters/json.rb @@ -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) @@ -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 diff --git a/lib/opencdd/parcel/sheet_schema.rb b/lib/opencdd/parcel/sheet_schema.rb index 81509f7..1fe56f6 100644 --- a/lib/opencdd/parcel/sheet_schema.rb +++ b/lib/opencdd/parcel/sheet_schema.rb @@ -27,13 +27,16 @@ class SheetSchema # project-specific column IDs (C0001 = code, C0002. = 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., 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 diff --git a/spec/exporters/per_entity_json_spec.rb b/spec/exporters/per_entity_json_spec.rb index 735cd9e..6b69df5 100644 --- a/spec/exporters/per_entity_json_spec.rb +++ b/spec/exporters/per_entity_json_spec.rb @@ -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) }