diff --git a/app/models/concerns/bulkrax/export_behavior.rb b/app/models/concerns/bulkrax/export_behavior.rb index 4cfa8513..23a98f50 100644 --- a/app/models/concerns/bulkrax/export_behavior.rb +++ b/app/models/concerns/bulkrax/export_behavior.rb @@ -26,11 +26,15 @@ def hyrax_record # Prepend the file_set id to ensure a unique filename and also one that is not longer than 255 characters def filename(file_set) - # NOTE: Will this work with Valkyrie? return if file_set.original_file.blank? - fn = file_set.original_file.file_name.first - mime = ::Marcel::MimeType.for(file_set.original_file.mime_type) - ext_mime = ::Marcel::MimeType.for(file_set.original_file.file_name) + if file_set.original_file.respond_to?(:original_filename) # valkyrie + fn = file_set.original_file.original_filename + mime = ::Marcel::MimeType.for(file_set.original_file.file.io) + else # original non valkyrie version + fn = file_set.original_file.file_name.first + mime = ::Marcel::MimeType.for(declared_type: file_set.original_file.mime_type) + end + ext_mime = ::Marcel::MimeType.for(name: fn) if fn.include?(file_set.id) || importerexporter.metadata_only? filename = "#{fn}.#{mime.to_sym}" filename = fn if mime.to_s == ext_mime.to_s diff --git a/app/parsers/bulkrax/csv_parser.rb b/app/parsers/bulkrax/csv_parser.rb index 03159ebb..de695a08 100644 --- a/app/parsers/bulkrax/csv_parser.rb +++ b/app/parsers/bulkrax/csv_parser.rb @@ -244,7 +244,10 @@ def store_files(identifier, folder_count) record = Bulkrax.object_factory.find(identifier) return unless record - file_sets = record.file_set? ? Array.wrap(record) : record.file_sets + file_sets = Array.wrap(record) if record.file_set? + if file_sets.nil? # for valkyrie + file_sets = record.respond_to?(:file_sets) ? record.file_sets : record.members&.select(&:file_set?) + end file_sets << record.thumbnail if exporter.include_thumbnails && record.thumbnail.present? && record.work? file_sets.each do |fs| path = File.join(exporter_export_path, folder_count, 'files') @@ -252,7 +255,7 @@ def store_files(identifier, folder_count) file = filename(fs) next if file.blank? || fs.original_file.blank? - io = open(fs.original_file.uri) + io = fs.original_file.respond_to?(:uri) ? open(fs.original_file.uri) : fs.original_file.file.io File.open(File.join(path, file), 'wb') do |f| f.write(io.read) f.close diff --git a/app/parsers/bulkrax/parser_export_record_set.rb b/app/parsers/bulkrax/parser_export_record_set.rb index 30262f94..f80d5c9b 100644 --- a/app/parsers/bulkrax/parser_export_record_set.rb +++ b/app/parsers/bulkrax/parser_export_record_set.rb @@ -173,7 +173,7 @@ def collections # @see https://github.com/samvera/hyrax/blob/64c0bbf0dc0d3e1b49f040b50ea70d177cc9d8f6/app/indexers/hyrax/work_indexer.rb#L15-L18 def file_sets @file_sets ||= ParserExportRecordSet.in_batches(candidate_file_set_ids) do |batch_of_ids| - fsq = "has_model_ssim:#{Bulkrax.file_model_internal_resource} AND id:(\"" + batch_of_ids.join('" OR "') + "\")" + fsq = "has_model_ssim:\"#{Bulkrax.file_model_internal_resource.demodulize}\" AND id:(\"" + batch_of_ids.join('" OR "') + "\")" fsq += extra_filters if extra_filters.present? Bulkrax.object_factory.query( fsq,