Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the Hyrax::FileSetFileService to determine "primary file" #6752

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback in #primary_file (at least) does

fallback_id = file_set.file_ids.first

This should probably use a query service too instead, yeah? (Maybe we need a “first file metadata in file set” query?)

I’d also very much like to get rid of the dependence on file_set.original_file_id in that method (which I think suffers from the same modelling issues that file_ids does), but I couldn’t figure out a way how when I wrote that method originally. Is there a query we could use for that instead?

(The difference between the service and any original file query is, and should remain, that the service has fallback behaviour if there is no original file, whereas the query would return nil.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you're probably right, on both points.

i remember the #primary_file setup being pretty fussy though (between Wings and PG), and i think for our purposes it's moot anyway, since we want to override this whole service in comet. getting this much through unblocks that, and next steps can be explored from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: original_file_id, i think custom_queries.find_original_file(file_set: file_set) is the preferred approach, and is executed in the other branch. but i presume there's a reason for original_file_id getting used preferentially.

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