diff --git a/app/actors/iiif_print/actors/cleanup_file_sets_actor_decorator.rb b/app/actors/iiif_print/actors/cleanup_file_sets_actor_decorator.rb index 329ed680..a35a2eb0 100644 --- a/app/actors/iiif_print/actors/cleanup_file_sets_actor_decorator.rb +++ b/app/actors/iiif_print/actors/cleanup_file_sets_actor_decorator.rb @@ -22,3 +22,4 @@ def destroy(env) end end end +Hyrax::Actors::CleanupFileSetsActor.prepend(IiifPrint::Actors::CleanupFileSetsActorDecorator) diff --git a/app/actors/iiif_print/actors/file_set_actor_decorator.rb b/app/actors/iiif_print/actors/file_set_actor_decorator.rb index 1b7b3122..144ad076 100644 --- a/app/actors/iiif_print/actors/file_set_actor_decorator.rb +++ b/app/actors/iiif_print/actors/file_set_actor_decorator.rb @@ -56,3 +56,4 @@ def destroy end end end +Hyrax::Actors::FileSetActor.prepend(IiifPrint::Actors::FileSetActorDecorator) diff --git a/app/helpers/iiif_print/iiif_helper_decorator.rb b/app/helpers/iiif_print/iiif_helper_decorator.rb index 819bd5c5..74100ae5 100644 --- a/app/helpers/iiif_print/iiif_helper_decorator.rb +++ b/app/helpers/iiif_print/iiif_helper_decorator.rb @@ -30,3 +30,4 @@ def uv_search_param end end end +Hyrax::IiifHelper.prepend(IiifPrint::IiifHelperDecorator) diff --git a/app/indexers/concerns/iiif_print/child_work_indexer.rb b/app/indexers/concerns/iiif_print/child_work_indexer.rb deleted file mode 100644 index abdd3017..00000000 --- a/app/indexers/concerns/iiif_print/child_work_indexer.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module IiifPrint - module ChildWorkIndexer - 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 diff --git a/app/indexers/concerns/iiif_print/child_work_indexer_decorator.rb b/app/indexers/concerns/iiif_print/child_work_indexer_decorator.rb new file mode 100644 index 00000000..bb9404b8 --- /dev/null +++ b/app/indexers/concerns/iiif_print/child_work_indexer_decorator.rb @@ -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 diff --git a/app/indexers/concerns/iiif_print/file_set_indexer.rb b/app/indexers/concerns/iiif_print/file_set_indexer_decorator.rb similarity index 63% rename from app/indexers/concerns/iiif_print/file_set_indexer.rb rename to app/indexers/concerns/iiif_print/file_set_indexer_decorator.rb index b42e8900..e815f4a9 100644 --- a/app/indexers/concerns/iiif_print/file_set_indexer.rb +++ b/app/indexers/concerns/iiif_print/file_set_indexer_decorator.rb @@ -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 diff --git a/app/models/iiif_print/iiif_search_decorator.rb b/app/models/iiif_print/iiif_search_decorator.rb index 4c007eb0..3e2370fc 100644 --- a/app/models/iiif_print/iiif_search_decorator.rb +++ b/app/models/iiif_print/iiif_search_decorator.rb @@ -33,3 +33,4 @@ def solr_params end end end +::BlacklightIiifSearch::IiifSearch.prepend(IiifPrint::IiifSearchDecorator) diff --git a/app/models/iiif_print/iiif_search_response_decorator.rb b/app/models/iiif_print/iiif_search_response_decorator.rb index e8b399aa..e852b37f 100644 --- a/app/models/iiif_print/iiif_search_response_decorator.rb +++ b/app/models/iiif_print/iiif_search_response_decorator.rb @@ -38,3 +38,4 @@ def add_metadata_match(json_results) end end end +::BlacklightIiifSearch::IiifSearchResponse.prepend(IiifPrint::IiifSearchResponseDecorator) diff --git a/app/presenters/iiif_print/file_set_presenter_decorator.rb b/app/presenters/iiif_print/file_set_presenter_decorator.rb index b7b40dbd..55ca6435 100644 --- a/app/presenters/iiif_print/file_set_presenter_decorator.rb +++ b/app/presenters/iiif_print/file_set_presenter_decorator.rb @@ -9,3 +9,4 @@ def show_split_button? end end end +Hyrax::FileSetPresenter.prepend(IiifPrint::FileSetPresenterDecorator) diff --git a/app/presenters/iiif_print/iiif_manifest_presenter_behavior.rb b/app/presenters/iiif_print/iiif_manifest_presenter_decorator.rb similarity index 97% rename from app/presenters/iiif_print/iiif_manifest_presenter_behavior.rb rename to app/presenters/iiif_print/iiif_manifest_presenter_decorator.rb index cec1477c..d8eb73ee 100644 --- a/app/presenters/iiif_print/iiif_manifest_presenter_behavior.rb +++ b/app/presenters/iiif_print/iiif_manifest_presenter_decorator.rb @@ -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) diff --git a/app/presenters/iiif_print/iiif_manifest_presenter_factory_behavior.rb b/app/presenters/iiif_print/iiif_manifest_presenter_factory_decorator.rb similarity index 89% rename from app/presenters/iiif_print/iiif_manifest_presenter_factory_behavior.rb rename to app/presenters/iiif_print/iiif_manifest_presenter_factory_decorator.rb index f1ee5385..1dcbee48 100644 --- a/app/presenters/iiif_print/iiif_manifest_presenter_factory_behavior.rb +++ b/app/presenters/iiif_print/iiif_manifest_presenter_factory_decorator.rb @@ -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) diff --git a/app/renderers/hyrax/renderers/faceted_attribute_renderer_decorator.rb b/app/renderers/hyrax/renderers/faceted_attribute_renderer_decorator.rb index 29da4229..2b5d7688 100644 --- a/app/renderers/hyrax/renderers/faceted_attribute_renderer_decorator.rb +++ b/app/renderers/hyrax/renderers/faceted_attribute_renderer_decorator.rb @@ -16,3 +16,4 @@ def search_path(value) end end end +Hyrax::Renderers::FacetedAttributeRenderer.prepend(Hyrax::Renderers::FacetedAttributeRendererDecorator) diff --git a/app/services/iiif_print/manifest_builder_service_behavior.rb b/app/services/iiif_print/manifest_builder_service_decorator.rb similarity index 97% rename from app/services/iiif_print/manifest_builder_service_behavior.rb rename to app/services/iiif_print/manifest_builder_service_decorator.rb index f8ba9edb..4a01a915 100644 --- a/app/services/iiif_print/manifest_builder_service_behavior.rb +++ b/app/services/iiif_print/manifest_builder_service_decorator.rb @@ -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) diff --git a/app/services/iiif_print/simple_schema_loader_decorator.rb b/app/services/iiif_print/simple_schema_loader_decorator.rb index 13f14b11..4cd255de 100644 --- a/app/services/iiif_print/simple_schema_loader_decorator.rb +++ b/app/services/iiif_print/simple_schema_loader_decorator.rb @@ -9,3 +9,4 @@ def config_search_paths end end end +Hyrax::SimpleSchemaLoader.prepend(IiifPrint::SimpleSchemaLoaderDecorator) diff --git a/app/transactions/hyrax/transactions/steps/delete_all_file_sets_decorator.rb b/app/transactions/hyrax/transactions/steps/delete_all_file_sets_decorator.rb index 148d77d7..d4edcbca 100644 --- a/app/transactions/hyrax/transactions/steps/delete_all_file_sets_decorator.rb +++ b/app/transactions/hyrax/transactions/steps/delete_all_file_sets_decorator.rb @@ -33,3 +33,5 @@ def call(resource, user: nil) end end end + +"Hyrax::Transactions::Steps::DeleteAllFileSets".safe_constantize&.prepend(Hyrax::Transactions::Steps::DeleteAllFileSetsDecorator) diff --git a/config/initializers/simple_schema_loader.rb b/config/initializers/simple_schema_loader.rb deleted file mode 100644 index a5c9fc56..00000000 --- a/config/initializers/simple_schema_loader.rb +++ /dev/null @@ -1 +0,0 @@ -"Hyrax::SimpleSchemaLoader".safe_constantize&.prepend(IiifPrint::SimpleSchemaLoaderDecorator) diff --git a/lib/iiif_print/blacklight_iiif_search/annotation_decorator.rb b/lib/iiif_print/blacklight_iiif_search/annotation_decorator.rb index 1801786b..7ba382ca 100644 --- a/lib/iiif_print/blacklight_iiif_search/annotation_decorator.rb +++ b/lib/iiif_print/blacklight_iiif_search/annotation_decorator.rb @@ -134,3 +134,4 @@ def text_resource_for_annotation end end end +::BlacklightIiifSearch::IiifSearchAnnotation.prepend(IiifPrint::BlacklightIiifSearch::AnnotationDecorator) diff --git a/lib/iiif_print/engine.rb b/lib/iiif_print/engine.rb index 40b108a8..0cb7e679 100644 --- a/lib/iiif_print/engine.rb +++ b/lib/iiif_print/engine.rb @@ -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 diff --git a/lib/iiif_print/works_controller_behavior.rb b/lib/iiif_print/works_controller_behavior.rb deleted file mode 100644 index ec43b6ee..00000000 --- a/lib/iiif_print/works_controller_behavior.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 diff --git a/lib/iiif_print/works_controller_behavior_decorator.rb b/lib/iiif_print/works_controller_behavior_decorator.rb new file mode 100644 index 00000000..96a8ea2d --- /dev/null +++ b/lib/iiif_print/works_controller_behavior_decorator.rb @@ -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) diff --git a/spec/presenters/iiif_print/iiif_manifest_presenter_behavior_spec.rb b/spec/presenters/iiif_print/iiif_manifest_presenter_decorator_spec.rb similarity index 97% rename from spec/presenters/iiif_print/iiif_manifest_presenter_behavior_spec.rb rename to spec/presenters/iiif_print/iiif_manifest_presenter_decorator_spec.rb index 641968c0..2541d582 100644 --- a/spec/presenters/iiif_print/iiif_manifest_presenter_behavior_spec.rb +++ b/spec/presenters/iiif_print/iiif_manifest_presenter_decorator_spec.rb @@ -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'], diff --git a/spec/presenters/iiif_print/iiif_manifest_presenter_factory_behavior_spec.rb b/spec/presenters/iiif_print/iiif_manifest_presenter_factory_decorator_spec.rb similarity index 96% rename from spec/presenters/iiif_print/iiif_manifest_presenter_factory_behavior_spec.rb rename to spec/presenters/iiif_print/iiif_manifest_presenter_factory_decorator_spec.rb index 2c6788b6..1f78c23d 100644 --- a/spec/presenters/iiif_print/iiif_manifest_presenter_factory_behavior_spec.rb +++ b/spec/presenters/iiif_print/iiif_manifest_presenter_factory_decorator_spec.rb @@ -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]) diff --git a/spec/services/iiif_print/manifest_builder_service_behavior_spec.rb b/spec/services/iiif_print/manifest_builder_service_decorator_spec.rb similarity index 92% rename from spec/services/iiif_print/manifest_builder_service_behavior_spec.rb rename to spec/services/iiif_print/manifest_builder_service_decorator_spec.rb index d358dffc..8046c406 100644 --- a/spec/services/iiif_print/manifest_builder_service_behavior_spec.rb +++ b/spec/services/iiif_print/manifest_builder_service_decorator_spec.rb @@ -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