app/models/bulkrax/csv_entry.rb in bulkrax-3.2.0 vs app/models/bulkrax/csv_entry.rb in bulkrax-3.3.0
- old
+ new
@@ -97,10 +97,11 @@
build_system_metadata
build_files_metadata unless hyrax_record.is_a?(Collection)
build_relationship_metadata
build_mapping_metadata
+ self.save!
self.parsed_metadata
end
# Metadata required by Bulkrax for round-tripping
@@ -138,10 +139,11 @@
handle_join_on_export(relationship_key, values, mapping[related_parents_parsed_mapping]['join'].present?)
end
end
def build_mapping_metadata
+ mapping = fetch_field_mapping
mapping.each do |key, value|
# these keys are handled by other methods
next if ['model', 'file', related_parents_parsed_mapping, related_children_parsed_mapping].include?(key)
next if value['excluded']
next if Bulkrax.reserved_properties.include?(key) && !field_supported?(key)
@@ -215,10 +217,29 @@
end
end
end
end
+ def build_files
+ file_mapping = mapping['file']&.[]('from')&.first || 'file'
+ file_sets = hyrax_record.file_set? ? Array.wrap(hyrax_record) : hyrax_record.file_sets
+
+ filenames = map_file_sets(file_sets)
+ handle_join_on_export(file_mapping, filenames, mapping['file']&.[]('join')&.present?)
+ build_thumbnail_files if hyrax_record.work?
+ end
+
+ def build_thumbnail_files
+ return unless importerexporter.include_thumbnails
+
+ thumbnail_mapping = 'thumbnail_file'
+ file_sets = Array.wrap(hyrax_record.thumbnail)
+
+ filenames = map_file_sets(file_sets)
+ handle_join_on_export(thumbnail_mapping, filenames, false)
+ end
+
def handle_join_on_export(key, values, join)
if join
parsed_metadata[key] = values.join(' | ') # TODO: make split char dynamic
else
values.each_with_index do |value, i|
@@ -250,11 +271,10 @@
e.is_a?(CsvCollectionEntry)
end
raise ::StandardError, 'Only expected to find one matching entry' if matching_collection_entries.count > 1
identifiers << matching_collection_entries.first&.identifier
end
-
@collection_identifiers = identifiers.compact.presence || []
end
def collections_created?
# TODO: look into if this method is still needed after new relationships code
@@ -280,8 +300,14 @@
return file if File.exist?(file)
path = importerexporter.parser.path_to_files
f = File.join(path, file)
return f if File.exist?(f)
raise "File #{f} does not exist"
+ end
+
+ private
+
+ def map_file_sets(file_sets)
+ file_sets.map { |fs| filename(fs).to_s if filename(fs).present? }.compact
end
end
end