Skip to content

Commit

Permalink
Revert "Merge branch 'xml_validation_issue649' of https://github.com/…
Browse files Browse the repository at this point in the history
…datacite/lupo"

This reverts commit 3e317b5, reversing
changes made to eb95c31.
  • Loading branch information
Martin Fenner committed Jan 7, 2019
1 parent 3e317b5 commit f66f395
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 142 deletions.
10 changes: 5 additions & 5 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Doi < ActiveRecord::Base
validates_format_of :url, :with => /\A(ftp|http|https):\/\/[\S]+/ , if: :url?, message: "URL is not valid"
validates_uniqueness_of :doi, message: "This DOI has already been taken", unless: :only_validate
validates :last_landing_page_status, numericality: { only_integer: true }, if: :last_landing_page_status?
validates :xml, xml_schema: true, :if => Proc.new { |doi| doi.validatable? }
validates :xml, presence: true, xml_schema: true, :if => Proc.new { |doi| doi.validatable? }

after_commit :update_url, on: [:create, :update]
after_commit :update_media, on: [:create, :update]
Expand Down Expand Up @@ -350,7 +350,7 @@ def self.import_one(doi_id: nil)
logger.error "[MySQL] No metadata for DOI " + doi.doi + " found: " + doi.current_metadata.inspect
return nil
end

meta = doi.read_datacite(string: string, sandbox: doi.sandbox)
attrs = %w(creators contributors titles publisher publication_year types descriptions container sizes formats language dates identifiers related_identifiers funding_references geo_locations rights_list subjects content_url).map do |a|
[a.to_sym, meta[a]]
Expand Down Expand Up @@ -402,7 +402,7 @@ def self.import_by_day(options={})
logger.error "[MySQL] No metadata for DOI " + doi.doi + " found."
return nil
end

meta = doi.read_datacite(string: string, sandbox: doi.sandbox)
attrs = %w(creators contributors titles publisher publication_year types descriptions container sizes formats language dates identifiers related_identifiers funding_references geo_locations rights_list subjects content_url).map do |a|
[a.to_sym, meta[a]]
Expand Down Expand Up @@ -438,7 +438,7 @@ def self.import_by_day_missing(options={})
logger.error "[MySQL] No metadata for DOI " + doi.doi + " found."
return nil
end

meta = doi.read_datacite(string: string, sandbox: doi.sandbox)
attrs = %w(creators contributors titles publisher publication_year types descriptions container sizes formats language dates identifiers related_identifiers funding_references geo_locations rights_list subjects content_url).map do |a|
[a.to_sym, meta[a]]
Expand Down Expand Up @@ -661,7 +661,7 @@ def validatable?
# providers europ and ethz do their own handle registration, so fetch url from handle system instead
def update_url
return nil if current_user.nil? || !is_registered_or_findable?

if %w(europ ethz).include?(provider_id) || %w(Crossref).include?(agency)
UrlJob.perform_later(self)
else
Expand Down
11 changes: 3 additions & 8 deletions lib/xml_schema_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,18 @@ def get_valid_kernel(sv)
end

def validate_each(record, attribute, value)
unless value.present?
record.errors[:xml] << "xml should be present"
return false
end

kernel = get_valid_kernel(record.schema_version)
return false unless kernel.present?

filepath = Bundler.rubygems.find_name('bolognese').first.full_gem_path + "/resources/#{kernel}/metadata.xsd"
schema = Nokogiri::XML::Schema(open(filepath))

schema.validate(Nokogiri::XML(value, nil, 'UTF-8')).reduce({}) do |sum, error|
location, level, source, text = error.message.split(": ", 4)
line, column = location.split(":", 2)
title = text.to_s.strip + " at line #{line}, column #{column}" if line.present?
source = source.split("}").last[0..-2] if line.present?
source = schema_attributes(source) if source.present?
source = schema_attributes(source) if source.present?
record.errors[source.to_sym] << title
end
rescue Nokogiri::XML::SyntaxError => e
Expand Down
Loading

0 comments on commit f66f395

Please sign in to comment.