From 106a22c0c33674955f7d69c5f4c4d501f16b20d9 Mon Sep 17 00:00:00 2001 From: tamsin woo Date: Tue, 26 Mar 2024 15:05:35 -0700 Subject: [PATCH] use the `Hyrax::FileSetFileService` to determine "primary file" `Hyrax::FileSetFileService` was introduced to un-hard code the assumption that the `:original_file` PCDM Use is the "primary" file for a given file set. use it throughout the code base to avoid requiring that assumption in downstream apps. --- app/controllers/hyrax/file_sets_controller.rb | 2 +- app/services/hyrax/file_set_file_service.rb | 11 ++++++++++- app/services/hyrax/valkyrie_upload.rb | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/hyrax/file_sets_controller.rb b/app/controllers/hyrax/file_sets_controller.rb index 31c63edaef..11bd5a6fe9 100644 --- a/app/controllers/hyrax/file_sets_controller.rb +++ b/app/controllers/hyrax/file_sets_controller.rb @@ -292,7 +292,7 @@ def wants_to_revert_valkyrie? end def file_metadata - @file_metadata ||= Hyrax.query_service.custom_queries.find_file_metadata_by(id: curation_concern.original_file_id) + @file_metadata ||= Hyrax.config.file_set_file_service.primary_file_for(file_set: file_set) end # Override this method to add additional response formats to your local app diff --git a/app/services/hyrax/file_set_file_service.rb b/app/services/hyrax/file_set_file_service.rb index 376a7cf708..cabc5f2898 100644 --- a/app/services/hyrax/file_set_file_service.rb +++ b/app/services/hyrax/file_set_file_service.rb @@ -32,7 +32,16 @@ def initialize(file_set:, query_service: Hyrax.query_service) end ## - # Return the Hyrax::FileMetadata which should be considered “primary” for + # Return the {Hyrax::FileMetadata} which should be considered “primary” for + # indexing and version‐tracking. + # + # @return [Hyrax::FileMetadata] + def self.primary_file_for(file_set:, query_service: Hyrax.query_service) + new(file_set: file_set, query_service: query_service).primary_file + end + + ## + # Return the {Hyrax::FileMetadata} which should be considered “primary” for # indexing and version‐tracking. # # If +file_set.original_file_id+ is defined, it will be used; otherwise, diff --git a/app/services/hyrax/valkyrie_upload.rb b/app/services/hyrax/valkyrie_upload.rb index d18a26a24d..3860d75dc6 100644 --- a/app/services/hyrax/valkyrie_upload.rb +++ b/app/services/hyrax/valkyrie_upload.rb @@ -30,8 +30,10 @@ def self.file( attr_reader :storage_adapter ## # @param [Valkyrie::StorageAdapter] storage_adapter - def initialize(storage_adapter: Hyrax.storage_adapter) + # @param [Class] file_set_file_service implementer of {Hyrax::FileSetFileService} + def initialize(storage_adapter: Hyrax.storage_adapter, file_set_file_service: Hyrax.config.file_set_file_service) @storage_adapter = storage_adapter + @file_set_file_service = file_set_file_service end def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FILE, user: nil, mime_type: nil) # rubocop:disable Metrics/AbcSize @@ -67,7 +69,8 @@ def upload(filename:, file_set:, io:, use: Hyrax::FileMetadata::Use::ORIGINAL_FI end def version_upload(file_set:, io:, user:) - file_metadata = Hyrax.query_service.custom_queries.find_file_metadata_by(id: file_set.original_file_id) + file_metadata = @file_set_file_service.primary_file_for(file_set: file_set) + Hyrax::VersioningService.create(file_metadata, user, io) Hyrax.publisher.publish("file.uploaded", metadata: file_metadata) ContentNewVersionEventJob.perform_later(file_set, user)