Skip to content

Commit

Permalink
use the Hyrax::FileSetFileService to determine "primary file"
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
tamsin woo committed Mar 27, 2024
1 parent 56c25f0 commit 106a22c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/hyrax/file_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion app/services/hyrax/file_set_file_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions app/services/hyrax/valkyrie_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 106a22c

Please sign in to comment.