Skip to content

Commit

Permalink
Merge pull request #777 from sul-dlss/t773-related_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Feb 19, 2025
2 parents 07ecf80 + cf94fbf commit bac1a03
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
20 changes: 12 additions & 8 deletions lib/cocina/models/mapping/from_mods/related_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion lib/cocina/models/mapping/to_mods/related_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/cocina/models/mapping/descriptive/h2/related_item_h2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<relatedItem otherType="source of">
<titleInfo>
<title>A paper</title>
</titleInfo>
</relatedItem>
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
Expand Down

0 comments on commit bac1a03

Please sign in to comment.