Skip to content

Commit

Permalink
Give IIIF Manifests Some Wings (#6102)
Browse files Browse the repository at this point in the history
* make sure rendering ids get indexed

* manifests should look for hyrax::filesets along with ::filesets

* update riiif path generator to be valkyrie aware

* index fields needed for riiif

Co-authored-by: Alisha Evans <[email protected]>

---------

Co-authored-by: Daniel Pierce <[email protected]>
Co-authored-by: Alisha Evans <[email protected]>
  • Loading branch information
3 people authored Jun 30, 2023
1 parent 33d9f16 commit 49d6b9c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 deletions.
16 changes: 13 additions & 3 deletions .dassie/config/initializers/riiif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@
{ height: doc['height_is'], width: doc['width_is'], format: doc['mime_type_ssi'], channels: doc['alpha_channels_ssi'] }
end

Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
if Hyrax.config.use_valkyrie?
# Use Valkyrie adapter to make sure file is available locally. Riiif will just open it then
# id comes in with the format "FILE_SET_ID/files/FILE_ID"
Riiif::Image.file_resolver.id_to_uri = lambda do |id|
file_metadata = Hyrax.query_service.find_by(id: id.split('/').last)
file = Hyrax.storage_adapter.find_by(id: file_metadata.file_identifier)
file.disk_path.to_s
end
else
Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
end
end
end

Expand Down
17 changes: 13 additions & 4 deletions .koppie/config/initializers/riiif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
{ height: doc['height_is'], width: doc['width_is'], format: doc['mime_type_ssi'], channels: doc['alpha_channels_ssi'] }
end

Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
if Hyrax.config.use_valkyrie?
# Use Valkyrie adapter to make sure file is available locally. Riiif will just open it then
# id comes in with the format "FILE_SET_ID/files/FILE_ID"
Riiif::Image.file_resolver.id_to_uri = lambda do |id|
file_metadata = Hyrax.query_service.find_by(id: id.split('/').last)
file = Hyrax.storage_adapter.find_by(id: file_metadata.file_identifier)
file.disk_path.to_s
end
else
Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
end
end
end

Riiif::Image.authorization_service = Hyrax::IiifAuthorizationService

Riiif.not_found_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg')
Expand Down
10 changes: 9 additions & 1 deletion app/indexers/hyrax/valkyrie_file_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met

# Metadata from the FileSet
solr_doc['file_ids_ssim'] = resource.file_ids&.map(&:to_s)
solr_doc['original_file_id_ssi'] = resource.original_file_id.to_s
solr_doc['original_file_id_ssi'] = original_file_id
solr_doc['extracted_text_id_ssi'] = resource.extracted_text_id.to_s
solr_doc['hasRelatedMediaFragment_ssim'] = resource.representative_id.to_s
solr_doc['hasRelatedImage_ssim'] = resource.thumbnail_id.to_s
Expand Down Expand Up @@ -56,10 +56,13 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met

solr_doc['height_tesim'] = file_metadata.height if file_metadata.height.present? # image, video
solr_doc['width_tesim'] = file_metadata.width if file_metadata.width.present? # image, video
solr_doc['height_is'] = Integer(file_metadata.height.first) if file_metadata.height.present?
solr_doc['width_is'] = Integer(file_metadata.width.first) if file_metadata.width.present?

# attributes set by fits for audio files
solr_doc['bit_depth_tesim'] = file_metadata.bit_depth if file_metadata.bit_depth.present?
solr_doc['channels_tesim'] = file_metadata.channels if file_metadata.channels.present?
solr_doc['alpha_channels_ssi'] = file_metadata.channels.first if file_metadata.channels.present?
solr_doc['data_format_tesim'] = file_metadata.data_format if file_metadata.data_format.present?
solr_doc['offset_tesim'] = file_metadata.offset if file_metadata.offset.present?

Expand Down Expand Up @@ -99,6 +102,11 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met

private

# Convert Valkyrie Original File Pointer to versioned url syntax expected by the iiif_presenter
def original_file_id
"#{resource.id}/files/#{resource.original_file_id}"
end

def file_format(file)
if file.mime_type.present? && file.format_label.present?
"#{file.mime_type.split('/').last} (#{file.format_label.join(', ')})"
Expand Down
1 change: 1 addition & 0 deletions app/indexers/hyrax/valkyrie_work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met
solr_doc['depositor_tesim'] = [resource.depositor]
solr_doc['hasRelatedMediaFragment_ssim'] = [resource.representative_id.to_s]
solr_doc['hasRelatedImage_ssim'] = [resource.thumbnail_id.to_s]
solr_doc['hasFormat_ssim'] = resource.rendering_ids.map(&:to_s) if resource.rendering_ids.present?
index_embargo(solr_doc)
index_lease(solr_doc)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/solr_document_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def collection?
##
# @return [Boolean]
def file_set?
hydra_model == ::FileSet
hydra_model == ::FileSet || hydra_model == Hyrax::FileSet
end

##
Expand Down
10 changes: 3 additions & 7 deletions app/presenters/hyrax/iiif_manifest_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def hostname
##
# @return [Boolean]
def file_set?
model.try(:file_set?) || Array(model[:has_model_ssim]).include?('FileSet')
model.try(:file_set?) || Array(model[:has_model_ssim]).include?('FileSet') || Array(model[:has_model_ssim]).include?('Hyrax::FileSet')
end

##
Expand Down Expand Up @@ -93,12 +93,8 @@ def manifest_url
##
# @return [Array<#to_s>]
def member_ids
case model
when Valkyrie::Resource
Array(model.try(:member_ids))
else
Hyrax::SolrDocument::OrderedMembers.decorate(model).ordered_member_ids
end
m = model.is_a?(::SolrDocument) ? model.hydra_model : model
m.class < Hyrax::Resource ? Array(model.member_ids) : Hyrax::SolrDocument::OrderedMembers.decorate(model).ordered_member_ids
end

##
Expand Down
20 changes: 15 additions & 5 deletions lib/generators/hyrax/templates/config/initializers/riiif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@
{ height: doc['height_is'], width: doc['width_is'], format: doc['mime_type_ssi'], channels: doc['alpha_channels_ssi'] }
end

Riiif::Image.file_resolver.id_to_uri = lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Hyrax.logger.info "Riiif resolved #{id} to #{url}"
end
end
Riiif::Image.file_resolver.id_to_uri = if Hyrax.config.use_valkyrie?
# Use Valkyrie adapter to make sure file is available locally. Riiif will just open it then
# id comes in with the format "FILE_SET_ID/files/FILE_ID"
lambda do |id|
file_metadata = Hyrax.query_service.find_by(id: id.split('/').last)
file = Hyrax.storage_adapter.find_by(id: file_metadata.file_identifier)
file.disk_path.to_s
end
else
lambda do |id|
Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url|
Rails.logger.info "Riiif resolved #{id} to #{url}"
end
end
end

Riiif::Image.authorization_service = Hyrax::IiifAuthorizationService

Expand Down
4 changes: 2 additions & 2 deletions spec/indexers/hyrax/valkyrie_file_set_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

# from FileSet metadata
expect(subject['file_ids_ssim']).to match_array [mock_file.id.to_s, mock_text.id.to_s, mock_thumbnail.id.to_s]
expect(subject['original_file_id_ssi']).to eq mock_file.id.to_s
expect(subject['original_file_id_ssi']).to eq "#{fileset_id}/files/#{mock_file.id}"
expect(subject['extracted_text_id_ssi']).to eq mock_text.id.to_s
expect(subject['hasRelatedMediaFragment_ssim']).to eq fileset_id
expect(subject['hasRelatedImage_ssim']).to eq mock_thumbnail.id.to_s
Expand Down Expand Up @@ -236,7 +236,7 @@
# end

it "does not have version info indexed" do
expect(subject['original_file_id_ssi']).to eq file_set.original_file_id.to_s
expect(subject['original_file_id_ssi']).to eq "#{file_set.id}/files/#{file_set.original_file_id}"
end
end
end
Expand Down

0 comments on commit 49d6b9c

Please sign in to comment.