diff --git a/app/models/datacite_doi.rb b/app/models/datacite_doi.rb index cb7f49c7e..1ceb2a613 100644 --- a/app/models/datacite_doi.rb +++ b/app/models/datacite_doi.rb @@ -107,11 +107,13 @@ def self.import_in_bulk(ids, options = {}) } # report errors - errors_in_response = - response["items"].select { |k, _v| k.values.first["error"].present? } - errors += errors_in_response.length - errors_in_response.each do |item| - Rails.logger.error "[Elasticsearch] " + item.inspect + if response["errors"] + errors_in_response = + response["items"].select { |k, _v| k.values.first["error"].present? } + errors += errors_in_response.length + errors_in_response.each do |item| + Rails.logger.error "[Elasticsearch] " + item.inspect + end end if errors > 1 diff --git a/app/models/other_doi.rb b/app/models/other_doi.rb index 200c05343..ce801e5af 100644 --- a/app/models/other_doi.rb +++ b/app/models/other_doi.rb @@ -135,11 +135,13 @@ def self.import_in_bulk(ids, options = {}) } # report errors - errors_in_response = - response["items"].select { |k, _v| k.values.first["error"].present? } - errors += errors_in_response.length - errors_in_response.each do |item| - Rails.logger.error "[Elasticsearch] " + item.inspect + if response["errors"] + errors_in_response = + response["items"].select { |k, _v| k.values.first["error"].present? } + errors += errors_in_response.length + errors_in_response.each do |item| + Rails.logger.error "[Elasticsearch] " + item.inspect + end end if errors > 1 diff --git a/app/validators/xml_schema_validator.rb b/app/validators/xml_schema_validator.rb index 55ef0f963..f544d3f2d 100644 --- a/app/validators/xml_schema_validator.rb +++ b/app/validators/xml_schema_validator.rb @@ -45,7 +45,7 @@ def validate_each(record, _attribute, value) http://datacite.org/schema/kernel-2.2 ].include?(record.schema_version) record.errors[:xml] << - "Schema #{record.schema_version} is no longer supported" + "DOI #{record.uid}: Schema #{record.schema_version} is no longer supported" return false end @@ -59,8 +59,9 @@ def validate_each(record, _attribute, value) ) do |_sum, error| location, _level, source, text = error.message.split(": ", 4) line, column = location.split(":", 2) + title = "DOI " + record.uid if line.present? - title = text.to_s.strip + " at line #{line}, column #{column}" + title += ": " + text.to_s.strip + " at line #{line}, column #{column}" end source = source.split("}").last[0..-2] if line.present? source = schema_attributes(source) if source.present? diff --git a/spec/fixtures/vcr_cassettes/DataciteDoisController/views/has_views.yml b/spec/fixtures/vcr_cassettes/DataciteDoisController/views/has_views.yml new file mode 100644 index 000000000..7ffa2380f --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DataciteDoisController/views/has_views.yml @@ -0,0 +1,55 @@ +--- +http_interactions: +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Thu, 07 Jan 2021 10:50:46 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=dce98e278f1957b17059b0891c68baa1f1610016646; expires=Sat, 06-Feb-21 + 10:50:46 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 077e117d340000dfe745985000000001 + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Report-To: + - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=2Br2f8v5Aa0tnjVz1vId%2BsLLMSlOHnzDfvhfNrgPWLkSFyO8D8QLSiOiDOLJYFN6TJaeodGujnwFjcQSvrl9fE7Oi7X9Sk2A"}],"group":"cf-nel","max_age":604800}' + Nel: + - '{"report_to":"cf-nel","max_age":604800}' + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 60dd1ea85933dfe7-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Thu, 07 Jan 2021 10:50:46 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index ea3375b51..60e3281c8 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -2195,7 +2195,7 @@ post "/dois", valid_attributes, headers expect(last_response.status).to eq(422) - expect(json.fetch("errors", nil)).to eq([{ "source" => "xml", "title" => "No matching global declaration available for the validation root. at line 2, column 0", "uid" => "10.14454/10703" }]) + expect(json.fetch("errors", nil)).to eq([{ "source" => "xml", "title" => "DOI 10.14454/10703: No matching global declaration available for the validation root. at line 2, column 0", "uid" => "10.14454/10703" }]) end end @@ -2641,7 +2641,7 @@ post "/dois", not_valid_attributes, headers expect(last_response.status).to eq(422) - expect(json["errors"]).to eq([{ "source" => "creators", "title" => "Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0", "uid" => "10.14454/4k3m-nyvg" }]) + expect(json["errors"]).to eq([{ "source" => "creators", "title" => "DOI 10.14454/4k3m-nyvg: Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ). at line 4, column 0", "uid" => "10.14454/4k3m-nyvg" }]) end end