Skip to content

Fix #28: Add JSON payload builder for DetClassification + preferred_name alias fix - #29

Merged
ronaldtse merged 1 commit into
mainfrom
fix/det-classification-exporter
Aug 7, 2026
Merged

Fix #28: Add JSON payload builder for DetClassification + preferred_name alias fix#29
ronaldtse merged 1 commit into
mainfrom
fix/det-classification-exporter

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Closes #28. Two fixes in one commit because the second was discovered
while writing the spec for the first.

Fix 1 — payload builder (the issue)

Register Opencdd::DetClassification in PAYLOAD_BUILDERS and add
a det_classification_node method following the same pattern as
view_control_node / value_list_node / list_of_unit_node. DET
classification entities have standard fields (code, preferred_name,
definition, version, revision) that flow through entity_payload;
no type-specific post-processing is needed.

Before:

ArgumentError: No JSON payload builder for Opencdd::DetClassification

After: 163 entities serialize into the browser JSON.

Fix 2 — preferred_name property-ID alias (drive-by)

The alias target for IECCDD_001_C0002 was MDC_P004_1
(preferred_name_localized), but the field DSL's
field :preferred_name, "MDC_P004" reads from MDC_P004
(preferred_name base). Result: every DET classification entity's
preferred_name was nil even after import.

The per-language entries (IECCDD_001_C0002.en → MDC_P004_1.en, etc.)
were dead code: canonical_id splits the language suffix off before
the lookup and reapplies it after, so only the base entry is
consulted. Removed them; changed the base to MDC_P004 so the
output is MDC_P004.<lang> — what the preferred_name DSL finds.

Test plan

  • bundle exec rspec — 974 examples, 0 failures (up from 962)
  • New det_classification context in
    spec/exporters/per_entity_json_spec.rb asserts type, irdi,
    code, and preferred_name
  • Existing det_classification_aliased_spec still passes (the
    end-to-end import spec — verified the alias change doesn't
    break the 163-entity count)
  • Manual verification needed in data-private:
    bash cd ../data-private bundle exec rake browser:build_from_export[iec-61360-4] python3 -c " import json db = json.load(open('data/iec-61360-4/database.json')) det = [e for e in db if e.get('type') == 'det_classification'] print(f'DET classification entities in browser JSON: {len(det)}') print(f'Sample: {det[0][\"code\"]} - {det[0].get(\"preferred_name\")}'[:80]) "
    Expected: 163 entities, first code="A11" with non-null preferred_name.

Closes #28.

The 163 DET classification entities that import successfully from
iec61360-4/export_DETCLASSIFICATION_*.xls (PRs #25 + #26) were
silently dropped from `rake browser:build_from_export[<dict>]`
because Opencdd::Exporters::Json#payload_for raised
`ArgumentError: No JSON payload builder for Opencdd::DetClassification`.

## Fix 1 — payload builder

Register Opencdd::DetClassification in PAYLOAD_BUILDERS and add a
det_classification_node method following the same pattern as
view_control_node / value_list_node / list_of_unit_node. DET
classification entities have standard fields (code, preferred_name,
definition, version, revision) that flow through entity_payload;
no type-specific post-processing is needed.

## Fix 2 — preferred_name property-ID alias

Discovered while writing the payload spec: the alias target for
IECCDD_001_C0002 was MDC_P004_1 (preferred_name_localized), but the
field DSL's `field :preferred_name, "MDC_P004"` reads from MDC_P004
(preferred_name base). The result: even though the importer stored
the data, every entity's preferred_name was nil.

The per-language entries (IECCDD_001_C0002.en → MDC_P004_1.en, etc.)
were dead code: canonical_id splits the language suffix off before
the lookup and reapplies it after, so only the base entry is
consulted. Removing them and changing the base entry to MDC_P004
produces MDC_P004.<lang>, which the preferred_name DSL finds.

## Spec

spec/exporters/per_entity_json_spec.rb gains a `det_classification`
context that constructs a DetClassification entity directly and
asserts the payload includes type, irdi, code, and preferred_name.

## Verification

bundle exec rspec — 974 examples, 0 failures (up from 962).
@ronaldtse
ronaldtse merged commit 2131e25 into main Aug 7, 2026
11 checks passed
@ronaldtse
ronaldtse deleted the fix/det-classification-exporter branch August 7, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add JSON payload builder for DetClassification (163 entities silently dropped)

1 participant