Fix #28: Add JSON payload builder for DetClassification + preferred_name alias fix - #29
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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::DetClassificationinPAYLOAD_BUILDERSand adda
det_classification_nodemethod following the same pattern asview_control_node/value_list_node/list_of_unit_node. DETclassification entities have standard fields (code, preferred_name,
definition, version, revision) that flow through
entity_payload;no type-specific post-processing is needed.
Before:
After: 163 entities serialize into the browser JSON.
Fix 2 — preferred_name property-ID alias (drive-by)
The alias target for
IECCDD_001_C0002wasMDC_P004_1(preferred_name_localized), but the field DSL's
field :preferred_name, "MDC_P004"reads fromMDC_P004(preferred_name base). Result: every DET classification entity's
preferred_namewas nil even after import.The per-language entries (
IECCDD_001_C0002.en → MDC_P004_1.en, etc.)were dead code:
canonical_idsplits the language suffix off beforethe lookup and reapplies it after, so only the base entry is
consulted. Removed them; changed the base to
MDC_P004so theoutput is
MDC_P004.<lang>— what thepreferred_nameDSL finds.Test plan
bundle exec rspec— 974 examples, 0 failures (up from 962)det_classificationcontext inspec/exporters/per_entity_json_spec.rbasserts type, irdi,code, and preferred_name
det_classification_aliased_specstill passes (theend-to-end import spec — verified the alias change doesn't
break the 163-entity count)
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.