Skip to content

Commit

Permalink
parameterize Hyrax::FileSetFileService
Browse files Browse the repository at this point in the history
open Hyrax to downstream customization of Hyrax::FileSetFileService
  • Loading branch information
tamsin johnson authored and tamsin johnson committed Oct 31, 2023
1 parent f4bceff commit addeadd
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/indexers/hyrax/valkyrie_file_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met
index_lease(solr_doc)
index_embargo(solr_doc)

# Add in metadata from the original file.
file_metadata = Hyrax::FileSetFileService.new(file_set: resource).primary_file
# Add in metadata from the primary file.
file_metadata = Hyrax.config.file_set_file_service.new(file_set: resource).primary_file
return solr_doc unless file_metadata

# Label is the actual file name. It's not editable by the user.
Expand Down
9 changes: 7 additions & 2 deletions app/presenters/hyrax/version_list_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ def initialize(service)
# relevant file versions.
#
# @raise [ArgumentError] if we can't build an enumerable
def self.for(file_set:)
original_file = Hyrax::FileSetFileService.new(file_set: file_set).primary_file
def self.for(file_set:, file_service: Hyrax.config.file_set_file_service)
original_file = case file_set
when ActiveFedora::Base
file_set.original_file
else
file_service.new(file_set: file_set).primary_file
end

new(Hyrax::VersioningService.new(resource: original_file))
rescue NoMethodError
Expand Down
10 changes: 5 additions & 5 deletions app/services/hyrax/file_set_file_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def primary_file
#
# See NOTE above regarding use of :find_file_metadata_by.
@primary_file ||= begin
query_service.custom_queries.find_original_file(file_set: file_set)
rescue Valkyrie::Persistence::ObjectNotFoundError
fallback_id = file_set.file_ids.first
query_service.custom_queries.find_file_metadata_by(id: fallback_id) if fallback_id
end
query_service.custom_queries.find_original_file(file_set: file_set)
rescue Valkyrie::Persistence::ObjectNotFoundError
fallback_id = file_set.file_ids.first
query_service.custom_queries.find_file_metadata_by(id: fallback_id) if fallback_id
end
end
end
alias original_file primary_file
Expand Down
4 changes: 4 additions & 0 deletions lib/generators/hyrax/templates/config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@
# Identify the form that will be used for File Sets
# config.file_set_form = Hyrax::Forms::FileSetForm

# Service for resolving {FileMetadata} nodes by status, e.g. "primary", rather
# than use.
# config.file_set_file_service = Hyrax::FileSetFileService

# Identify the form that will be used for Collections
# config.pcdm_collection_form = Hyrax::Forms::PcdmCollectionForm

Expand Down
8 changes: 8 additions & 0 deletions lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ def derivative_services
@derivative_services ||= [Hyrax::FileSetDerivativesService]
end

##
# @!attribute [rw] file_set_file_service
# @return [Class] implementer of {Hyrax::FileSetFileService}
attr_writer :file_set_file_service
def file_set_file_service
@file_set_file_service ||= Hyrax::FileSetFileService
end

attr_writer :fixity_service
def fixity_service
@fixity_service ||= Hyrax::Fixity::ActiveFedoraFixityService
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/hyrax/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
it { is_expected.to respond_to(:feature_config_path) }
it { is_expected.to respond_to(:file_set_form) }
it { is_expected.to respond_to(:file_set_form=) }
it { is_expected.to respond_to(:file_set_file_service) }
it { is_expected.to respond_to(:file_set_file_service=) }
it { is_expected.to respond_to(:identifier_registrars) }
it { is_expected.to respond_to(:iiif_image_compliance_level_uri) }
it { is_expected.to respond_to(:iiif_image_compliance_level_uri=) }
Expand Down
2 changes: 1 addition & 1 deletion spec/services/hyrax/file_set_file_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
it "finds the original_file" do
expect(service.primary_file)
.to have_attributes(file_set_id: file_set.id,
pcdm_use: contain_exactly("http://pcdm.org/use#OriginalFile"))
pcdm_use: include("http://pcdm.org/use#OriginalFile"))
end
end

Expand Down

0 comments on commit addeadd

Please sign in to comment.