File tree Expand file tree Collapse file tree 3 files changed +36
-7
lines changed Expand file tree Collapse file tree 3 files changed +36
-7
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 ,
Original file line number Diff line number Diff line change 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 :,
2020 structural :
2121 } )
2222 end
23+ let ( :druid ) { "druid:bc123df4567" }
2324
2425 let ( :access ) { { } }
2526 let ( :identification ) { { sourceId : 'sul:123' } }
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 )
You can’t perform that action at this time.
0 commit comments