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

Iiif manifiest backport #4412

Merged
merged 8 commits into from
Jul 8, 2020
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
25 changes: 18 additions & 7 deletions app/controllers/concerns/hyrax/works_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ module WorksControllerBehavior
with_themed_layout :decide_layout
copy_blacklight_config_from(::CatalogController)

class_attribute :_curation_concern_type, :show_presenter, :work_form_service, :search_builder_class
class_attribute :_curation_concern_type, :show_presenter, :work_form_service, :search_builder_class, :iiif_manifest_builder
self.show_presenter = Hyrax::WorkShowPresenter
self.work_form_service = Hyrax::WorkFormService
self.search_builder_class = WorkSearchBuilder
self.iiif_manifest_builder = (Flipflop.cache_work_iiif_manifest? ? Hyrax::CachingIiifManifestBuilder.new : Hyrax::ManifestBuilderService.new)
attr_accessor :curation_concern
helper_method :curation_concern, :contextual_path

Expand Down Expand Up @@ -127,14 +128,28 @@ def inspect_work

def manifest
headers['Access-Control-Allow-Origin'] = '*'

json = iiif_manifest_builder.manifest_for(presenter: iiif_manifest_presenter)

respond_to do |wants|
wants.json { render json: manifest_builder.to_h }
wants.html { render json: manifest_builder.to_h }
wants.json { render json: json }
wants.html { render json: json }
end
end

private

def iiif_manifest_builder
self.class.iiif_manifest_builder
end

def iiif_manifest_presenter
IiifManifestPresenter.new(curation_concern_from_search_results).tap do |p|
p.hostname = request.hostname
p.ability = current_ability
end
end

def user_collections
collections_service.search_results(:deposit)
end
Expand All @@ -157,10 +172,6 @@ def build_form
@form = work_form_service.build(curation_concern, current_ability, self)
end

def manifest_builder
::IIIFManifest::ManifestFactory.new(presenter)
end

def actor
@actor ||= Hyrax::CurationConcern.actor
end
Expand Down
16 changes: 16 additions & 0 deletions app/jobs/iiif_manifest_cache_prewarm_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class IiifManifestCachePrewarmJob < Hyrax::ApplicationJob
##
# @param work [ActiveFedora::Base]
def perform(work)
presenter = Hyrax::IiifManifestPresenter.new(work)
manifest_builder.manifest_for(presenter: presenter)
end

private

def manifest_builder
Hyrax::CachingIiifManifestBuilder.new
end
end
1 change: 1 addition & 0 deletions app/models/concerns/hyrax/solr_document/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def self.coerce(input)
attribute :read_groups, Solr::Array, ::Ability.read_group_field
attribute :collection_ids, Solr::Array, 'collection_ids_tesim'
attribute :admin_set, Solr::Array, solr_name('admin_set')
attribute :member_ids, Solr::Array, "member_ids_ssim"
attribute :member_of_collection_ids, Solr::Array, solr_name('member_of_collection_ids', :symbol)
attribute :description, Solr::Array, solr_name('description')
attribute :title, Solr::Array, solr_name('title')
Expand Down
10 changes: 10 additions & 0 deletions app/models/concerns/hyrax/solr_document_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,20 @@ def to_model
@model ||= ModelWrapper.new(hydra_model, id)
end

##
# @return [Boolean]
def collection?
hydra_model == ::Collection
end

##
# @return [Boolean]
def file_set?
hydra_model == ::FileSet
end

##
# @return [Boolean]
def admin_set?
hydra_model == ::AdminSet
end
Expand Down
46 changes: 25 additions & 21 deletions app/presenters/hyrax/displays_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,55 @@ module DisplaysImage
# @return [IIIFManifest::DisplayImage] the display image required by the manifest builder.
def display_image
return nil unless solr_document.image? && current_ability.can?(:read, solr_document)

latest_file_id = lookup_original_file_id

return nil unless latest_file_id

url = Hyrax.config.iiif_image_url_builder.call(
latest_file_id,
request.base_url,
Hyrax.config.iiif_image_size_default
)

# @see https://github.com/samvera-labs/iiif_manifest
IIIFManifest::DisplayImage.new(url,
format: image_format([]),
IIIFManifest::DisplayImage.new(display_image_url(request.base_url),
format: image_format(alpha_channels),
width: width,
height: height,
iiif_endpoint: iiif_endpoint(latest_file_id))
end

private

def iiif_endpoint(file_id)
def display_image_url(base_url)
Hyrax.config.iiif_image_url_builder.call(
latest_file_id,
base_url,
Hyrax.config.iiif_image_size_default
)
end

def iiif_endpoint(file_id, base_url: request.base_url)
return unless Hyrax.config.iiif_image_server?
IIIFManifest::IIIFEndpoint.new(
Hyrax.config.iiif_info_url_builder.call(file_id, request.base_url),
Hyrax.config.iiif_info_url_builder.call(file_id, base_url),
profile: Hyrax.config.iiif_image_compliance_level_uri
)
end

def image_format(channels)
channels.find { |c| c.include?('rgba') }.nil? ? 'jpg' : 'png'
channels&.find { |c| c.include?('rgba') }.nil? ? 'jpg' : 'png'
end

def unindexed_current_file_version
Rails.logger.warn "Indexed current_file_version for #{id} not found, falling back to Fedora."
ActiveFedora::File.uri_to_id(::FileSet.find(id).current_content_version_uri)
end

def lookup_original_file_id
result = original_file_id
if result.blank?
Rails.logger.warn "original_file_id for #{id} not found, falling back to Fedora."
result = ActiveFedora::File.uri_to_id(::FileSet.find(id).current_content_version_uri)
end
result
def latest_file_id
@latest_file_id ||=
begin
result = original_file_id

if result.blank?
Rails.logger.warn "original_file_id for #{id} not found, falling back to Fedora."
result = Hyrax::VersioningService.versioned_file_id ::FileSet.find(id).original_file
end

result
end
end
end
end
Loading