Skip to content

Commit

Permalink
Fixes issues with filesets exporting in Valkyrie (#991)
Browse files Browse the repository at this point in the history
* Fixes issues with filesets to exporting in Valkyrie versions of Hyrax/Hyku

* fixed issue where Marcel expects labelled arguments now.

* accounts for valkyrie storage, and allows for exporting of files.

* fixed missing open call for non-valkyrie io
  • Loading branch information
sephirothkod authored Dec 6, 2024
1 parent 39ec77d commit 13a37b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 8 additions & 4 deletions app/models/concerns/bulkrax/export_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions app/parsers/bulkrax/csv_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,18 @@ 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')
FileUtils.mkdir_p(path) unless File.exist? path
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
Expand Down
2 changes: 1 addition & 1 deletion app/parsers/bulkrax/parser_export_record_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 13a37b4

Please sign in to comment.