Skip to content

Commit

Permalink
Merge pull request #189 from datacite/codycooperross/issue188
Browse files Browse the repository at this point in the history
Fix for ORCID and ROR identifiers ending with a `/` not being rendered in JSON when converting from XML
  • Loading branch information
svogt0511 authored Feb 26, 2024
2 parents 7a1ea4a + 0152810 commit 02e1860
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/bolognese/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,12 @@ def orcid_as_url(orcid)
end

def validate_orcid(orcid)
orcid = Array(/\A(?:(?:http|https):\/\/(?:(?:www|sandbox)?\.)?orcid\.org\/)?(\d{4}[[:space:]-]\d{4}[[:space:]-]\d{4}[[:space:]-]\d{3}[0-9X]+)\z/.match(orcid)).last
orcid = Array(/\A(?:(?:http|https):\/\/(?:(?:www|sandbox)?\.)?orcid\.org\/)?(\d{4}[[:space:]-]\d{4}[[:space:]-]\d{4}[[:space:]-]\d{3}[0-9X]+)\/{0,1}\z/.match(orcid)).last
orcid.gsub(/[[:space:]]/, "-") if orcid.present?
end

def validate_ror(ror)
Array(/^(?:(?:(?:http|https):\/\/)?ror\.org\/)?(0\w{6}\d{2})$/.match(ror)).last
Array(/^(?:(?:(?:http|https):\/\/)?ror\.org\/)?(0\w{6}\d{2})\/{0,1}$/.match(ror)).last
end

def validate_orcid_scheme(orcid_scheme)
Expand Down
10 changes: 8 additions & 2 deletions spec/author_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@
expect(subject.creators[4]).to eq("nameType"=>"Organizational", "name"=>"University Of Kivu", "nameIdentifiers"=> [{"nameIdentifier"=>"https://ror.org/01qfhxr31", "schemeUri"=>"https://ror.org", "nameIdentifierScheme"=>"ROR"}], "affiliation"=>[])
expect(subject.creators[5]).to eq("nameType"=>"Organizational", "name"=>"សាកលវិទ្យាល័យកម្ពុជា", "nameIdentifiers"=> [{"nameIdentifier"=>"http://ror.org/025e3rc84", "nameIdentifierScheme"=>"RORS"}], "affiliation"=>[])
expect(subject.creators[6]).to eq("nameType"=>"Organizational", "name"=>"جامعة زاخۆ", "nameIdentifiers"=> [{"nameIdentifier"=>"05sd1pz50", "schemeUri"=>"https://ror.org", "nameIdentifierScheme"=>"RORS"}], "affiliation"=>[])
expect(subject.creators[9]).to eq("nameType"=>"Organizational", "name"=>"Gump South Pacific Research Station", "nameIdentifiers"=> [{"nameIdentifier"=>"https://ror.org/04sk0et52", "schemeUri"=>"https://ror.org", "nameIdentifierScheme"=>"ROR"}], "affiliation"=>[])
expect(subject.contributors.first).to eq("nameType"=>"Organizational", "name"=>" Nawroz University ", "nameIdentifiers"=> [{"nameIdentifier"=>"https://ror.org/04gp75d48", "schemeUri"=>"https://ror.org", "nameIdentifierScheme"=>"ROR"}], "affiliation"=>[], "contributorType"=>"Producer")
expect(subject.contributors.last).to eq("nameType"=>"Organizational", "name"=>"University Of Greenland (Https://Www.Uni.Gl/)", "nameIdentifiers"=> [{"nameIdentifier"=>"https://ror.org/00t5j6b61", "schemeUri"=>"https://ror.org", "nameIdentifierScheme"=>"ROR"}],"affiliation"=>[], "contributorType"=>"Sponsor")
end

context "affiliationIdentifier" do
context "affiliationIdentifier/nameIdentifier" do
let(:input) { fixture_path + 'datacite-example-ROR-nameIdentifiers.xml' }
subject { Bolognese::Metadata.new(input: input, from: "datacite") }

Expand Down Expand Up @@ -207,6 +208,11 @@
expect(subject.creators[8]["nameIdentifiers"]).to eq([{"nameIdentifier"=>"https://orcid.org/0000-0001-9998-0118", "schemeUri"=>"https://orcid.org", "nameIdentifierScheme"=>"ORCID"}])
end

it "should normalize valid ORCID nameIdentifier with trailing slash" do
#" 0000-0001-9998-0118 ", # Valid ORCID with leading/trailing spaces
expect(subject.creators[10]["nameIdentifiers"]).to eq([{"nameIdentifier"=>"https://orcid.org/0000-0001-9998-0117", "schemeUri"=>"https://orcid.org", "nameIdentifierScheme"=>"ORCID"}])
end

it "should parse non ROR schema's without normalizing them" do
input = fixture_path + 'datacite-example-ROR-nameIdentifiers.xml'
subject = Bolognese::Metadata.new(input: input, from: "datacite")
Expand Down Expand Up @@ -250,4 +256,4 @@
expect(response).to eq("Matt Jones and Peter Slaughter and {University of California, Santa Barbara}")
end
end
end
end
8 changes: 8 additions & 0 deletions spec/fixtures/datacite-example-ROR-nameIdentifiers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
<creatorName nameType="Personal">Mike B</creatorName>
<nameIdentifier nameIdentifierScheme="ORCID"> 0000-0001-9998-0118 </nameIdentifier>
</creator>
<creator>
<creatorName nameType="Organizational">Gump South Pacific Research Station</creatorName>
<nameIdentifier nameIdentifierScheme="ROR" schemeURI="https://ror.org/">https://ror.org/04sk0et52/</nameIdentifier>
</creator>
<creator>
<creatorName nameType="Personal">Ashwini Sukale</creatorName>
<nameIdentifier schemeURI="https://orcid.org/" nameIdentifierScheme="ORCID">https://orcid.org/0000-0001-9998-0117/</nameIdentifier>
</creator>
</creators>
<titles>
<title xml:lang="en-US">Genomic Standards Consortium (GSC) Island Sampling Day: Moorea Reef to Ridges Genomic Transect</title>
Expand Down

0 comments on commit 02e1860

Please sign in to comment.