Skip to content

Commit

Permalink
Merge pull request #97 from datacite/fix_kernel-3-problem
Browse files Browse the repository at this point in the history
Fix  content negotiate for schema 3.x dois
  • Loading branch information
kjgarza authored Jul 16, 2020
2 parents ec81492 + e322866 commit a61533f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/bolognese/datacite_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ def datacite_xml
end

def datacite_errors(xml: nil, schema_version: nil)
schema_version = schema_version.to_s.start_with?("http://datacite.org/schema/kernel") ? schema_version : "http://datacite.org/schema/kernel-4"
if xml.present?
namespaces = Nokogiri::XML(xml, nil, 'UTF-8').root.namespaces
schema_version = namespaces.fetch('xmlns',nil).presence || namespaces.fetch('xmlns:ns0',nil).presence
else
schema_version = schema_version.to_s.start_with?("http://datacite.org/schema/kernel") ? schema_version : "http://datacite.org/schema/kernel-4"
end

kernel = schema_version.to_s.split("/").last
filepath = File.expand_path("../../../resources/#{kernel}/metadata.xsd", __FILE__)
schema = Nokogiri::XML::Schema(open(filepath))
Expand Down
12 changes: 12 additions & 0 deletions spec/writers/bibtex_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
expect(bibtex[:copyright]).to eq("Creative Commons Attribution 3.0 Unported")
end

it "with schema_3" do
# input = fixture_path + "datacite_kernel_3.json"
input = fixture_path + "datacite_schema_3.xml"
json = Bolognese::Metadata.new(input: input, from: "datacite")
subject = Bolognese::Metadata.new(input: json.meta.to_json, from: "datacite_json")
bibtex = BibTeX.parse(subject.bibtex).to_a(quotes: '').first
expect(bibtex[:bibtex_type].to_s).to eq("misc")
expect(bibtex[:bibtex_key]).to eq("https://doi.org/10.5061/dryad.8515")
expect(bibtex[:doi]).to eq("10.5061/dryad.8515")
expect(bibtex[:year]).to eq("2011")
end

it "with pages" do
input = "https://doi.org/10.1155/2012/291294"
subject = Bolognese::Metadata.new(input: input, from: "crossref")
Expand Down

0 comments on commit a61533f

Please sign in to comment.