Skip to content

Commit e5ef909

Browse files
authored
Merge pull request #1031 from sul-dlss/doi-public-xml
Prevent duplicate DOI identifiers in public XML
2 parents 779090c + 5f018da commit e5ef909

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

app/services/publish/public_desc_metadata_service.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ def strip_comments!
5757
def add_doi
5858
return unless cocina_object.dro? && cocina_object.identification.doi
5959

60-
identifier = doc.create_element('identifier', xmlns: MODS_NS)
61-
identifier.content = "https://doi.org/#{cocina_object.identification.doi}"
62-
identifier['type'] = 'doi'
63-
identifier['displayLabel'] = 'DOI'
64-
doc.root << identifier
60+
doi_node = doc.xpath('/xmlns:mods/xmlns:identifier[@type="doi"]').first
61+
if doi_node
62+
doi_node['displayLabel'] = 'DOI'
63+
doi_node.content = "https://doi.org/#{doi_node.content}" unless doi_node.content.starts_with?('https')
64+
else
65+
identifier = doc.create_element('identifier', xmlns: MODS_NS)
66+
identifier.content = "https://doi.org/#{cocina_object.identification.doi}"
67+
identifier['type'] = 'doi'
68+
identifier['displayLabel'] = 'DOI'
69+
doc.root << identifier
70+
end
6571
end
6672

6773
# expand constituent relations into relatedItem references -- see JUMBO-18

spec/requests/v1/publish_collection_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
end
2424

2525
context 'when using the legacy endpoint' do
26+
after do
27+
FileUtils.rm_rf(Settings.filesystems.stacks_root)
28+
end
29+
2630
it 'does not fail' do
2731
post "/v1/resources",
2832
params: request,

spec/services/publish/public_desc_metadata_service_spec.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
let(:cocina) do
1111
Cocina::Models.build({
1212
type: "https://cocina.sul.stanford.edu/models/book",
13-
externalIdentifier: "druid:bc123df4567",
13+
externalIdentifier: druid,
1414
label: "Test DRO",
1515
version: 1,
1616
access:,
@@ -20,6 +20,7 @@
2020
structural:
2121
})
2222
end
23+
let(:druid) { "druid:bc123df4567" }
2324

2425
let(:access) { {} }
2526
let(:identification) { { sourceId: 'sul:123' } }
@@ -151,7 +152,25 @@
151152
service.ng_xml
152153
end
153154

154-
it 'adds the doi in identityMetadata' do
155+
let(:description) do
156+
{
157+
title: [{ value: 'Best Thesis Ever' }],
158+
purl: 'https://purl.stanford.edu/ty606df5808',
159+
identifier: [
160+
{
161+
value: '10.80343/ty606df5808',
162+
type: 'DOI',
163+
source: {
164+
code: 'doi'
165+
}
166+
}
167+
]
168+
}
169+
end
170+
171+
let(:druid) { "druid:ty606df5808" }
172+
173+
it 'adds the doi to mods:identifier' do
155174
expect(public_mods.xpath('//xmlns:identifier[@type="doi"]').to_xml).to eq(
156175
'<identifier type="doi" displayLabel="DOI">https://doi.org/10.80343/ty606df5808</identifier>'
157176
)

0 commit comments

Comments
 (0)