Skip to content

Commit

Permalink
include doi in xml validation error messages. #690
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 7, 2021
1 parent 285a865 commit 07ac6af
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 14 deletions.
12 changes: 7 additions & 5 deletions app/models/datacite_doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions app/models/other_doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/validators/xml_schema_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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?
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/requests/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 07ac6af

Please sign in to comment.