Skip to content

Commit

Permalink
move everything to the established decorator pattern
Browse files Browse the repository at this point in the history
orangewolf committed May 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 830a9af commit c029383
Showing 23 changed files with 101 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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)
@@ -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
1 change: 1 addition & 0 deletions app/models/iiif_print/iiif_search_decorator.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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,6 +1,6 @@
# mixin to provide URL for IIIF Content Search service
module IiifPrint
module IiifManifestPresenterBehavior
module IiifManifestPresenterDecorator
extend ActiveSupport::Concern

# Extending the presenter to the base url which includes the protocol.
@@ -128,3 +128,4 @@ def iiif_image_url_builder(url_builder:)
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
@@ -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
@@ -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),
@@ -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
@@ -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
@@ -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.

Original file line number Diff line number Diff line change
@@ -134,3 +134,4 @@ def text_resource_for_annotation
end
end
end
::BlacklightIiifSearch::IiifSearchAnnotation.prepend(IiifPrint::BlacklightIiifSearch::AnnotationDecorator)
55 changes: 7 additions & 48 deletions lib/iiif_print/engine.rb
Original file line number Diff line number Diff line change
@@ -48,55 +48,14 @@ class Engine < ::Rails::Engine

Hyrax.publisher.subscribe(IiifPrint::Listener.new) if Hyrax.respond_to?(:publisher)

Hyrax::IiifManifestPresenter.prepend(IiifPrint::IiifManifestPresenterBehavior)
Hyrax::IiifManifestPresenter::Factory.prepend(IiifPrint::IiifManifestPresenterFactoryBehavior)
Hyrax::ManifestBuilderService.prepend(IiifPrint::ManifestBuilderServiceBehavior)
Hyrax::Renderers::FacetedAttributeRenderer.prepend(Hyrax::Renderers::FacetedAttributeRendererDecorator)
Hyrax::WorksControllerBehavior.prepend(IiifPrint::WorksControllerBehaviorDecorator)
"Hyrax::Transactions::Steps::DeleteAllFileSets".safe_constantize&.prepend(Hyrax::Transactions::Steps::DeleteAllFileSetsDecorator)
# Hyku::WorksControllerBehavior was introduced in Hyku v6.0.0+. Yes we don't depend on Hyku,
# but this allows us to do minimal Hyku antics with IiifPrint.
'Hyku::WorksControllerBehavior'.safe_constantize&.prepend(IiifPrint::WorksControllerBehaviorDecorator)

Hyrax::FileSetPresenter.prepend(IiifPrint::FileSetPresenterDecorator)
Hyrax::WorkShowPresenter.prepend(IiifPrint::WorkShowPresenterDecorator)
Hyrax::IiifHelper.prepend(IiifPrint::IiifHelperDecorator)

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::FileSetIndexer)

# 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::FileSetIndexer)

# 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::ChildWorkIndexer) }

# 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::ChildWorkIndexer)
else
# The ActiveFedora::Base indexer for FileSets
Hyrax::FileSetIndexer.prepend(IiifPrint::FileSetIndexer)
# The ActiveFedora::Base indexer for Works
Hyrax::WorkIndexer.prepend(IiifPrint::ChildWorkIndexer)
# Allows us to use decorator files
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

::BlacklightIiifSearch::IiifSearchResponse.prepend(IiifPrint::IiifSearchResponseDecorator)
::BlacklightIiifSearch::IiifSearchAnnotation.prepend(IiifPrint::BlacklightIiifSearch::AnnotationDecorator)
::BlacklightIiifSearch::IiifSearch.prepend(IiifPrint::IiifSearchDecorator)
Hyrax::Actors::FileSetActor.prepend(IiifPrint::Actors::FileSetActorDecorator)
Hyrax::Actors::CleanupFileSetsActor.prepend(IiifPrint::Actors::CleanupFileSetsActorDecorator)
Dir.glob(File.join(File.dirname(__FILE__), "../../lib/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

Hyrax.config do |config|
config.callback.set(:after_create_fileset) do |file_set, user|
@@ -108,7 +67,7 @@ class Engine < ::Rails::Engine
config.after_initialize do
IiifPrint::Solr::Document.decorate(SolrDocument)
Hyrax::IiifManifestPresenter::DisplayImagePresenter
.prepend(IiifPrint::IiifManifestPresenterBehavior::DisplayImagePresenterBehavior)
.prepend(IiifPrint::IiifManifestPresenterDecorator::DisplayImagePresenterDecorator)
end
# rubocop:enable Metrics/BlockLength
end
9 changes: 0 additions & 9 deletions lib/iiif_print/works_controller_behavior.rb

This file was deleted.

13 changes: 13 additions & 0 deletions lib/iiif_print/works_controller_behavior_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module IiifPrint
module WorksControllerBehaviorDecorator
# Extending the presenter to the base url which includes the protocol.
# We need the base url to render the facet links.
def iiif_manifest_presenter
super.tap { |i| i.base_url = request.base_url }
end
end
end
Hyrax::WorksControllerBehavior.prepend(IiifPrint::WorksControllerBehaviorDecorator)
# Hyku::WorksControllerBehavior was introduced in Hyku v6.0.0+. Yes we don't depend on Hyku,
# but this allows us to do minimal Hyku antics with IiifPrint.
'Hyku::WorksControllerBehavior'.safe_constantize&.prepend(IiifPrint::WorksControllerBehaviorDecorator)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.describe IiifPrint::IiifManifestPresenterBehavior do
RSpec.describe IiifPrint::IiifManifestPresenterDecorator do
let(:attributes) do
{ "id" => "abc123",
"title_tesim" => ['Page the first'],
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

RSpec.describe IiifPrint::IiifManifestPresenterBehavior do
RSpec.describe IiifPrint::IiifManifestPresenterDecorator do
let(:parent_fs_attributes) do
{ "id" => "parent_fs123",
"title_tesim" => ["My Parent FileSet"],
@@ -35,7 +35,7 @@
it "returns an Array of DisplayImagePresenters" do
allow_any_instance_of(Hyrax::IiifManifestPresenter::Factory)
.to receive(:load_docs).and_return([parent_fs_solr_doc, child_work_solr_doc])
allow_any_instance_of(IiifPrint::IiifManifestPresenterFactoryBehavior)
allow_any_instance_of(IiifPrint::IiifManifestPresenterFactoryDecorator)
.to receive(:load_file_set_docs).and_return([child_fs_solr_doc])
allow(child_work_solr_doc).to receive(:hydra_model).and_return(MyWork)
allow(Hyrax.config).to receive(:curation_concerns).and_return([MyWork])
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe IiifPrint::ManifestBuilderServiceBehavior do
RSpec.describe IiifPrint::ManifestBuilderServiceDecorator do
context '#initialize' do
it 'uses defaults to set the version' do
builder_service = Hyrax::ManifestBuilderService.new

0 comments on commit c029383

Please sign in to comment.