app/parsers/bulkrax/xml_parser.rb in bulkrax-5.1.0 vs app/parsers/bulkrax/xml_parser.rb in bulkrax-5.2.0

- old
+ new

@@ -1,6 +1,7 @@ # frozen_string_literal: true +require 'marcel' module Bulkrax class XmlParser < ApplicationParser def entry_class Bulkrax::XmlEntry @@ -29,11 +30,11 @@ def valid_import? raise StandardError, 'No metadata files found' if metadata_paths.blank? raise StandardError, 'No records found' if records.blank? true rescue StandardError => e - status_info(e) + set_status_info(e) false end # For multiple, we expect to find metadata for multiple works in the given metadata file(s) # For single, we expect to find metadata for a single work in the given metadata file(s) @@ -76,20 +77,23 @@ # If the import_file_path is an xml file, return that # Otherwise return all xml files in the given folder def metadata_paths @metadata_paths ||= - if file? && MIME::Types.type_for(import_file_path).include?('application/xml') + if file? && good_file_type?(import_file_path) [import_file_path] else file_paths.select do |f| - MIME::Types.type_for(f).include?('application/xml') && - f.include?("import_#{importerexporter.id}") + good_file_type?(f) && f.include?("import_#{importerexporter.id}") end end end + def good_file_type?(path) + %w[.xml .xls .xsd].include?(File.extname(path)) || ::Marcel::MimeType.for(path).include?('application/xml') + end + def create_works records.each_with_index do |record, index| next unless record_has_source_identifier(record, index) break if !limit.nil? && index >= limit @@ -102,10 +106,10 @@ end increment_counters(index, work: true) end importer.record_status rescue StandardError => e - status_info(e) + set_status_info(e) end def total records.size end