Skip to content

Commit

Permalink
Add support for xml detail return in dois endpoint
Browse files Browse the repository at this point in the history
Issue #315
  • Loading branch information
richardhallett committed Jul 17, 2019
1 parent ca90901 commit 9b89b18
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def index
options[:is_collection] = true
options[:params] = {
:current_ability => current_ability,
:detail => params[:detail]
}

bmr = Benchmark.ms {
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DoiSerializer
has_many :media, if: Proc.new { |object, params| params && params[:detail] }

attribute :xml, if: Proc.new { |object, params| params && params[:detail] } do |object|
object.xml_encoded
Base64.strict_encode64(object.xml) if object.xml.present?
end

attribute :doi do |object|
Expand Down
49 changes: 30 additions & 19 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
expect(json['data'].size).to eq(3)
expect(json.dig('meta', 'total')).to eq(3)
end

it 'returns dois with extra detail' do
get '/dois?detail=true', nil, headers

expect(last_response.status).to eq(200)
expect(json['data'].size).to eq(3)
json['data'].each{
|doi|
expect(doi.dig('attributes')).to include('xml')
}
end
end

describe 'GET /dois/:id', elasticsearch: true do
Expand Down Expand Up @@ -59,7 +70,7 @@

context 'anonymous user' do
it 'returns the Doi' do
get "/dois/#{doi.doi}"
get "/dois/#{doi.doi}"

expect(last_response.status).to eq(401)
expect(json.fetch('errors')).to eq([{"status"=>"401", "title"=>"Bad credentials."}])
Expand Down Expand Up @@ -786,7 +797,7 @@

it 'updates the record' do
patch "/dois/#{doi.doi}", valid_attributes, headers

expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'url')).to eq("http://www.bl.uk/pdf/pat.pdf")
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
Expand Down Expand Up @@ -959,7 +970,7 @@
"nameIdentifiers" => [{"nameIdentifier"=>"https://orcid.org/0000-0002-1825-0097", "nameIdentifierScheme"=>"ORCID", "schemeUri"=>"https://orcid.org"}],
"nameType" => "Personal")
expect(json.dig('data', 'attributes', 'creators')[2]).to eq("nameType"=>"Organizational", "name"=>"The Psychoceramics Study Group", "affiliation"=>[{"affiliationIdentifier"=>"https://ror.org/05gq02987", "name"=>"Brown University", "affiliationIdentifierScheme"=>"ROR"}])

xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {})
expect(xml.dig("creators", "creator")[0]).to eq("affiliation" => {"__content__"=>"DataCite", "affiliationIdentifier"=>"https://ror.org/04wxnsj81", "affiliationIdentifierScheme"=>"ROR"},
"creatorName" => {"__content__"=>"Miller, Elizabeth", "nameType"=>"Personal"},
Expand Down Expand Up @@ -1003,7 +1014,7 @@
context 'crossref url', vcr: true do
let(:provider) { create(:provider, name: "Crossref", symbol: "CROSSREF", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "Crossref Citations", symbol: "CROSSREF.CITATIONS") }

let(:xml) { Base64.strict_encode64("https://doi.org/10.7554/elife.01567") }
let(:valid_attributes) do
{
Expand Down Expand Up @@ -1035,7 +1046,7 @@
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth"}])
# expect(json.dig('data', 'attributes', 'agency')).to eq("Crossref")
expect(json.dig('data', 'attributes', 'state')).to eq("findable")

xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {})
expect(xml.dig("titles", "title")).to eq("Automated quantitative histology reveals vascular morphodynamics during Arabidopsis hypocotyl secondary growth")
end
Expand All @@ -1044,7 +1055,7 @@
context 'crossref url not found', vcr: true do
let(:provider) { create(:provider, name: "Crossref", symbol: "CROSSREF", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "Crossref Citations", symbol: "CROSSREF.CITATIONS") }

let(:xml) { Base64.strict_encode64("https://doi.org/10.3389/fmicb.2019.01425") }
let(:valid_attributes) do
{
Expand Down Expand Up @@ -1078,7 +1089,7 @@
context 'medra url', vcr: true do
let(:provider) { create(:provider, name: "mEDRA", symbol: "MEDRA", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "mEDRA Citations", symbol: "MEDRA.CITATIONS") }

let(:xml) { Base64.strict_encode64("https://doi.org/10.3280/ecag2018-001005") }
let(:valid_attributes) do
{
Expand Down Expand Up @@ -1110,7 +1121,7 @@
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Substitutability between organic and conventional poultry products and organic price premiums"}])
# expect(json.dig('data', 'attributes', 'agency')).to eq("mEDRA")
expect(json.dig('data', 'attributes', 'state')).to eq("findable")

xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {})
expect(xml.dig("titles", "title")).to eq("Substitutability between organic and conventional poultry products and organic price premiums")
end
Expand All @@ -1119,7 +1130,7 @@
context 'kisti url', vcr: true do
let(:provider) { create(:provider, name: "KISTI", symbol: "KISTI", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "KISTI Citations", symbol: "KISTI.CITATIONS") }

let(:xml) { Base64.strict_encode64("https://doi.org/10.5012/bkcs.2013.34.10.2889") }
let(:valid_attributes) do
{
Expand Down Expand Up @@ -1151,7 +1162,7 @@
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Synthesis, Crystal Structure and Theoretical Calculation of a Novel Nickel(II) Complex with Dibromotyrosine and 1,10-Phenanthroline"}])
# expect(json.dig('data', 'attributes', 'agency')).to eq("mEDRA")
expect(json.dig('data', 'attributes', 'state')).to eq("findable")

xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {})
expect(xml.dig("titles", "title")).to eq("Synthesis, Crystal Structure and Theoretical Calculation of a Novel Nickel(II) Complex with Dibromotyrosine and 1,10-Phenanthroline")
end
Expand All @@ -1160,7 +1171,7 @@
context 'jalc url', vcr: true do
let(:provider) { create(:provider, name: "JaLC", symbol: "JALC", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "JALC Citations", symbol: "JALC.CITATIONS") }

let(:xml) { Base64.strict_encode64("https://doi.org/10.1241/johokanri.39.979") }
let(:valid_attributes) do
{
Expand Down Expand Up @@ -1192,7 +1203,7 @@
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Utilizing the Internet. 12 Series. Future of the Internet."}])
# expect(json.dig('data', 'attributes', 'agency')).to eq("mEDRA")
expect(json.dig('data', 'attributes', 'state')).to eq("findable")

xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {})
expect(xml.dig("titles", "title")).to eq("Utilizing the Internet. 12 Series. Future of the Internet.")
end
Expand All @@ -1201,7 +1212,7 @@
context 'op url', vcr: true do
let(:provider) { create(:provider, name: "OP", symbol: "OP", role_name: "ROLE_REGISTRATION_AGENCY") }
let(:client) { create(:client, provider: provider, name: "OP Citations", symbol: "OP.CITATIONS") }

let(:xml) { Base64.strict_encode64("https://doi.org/10.2903/j.efsa.2018.5239") }
let(:valid_attributes) do
{
Expand Down Expand Up @@ -1233,7 +1244,7 @@
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Scientific opinion on the safety of green tea catechins"}])
# expect(json.dig('data', 'attributes', 'agency')).to eq("mEDRA")
expect(json.dig('data', 'attributes', 'state')).to eq("findable")

xml = Maremma.from_xml(Base64.decode64(json.dig('data', 'attributes', 'xml'))).fetch("resource", {})
expect(xml.dig("titles", "title")).to eq("Scientific opinion on the safety of green tea catechins")
end
Expand Down Expand Up @@ -2284,7 +2295,7 @@
context 'landing page' do
let(:url) { "https://blog.datacite.org/re3data-science-europe/" }
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
let(:landing_page) do
let(:landing_page) do
{
"checked" => Time.zone.now.utc.iso8601,
"status" => 200,
Expand Down Expand Up @@ -2330,7 +2341,7 @@
context 'update with landing page info as admin' do
let(:url) { "https://blog.datacite.org/re3data-science-europe/" }
let(:doi) { create(:doi, doi: "10.14454/10703", url: url, client: client) }
let(:landing_page) do
let(:landing_page) do
{
"checked" => Time.zone.now.utc.iso8601,
"status" => 200,
Expand Down Expand Up @@ -2372,7 +2383,7 @@
context 'landing page schema-org-id array' do
let(:url) { "https://blog.datacite.org/re3data-science-europe/" }
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
let(:landing_page) do
let(:landing_page) do
{
"checked" => Time.zone.now.utc.iso8601,
"status" => 200,
Expand Down Expand Up @@ -2728,7 +2739,7 @@

it 'returns error message' do
get "/dois/#{doi.doi}", nil, { "HTTP_ACCEPT" => "application/vnd.jats+xml" }

expect(last_response.status).to eq(401)
expect(json["errors"]).to eq([{"status"=>"401", "title"=>"Bad credentials."}])
end
Expand Down Expand Up @@ -2984,7 +2995,7 @@
context "style and locale" do
it 'returns the Doi' do
get "/dois/#{doi.doi}?style=vancouver&locale=de", nil, { "HTTP_ACCEPT" => "text/x-bibliography", 'HTTP_AUTHORIZATION' => 'Bearer ' + bearer }

expect(last_response.status).to eq(200)
expect(last_response.body).to start_with("Ollomo B")
end
Expand Down

0 comments on commit 9b89b18

Please sign in to comment.