From cf94fbfaa766d48c7d301ec18ddd2efd9062fb7b Mon Sep 17 00:00:00 2001 From: Justin Littman Date: Wed, 19 Feb 2025 12:55:31 -0500 Subject: [PATCH] Maps new H3 relatedResource types to MODS mapping. closes #773 --- .../mapping/from_mods/related_resource.rb | 20 +++++++----- .../mapping/to_mods/related_resource.rb | 17 +++++++++- .../descriptive/h2/related_item_h2_spec.rb | 31 +++++++++++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/lib/cocina/models/mapping/from_mods/related_resource.rb b/lib/cocina/models/mapping/from_mods/related_resource.rb index ca7a1a55..4119598e 100644 --- a/lib/cocina/models/mapping/from_mods/related_resource.rb +++ b/lib/cocina/models/mapping/from_mods/related_resource.rb @@ -51,14 +51,18 @@ def build_related_item(related_item) item[:displayLabel] = related_item['displayLabel'] if related_item['type'] item[:type] = normalized_type_for(related_item['type']) - elsif related_item['otherType'] - item[:type] = 'related to' - item[:note] ||= [] - item[:note] << - { type: 'other relation type', value: related_item['otherType'] }.tap do |note| - note[:uri] = related_item['otherTypeURI'] if related_item['otherTypeURI'] - note[:source] = { value: related_item['otherTypeAuth'] } if related_item['otherTypeAuth'] - end + elsif (other_type = related_item['otherType']) + if Cocina::Models::Mapping::ToMods::RelatedResource::OTHER_TYPES.include?(other_type) + item[:type] = other_type + else + item[:type] = 'related to' + item[:note] ||= [] + item[:note] << + { type: 'other relation type', value: related_item['otherType'] }.tap do |note| + note[:uri] = related_item['otherTypeURI'] if related_item['otherTypeURI'] + note[:source] = { value: related_item['otherTypeAuth'] } if related_item['otherTypeAuth'] + end + end end end.compact end diff --git a/lib/cocina/models/mapping/to_mods/related_resource.rb b/lib/cocina/models/mapping/to_mods/related_resource.rb index cb45a489..303dcbf9 100644 --- a/lib/cocina/models/mapping/to_mods/related_resource.rb +++ b/lib/cocina/models/mapping/to_mods/related_resource.rb @@ -22,6 +22,15 @@ class RelatedResource 'succeeded by' => 'succeeding' }.freeze + OTHER_TYPES = [ + 'supplement to', + 'supplemented by', + 'derived from', + 'source of', + 'version of record', + 'identical to' + ].freeze + DETAIL_TYPES = { 'location within source' => 'part', 'volume' => 'volume', @@ -85,7 +94,13 @@ def filtered_related_resources def attributes_for(related, other_type_note) {}.tap do |attrs| - attrs[:type] = TYPES.fetch(related.type) if related.type + if related.type + if (mapped_type = TYPES[related.type]) + attrs[:type] = mapped_type + elsif OTHER_TYPES.include?(related.type) + attrs[:otherType] = related.type + end + end attrs[:displayLabel] = related.displayLabel if other_type_note diff --git a/spec/cocina/models/mapping/descriptive/h2/related_item_h2_spec.rb b/spec/cocina/models/mapping/descriptive/h2/related_item_h2_spec.rb index b9ba914c..1b8d31d9 100644 --- a/spec/cocina/models/mapping/descriptive/h2/related_item_h2_spec.rb +++ b/spec/cocina/models/mapping/descriptive/h2/related_item_h2_spec.rb @@ -30,6 +30,37 @@ end end + # Related resource types that does not map to MODS + # See https://github.com/sul-dlss/cocina-models/issues/773 + describe 'OtherType related citation' do + it_behaves_like 'cocina MODS mapping' do + let(:mods) do + <<~XML + + + A paper + + + XML + end + + let(:cocina) do + { + relatedResource: [ + { + title: [ + { + value: 'A paper' + } + ], + type: 'source of' + } + ] + } + end + end + end + describe 'Related link with title' do it_behaves_like 'cocina MODS mapping' do let(:mods) do