Skip to content

Commit

Permalink
make metadata import more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 27, 2018
1 parent a2e3f81 commit 7e7fe5b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/crosscitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def well_formed_xml(string)
end

def from_xml(string)
return nil unless string.start_with?('<?xml version=')
return nil unless string.start_with?('<?xml version=') || string.start_with?('<resource ')

doc = Nokogiri::XML(string) { |config| config.strict.noblanks }
doc.to_xml.strip
Expand Down
4 changes: 2 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def self.import_one(doi_id: nil)
return nil
end

string = doi.current_metadata.present? && doi.current_metadata.xml.to_s.start_with?('<?xml version=') ? doi.current_metadata.xml.force_encoding("UTF-8") : nil
string = doi.current_metadata.present? ? doi.from_xml(doi.current_metadata.xml).to_s.force_encoding("UTF-8").presence : nil
unless string.present?
logger.error "[MySQL] No metadata for DOI " + doi.doi + " found: " + doi.current_metadata.inspect
return nil
Expand Down Expand Up @@ -397,7 +397,7 @@ def self.import_by_day(options={})
Doi.where(created: from_date.midnight..from_date.end_of_day).find_each do |doi|
begin
# ignore broken xml
string = doi.current_metadata.present? && doi.current_metadata.xml.to_s.start_with?('<?xml version=') ? doi.current_metadata.xml.force_encoding("UTF-8") : nil
string = doi.current_metadata.present? ? doi.from_xml(doi.current_metadata.xml).to_s.force_encoding("UTF-8").presence : nil
unless string.present?
logger.error "[MySQL] No metadata for DOI " + doi.doi + " found."
return nil
Expand Down

0 comments on commit 7e7fe5b

Please sign in to comment.