Skip to content

Commit

Permalink
Merge branch 'main' into i84-support-dynamic-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaLMoore committed Jul 5, 2024
2 parents 8d949ea + 0fb7c04 commit 7f5231c
Show file tree
Hide file tree
Showing 31 changed files with 212 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ def destroy(env)
end
end
end
Hyrax::Actors::CleanupFileSetsActor.prepend(IiifPrint::Actors::CleanupFileSetsActorDecorator)
1 change: 1 addition & 0 deletions app/actors/iiif_print/actors/file_set_actor_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ def destroy
end
end
end
Hyrax::Actors::FileSetActor.prepend(IiifPrint::Actors::FileSetActorDecorator)
1 change: 1 addition & 0 deletions app/helpers/iiif_print/iiif_helper_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ def uv_search_param
end
end
end
Hyrax::IiifHelper.prepend(IiifPrint::IiifHelperDecorator)
27 changes: 0 additions & 27 deletions app/indexers/concerns/iiif_print/child_work_indexer.rb

This file was deleted.

45 changes: 45 additions & 0 deletions app/indexers/concerns/iiif_print/child_work_indexer_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

module IiifPrint
module ChildWorkIndexerDecorator
def to_solr
super.tap do |index_document|
index_solr_doc(index_document)
end
end

def generate_solr_document
super.tap do |solr_doc|
index_solr_doc(solr_doc)
end
end

private

def index_solr_doc(solr_doc)
object ||= @object || resource
solr_doc['is_child_bsi'] ||= object.try(:is_child)
solr_doc['split_from_pdf_id_ssi'] ||= object.try(:split_from_pdf_id)
solr_doc['is_page_of_ssim'] = iiif_print_lineage_service.ancestor_ids_for(object)
solr_doc['member_ids_ssim'] = iiif_print_lineage_service.descendent_member_ids_for(object)
end
end
end

if ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_VALKYRIE', false))
# Newer versions of Hyrax favor `Hyrax::Indexers::PcdmObjectIndexer` and deprecate
# `Hyrax::ValkyrieWorkIndexer`
indexers = Hyrax.config.curation_concerns.map do |concern|
"#{concern}ResourceIndexer".safe_constantize
end
indexers.each { |indexer| indexer.prepend(IiifPrint::ChildWorkIndexerDecorator) }

# Versions 3.0+ of Hyrax have `Hyrax::ValkyrieWorkIndexer` so we want to decorate that as
# well. We want to use the elsif construct because later on Hyrax::ValkyrieWorkIndexer
# inherits from Hyrax::Indexers::PcdmObjectIndexer and only implements:
# `def initialize(*args); super; end`
'Hyrax::ValkyrieWorkIndexer'.safe_constantize&.prepend(IiifPrint::ChildWorkIndexerDecorator)
else
# The ActiveFedora::Base indexer for Works
Hyrax::WorkIndexer.prepend(IiifPrint::ChildWorkIndexerDecorator)
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module IiifPrint
module FileSetIndexer
module FileSetIndexerDecorator
def to_solr
super.tap do |index_document|
index_solr_doc(index_document)
Expand Down Expand Up @@ -55,3 +55,17 @@ def all_text(object)
end
end
end
if ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYRAX_VALKYRIE', false))
# Newer versions of Hyrax favor `Hyrax::Indexers::FileSetIndexer` and deprecate
# `Hyrax::ValkyrieFileSetIndexer`.
'Hyrax::Indexers::FileSetIndexer'.safe_constantize&.prepend(IiifPrint::FileSetIndexerDecorator)

# Versions 3.0+ of Hyrax have `Hyrax::ValkyrieFileSetIndexer` so we want to decorate that as
# well. We want to use the elsif construct because later on Hyrax::ValkyrieFileSetIndexer
# inherits from Hyrax::Indexers::FileSetIndexer and only implements:
# `def initialize(*args); super; end`
'Hyrax::ValkyrieFileSetIndexer'.safe_constantize&.prepend(IiifPrint::FileSetIndexerDecorator)
else
# The ActiveFedora::Base indexer for FileSets
Hyrax::FileSetIndexer.prepend(IiifPrint::FileSetIndexerDecorator)
end
63 changes: 0 additions & 63 deletions app/models/concerns/iiif_print/solr/document.rb

This file was deleted.

47 changes: 47 additions & 0 deletions app/models/concerns/iiif_print/solr_document_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module IiifPrint
module SolrDocumentDecorator
def digest_sha1
digest[/urn:sha1:([\w]+)/, 1]
end

def method_missing(method_name, *args, &block)
super unless iiif_print_solr_field_names.include? method_name.to_s
self[IiifPrint.solr_name(method_name.to_s)]
end

def respond_to_missing?(method_name, include_private = false)
iiif_print_solr_field_names.include?(method_name.to_s) || super
end

# @see https://github.com/samvera/hyrax/commit/7108409c619cd2ba4ae8c836b9f3b429a7e9837b
def file_set_ids
# Yes, this looks a little odd. But the truth is the prior key (e.g. `file_set_ids_ssim`) was
# an alias of `member_ids_ssim`.
self['member_ids_ssim']
end

def any_highlighting?
response&.[]('highlighting')&.[](id)&.present?
end

def solr_document
self
end
end
end

SolrDocument.prepend(IiifPrint::SolrDocumentDecorator)
SolrDocument.attribute :is_child, Hyrax::SolrDocument::Metadata::Solr::String, 'is_child_bsi'
SolrDocument.attribute :split_from_pdf_id, Hyrax::SolrDocument::Metadata::Solr::String, 'split_from_pdf_id_ssi'
SolrDocument.attribute :digest, Hyrax::SolrDocument::Metadata::Solr::String, 'digest_ssim'

# @note These properties came from the newspaper_works gem. They are configurable.
SolrDocument.class_attribute :iiif_print_solr_field_names, default: %w[alternative_title genre
issn lccn oclcnum held_by text_direction
page_number section author photographer
volume issue_number geographic_coverage
extent publication_date height width
edition_number edition_name frequency preceded_by
succeeded_by]
1 change: 1 addition & 0 deletions app/models/iiif_print/iiif_search_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ def solr_params
end
end
end
::BlacklightIiifSearch::IiifSearch.prepend(IiifPrint::IiifSearchDecorator)
1 change: 1 addition & 0 deletions app/models/iiif_print/iiif_search_response_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ def add_metadata_match(json_results)
end
end
end
::BlacklightIiifSearch::IiifSearchResponse.prepend(IiifPrint::IiifSearchResponseDecorator)
1 change: 1 addition & 0 deletions app/presenters/iiif_print/file_set_presenter_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ def show_split_button?
end
end
end
Hyrax::FileSetPresenter.prepend(IiifPrint::FileSetPresenterDecorator)
Original file line number Diff line number Diff line change
@@ -1,38 +1,9 @@
# mixin to provide URL for IIIF Content Search service
module IiifPrint
module IiifManifestPresenterBehavior
extend ActiveSupport::Concern

# Extending the presenter to the base url which includes the protocol.
# We need the base url to render the facet links and normalize the interface.
attr_accessor :base_url

def manifest_metadata
# ensure we are using a SolrDocument
@manifest_metadata ||= IiifPrint.manifest_metadata_from(work: model.solr_document, presenter: self)
end

def search_service
Rails.application.routes.url_helpers.solr_document_iiif_search_url(id, host: hostname)
end

# OVERRIDE: Hyrax 3x, avoid nil returning to IIIF Manifest gem
# @see https://github.com/samvera/iiif_manifest/blob/c408f90eba11bef908796c7236ba6bcf8d687acc/lib/iiif_manifest/v3/manifest_builder/record_property_builder.rb#L28
##
# @return [Array<Hash{String => String}>]
def sequence_rendering
Array(try(:rendering_ids)).map do |file_set_id|
rendering = file_set_presenters.find { |p| p.id == file_set_id }
return [] unless rendering

{ '@id' => Hyrax::Engine.routes.url_helpers.download_url(rendering.id, host: hostname),
'format' => rendering.mime_type.presence || I18n.t("hyrax.manifest.unknown_mime_text"),
'label' => I18n.t("hyrax.manifest.download_text") + (rendering.label || '') }
end.flatten
end

module IiifManifestPresenter
# OVERRIDE: Hyrax v3.x
module DisplayImagePresenterBehavior
module DisplayImagePresenterDecorator
extend ActiveSupport::Concern
# Extending the presenter to the base url which includes the protocol.
# We need the base url to render the facet links and normalize the interface.
attr_accessor :base_url
Expand Down Expand Up @@ -128,3 +99,4 @@ def iiif_image_url_builder(url_builder:)
end
end
end
Hyrax::IiifManifestPresenter::DisplayImagePresenter.prepend(IiifPrint::IiifManifestPresenter::DisplayImagePresenterDecorator)
35 changes: 35 additions & 0 deletions app/presenters/iiif_print/iiif_manifest_presenter_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# mixin to provide URL for IIIF Content Search service
module IiifPrint
module IiifManifestPresenterDecorator
extend ActiveSupport::Concern

# Extending the presenter to the base url which includes the protocol.
# We need the base url to render the facet links and normalize the interface.
attr_accessor :base_url

def manifest_metadata
# ensure we are using a SolrDocument
@manifest_metadata ||= IiifPrint.manifest_metadata_from(work: model.solr_document, presenter: self)
end

def search_service
Rails.application.routes.url_helpers.solr_document_iiif_search_url(id, host: hostname)
end

# OVERRIDE: Hyrax 3x, avoid nil returning to IIIF Manifest gem
# @see https://github.com/samvera/iiif_manifest/blob/c408f90eba11bef908796c7236ba6bcf8d687acc/lib/iiif_manifest/v3/manifest_builder/record_property_builder.rb#L28
##
# @return [Array<Hash{String => String}>]
def sequence_rendering
Array(try(:rendering_ids)).map do |file_set_id|
rendering = file_set_presenters.find { |p| p.id == file_set_id }
return [] unless rendering

{ '@id' => Hyrax::Engine.routes.url_helpers.download_url(rendering.id, host: hostname),
'format' => rendering.mime_type.presence || I18n.t("hyrax.manifest.unknown_mime_text"),
'label' => I18n.t("hyrax.manifest.download_text") + (rendering.label || '') }
end.flatten
end
end
end
Hyrax::IiifManifestPresenter.prepend(IiifPrint::IiifManifestPresenterDecorator)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module IiifPrint
module IiifManifestPresenterFactoryBehavior
module IiifManifestPresenterFactoryDecorator
# This will override Hyrax::IiifManifestPresenter::Factory#build and introducing
# the expected behavior:
# - child work images show as canvases in the parent work manifest
Expand Down Expand Up @@ -31,3 +31,4 @@ def load_file_set_docs(file_set_ids)
end
end
end
Hyrax::IiifManifestPresenter::Factory.prepend(IiifPrint::IiifManifestPresenterFactoryDecorator)
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ def search_path(value)
end
end
end
Hyrax::Renderers::FacetedAttributeRenderer.prepend(Hyrax::Renderers::FacetedAttributeRendererDecorator)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module IiifPrint
# rubocop:disable Metrics/ModuleLength
module ManifestBuilderServiceBehavior
module ManifestBuilderServiceDecorator
def initialize(*args,
version: IiifPrint.config.default_iiif_manifest_version,
iiif_manifest_factory: iiif_manifest_factory_for(version),
Expand Down Expand Up @@ -154,3 +154,4 @@ def get_solr_hits(ids)
end
# rubocop:enable Metrics/ClassLength
end
Hyrax::ManifestBuilderService.prepend(IiifPrint::ManifestBuilderServiceDecorator)
1 change: 1 addition & 0 deletions app/services/iiif_print/simple_schema_loader_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ def config_search_paths
end
end
end
Hyrax::SimpleSchemaLoader.prepend(IiifPrint::SimpleSchemaLoaderDecorator)
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ def call(resource, user: nil)
end
end
end

"Hyrax::Transactions::Steps::DeleteAllFileSets".safe_constantize&.prepend(Hyrax::Transactions::Steps::DeleteAllFileSetsDecorator)
1 change: 0 additions & 1 deletion config/initializers/simple_schema_loader.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/iiif_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
require "iiif_print/tiff_derivative_service"
require "iiif_print/lineage_service"
require "iiif_print/metadata"
require "iiif_print/works_controller_behavior"
require "iiif_print/blacklight_iiif_search/annotation_decorator"
require "iiif_print/split_pdfs/base_splitter"
require "iiif_print/split_pdfs/child_work_creation_from_pdf_service"
require "iiif_print/split_pdfs/derivative_rodeo_splitter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ def text_resource_for_annotation
end
end
end
::BlacklightIiifSearch::IiifSearchAnnotation.prepend(IiifPrint::BlacklightIiifSearch::AnnotationDecorator)
2 changes: 1 addition & 1 deletion lib/iiif_print/data/fileset_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def fileset_id
def first_fileset
# if context is fileset id (e.g. caller is view partial) string,
# get the fileset from that id
return FileSet.find(@work) if @work.is_a?(String)
return Hyrax.query_service.find_by(id: @work) if @work.is_a?(String)
# if "work" context is a FileSet, not actual work, return it
return @work if @work.is_a?(Hyrax::FileSet) || @work.is_a?(FileSet)
# in most cases, get from work's members:
Expand Down
Loading

0 comments on commit 7f5231c

Please sign in to comment.