app/models/bulkrax/csv_entry.rb in bulkrax-7.0.0 vs app/models/bulkrax/csv_entry.rb in bulkrax-8.0.0

- old
+ new

@@ -1,9 +1,7 @@ # frozen_string_literal: true -require 'csv' - module Bulkrax # TODO: We need to rework this class some to address the Metrics/ClassLength rubocop offense. # We do too much in these entry classes. We need to extract the common logic from the various # entry models into a module that can be shared between them. class CsvEntry < Entry # rubocop:disable Metrics/ClassLength @@ -104,11 +102,11 @@ add_metadata('model', record[key]) if record.key?(key) end end def add_metadata_for_model - if defined?(::Collection) && factory_class == ::Collection + if factory_class.present? && factory_class == Bulkrax.collection_model_class add_collection_type_gid if defined?(::Hyrax) # add any additional collection metadata methods here elsif factory_class == Bulkrax.file_model_class validate_presence_of_filename! add_path_to_file @@ -144,11 +142,11 @@ def build_export_metadata self.parsed_metadata = {} build_system_metadata - build_files_metadata if defined?(Collection) && !hyrax_record.is_a?(Collection) + build_files_metadata if Bulkrax.collection_model_class.present? && !hyrax_record.is_a?(Bulkrax.collection_model_class) build_relationship_metadata build_mapping_metadata self.save! self.parsed_metadata @@ -156,12 +154,15 @@ # Metadata required by Bulkrax for round-tripping def build_system_metadata self.parsed_metadata['id'] = hyrax_record.id source_id = hyrax_record.send(work_identifier) - source_id = source_id.to_a.first if source_id.is_a?(ActiveTriples::Relation) + # Because ActiveTriples::Relation does not respond to #to_ary we can't rely on Array.wrap universally + source_id = source_id.to_a if source_id.is_a?(ActiveTriples::Relation) + source_id = Array.wrap(source_id).first self.parsed_metadata[source_identifier] = source_id - self.parsed_metadata[key_for_export('model')] = hyrax_record.has_model.first + model_name = hyrax_record.respond_to?(:to_rdf_representation) ? hyrax_record.to_rdf_representation : hyrax_record.has_model.first + self.parsed_metadata[key_for_export('model')] = model_name end def build_files_metadata # attaching files to the FileSet row only so we don't have duplicates when importing to a new tenant if hyrax_record.work?