app/parsers/bulkrax/application_parser.rb in bulkrax-5.1.0 vs app/parsers/bulkrax/application_parser.rb in bulkrax-5.2.0
- old
+ new
@@ -1,21 +1,23 @@
# frozen_string_literal: true
require 'zip'
+require 'marcel'
module Bulkrax
# An abstract class that establishes the API for Bulkrax's import and export parsing.
#
# @abstract Subclass the Bulkrax::ApplicationParser to create a parser that handles a specific format (e.g. CSV, Bagit, XML, etc).
class ApplicationParser # rubocop:disable Metrics/ClassLength
attr_accessor :importerexporter, :headers
alias importer importerexporter
alias exporter importerexporter
delegate :only_updates, :limit, :current_run, :errors, :mapping,
- :seen, :increment_counters, :parser_fields, :user, :keys_without_numbers,
- :key_without_numbers, :status, :status_info, :status_at,
- :exporter_export_path, :exporter_export_zip_path, :importer_unzip_path, :validate_only,
- to: :importerexporter
+ :seen, :increment_counters, :parser_fields, :user, :keys_without_numbers,
+ :key_without_numbers, :status, :set_status_info, :status_info, :status_at,
+ :exporter_export_path, :exporter_export_zip_path, :importer_unzip_path, :validate_only,
+ :zip?, :file?,
+ to: :importerexporter
# @todo Convert to `class_attribute :parser_fiels, default: {}`
def self.parser_fields
{}
end
@@ -273,14 +275,20 @@
end
# rubocop:enable Rails/SkipsModelValidations
# @return [Array<String>]
def required_elements
+ matched_elements = ((importerexporter.mapping.keys || []) & (Bulkrax.required_elements || []))
+ unless matched_elements.count == Bulkrax.required_elements.count
+ missing_elements = Bulkrax.required_elements - matched_elements
+ error_alert = "Missing mapping for at least one required element, missing mappings are: #{missing_elements.join(', ')}"
+ raise StandardError, error_alert
+ end
if Bulkrax.fill_in_blank_source_identifiers
- ['title']
+ Bulkrax.required_elements
else
- ['title', source_identifier]
+ Bulkrax.required_elements + [source_identifier]
end
end
def new_entry(entryclass, type)
entryclass.new(
@@ -347,19 +355,9 @@
Dir["#{folder}/**/**"].each do |file|
zip_file.add(file.sub("#{folder}/", ''), file)
end
end
end
- end
-
- # Is this a file?
- def file?
- parser_fields&.[]('import_file_path') && File.file?(parser_fields['import_file_path'])
- end
-
- # Is this a zip file?
- def zip?
- parser_fields&.[]('import_file_path') && MIME::Types.type_for(parser_fields['import_file_path']).include?('application/zip')
end
# Path for the import
# @return [String]
def import_file_path