From 249904e4ff2109395f3b65afbae18ef44a886747 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Wed, 21 Feb 2024 10:04:49 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Favor=20using=20Model=20Re?= =?UTF-8?q?gistry=20over=20hard-coding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hyrax/admin/analytics/work_reports_controller.rb | 7 ++++--- app/models/hyrax/model_registry.rb | 2 -- app/models/hyrax/statistic.rb | 2 +- app/presenters/hyrax/iiif_manifest_presenter.rb | 3 ++- app/presenters/hyrax/member_presenter_factory.rb | 6 +++++- app/search_builders/hyrax/filter_by_type.rb | 4 +--- app/services/hyrax/admin_set_service.rb | 3 ++- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/hyrax/admin/analytics/work_reports_controller.rb b/app/controllers/hyrax/admin/analytics/work_reports_controller.rb index 977e80a60c..350f9cac78 100644 --- a/app/controllers/hyrax/admin/analytics/work_reports_controller.rb +++ b/app/controllers/hyrax/admin/analytics/work_reports_controller.rb @@ -39,7 +39,7 @@ def show private def accessible_works - models = Hyrax.config.curation_concerns.map { |m| "\"#{m}\"" } + models = Hyrax::ModelRegistry.work_rdf_representations.map { |m| "\"#{m}\"" } if current_user.ability.admin? Hyrax::SolrService.query("has_model_ssim:(#{models.join(' OR ')})", fl: 'title_tesim, id, member_of_collections', @@ -54,15 +54,16 @@ def accessible_works end def accessible_file_sets + file_set_model_clause = "has_model_ssim:\"#{Hyrax::ModelRegistry.rdf_representations_from.join('" OR "')}\"" if current_user.ability.admin? Hyrax::SolrService.query( - "has_model_ssim:FileSet", + file_set_model_clause, fl: 'title_tesim, id', rows: 50_000 ) else Hyrax::SolrService.query( - "edit_access_person_ssim:#{current_user} AND has_model_ssim:FileSet", + "edit_access_person_ssim:#{current_user} AND #{file_set_model_clause}", fl: 'title_tesim, id', rows: 50_000 ) diff --git a/app/models/hyrax/model_registry.rb b/app/models/hyrax/model_registry.rb index 37c8a8b07b..ac90e19b60 100644 --- a/app/models/hyrax/model_registry.rb +++ b/app/models/hyrax/model_registry.rb @@ -101,11 +101,9 @@ def self.work_rdf_representations def self.classes_from(strings) strings.map(&:safe_constantize).flatten.uniq end - private_class_method :classes_from def self.rdf_representations_from(klasses) klasses.map { |klass| klass.respond_to?(:to_rdf_represntation) ? klass.to_rdf_represntation : klass.name }.uniq end - private_class_method :rdf_representations_from end end diff --git a/app/models/hyrax/statistic.rb b/app/models/hyrax/statistic.rb index 488e407b62..c6f0b8920c 100644 --- a/app/models/hyrax/statistic.rb +++ b/app/models/hyrax/statistic.rb @@ -42,7 +42,7 @@ def ga_statistics(start_date, object) end def query_works(query) - models = Hyrax.config.curation_concerns.map { |m| "\"#{m}\"" } + models = Hyrax::ModelRegistry.work_rdf_representations.map { |m| "\"#{m}\"" } Hyrax::SolrService.query("has_model_ssim:(#{models.join(' OR ')})", fl: query, rows: 100_000) end diff --git a/app/presenters/hyrax/iiif_manifest_presenter.rb b/app/presenters/hyrax/iiif_manifest_presenter.rb index 0330371aa3..f12740d977 100644 --- a/app/presenters/hyrax/iiif_manifest_presenter.rb +++ b/app/presenters/hyrax/iiif_manifest_presenter.rb @@ -56,7 +56,8 @@ def hostname ## # @return [Boolean] def file_set? - model.try(:file_set?) || Array(model[:has_model_ssim]).include?('FileSet') || Array(model[:has_model_ssim]).include?('Hyrax::FileSet') + return true if model.try(:file_set?) + (Array(model[:has_model_ssim]) & Hyrax::ModelRegistry.file_set_rdf_representations).any? end ## diff --git a/app/presenters/hyrax/member_presenter_factory.rb b/app/presenters/hyrax/member_presenter_factory.rb index 877c76c56e..94d90fe564 100644 --- a/app/presenters/hyrax/member_presenter_factory.rb +++ b/app/presenters/hyrax/member_presenter_factory.rb @@ -47,7 +47,7 @@ def ordered_ids # in order. # Arbitrarily maxed at 10 thousand; had to specify rows due to solr's default of 10 def file_set_ids - @file_set_ids ||= Hyrax::SolrService.query("{!field f=has_model_ssim}FileSet", + @file_set_ids ||= Hyrax::SolrService.query("{!field f=has_model_ssim}#{file_set_models.join(',')}", rows: 10_000, fl: Hyrax.config.id_field, fq: "{!join from=ordered_targets_ssim to=id}id:\"#{id}/list_source\"") @@ -61,5 +61,9 @@ def presenter_factory_arguments def composite_presenter_class CompositePresenterFactory.new(file_presenter_class, work_presenter_class, ordered_ids & file_set_ids) end + + def file_set_models + Hyrax::ModelRegistry.file_set_rdf_representations + end end end diff --git a/app/search_builders/hyrax/filter_by_type.rb b/app/search_builders/hyrax/filter_by_type.rb index 8905248edb..92a0ca65fa 100644 --- a/app/search_builders/hyrax/filter_by_type.rb +++ b/app/search_builders/hyrax/filter_by_type.rb @@ -30,9 +30,7 @@ def models end def models_to_solr_clause - models.map do |model| - model.respond_to?(:to_rdf_representation) ? model.to_rdf_representation : model.name - end.join(',') + Hyrax::ModelRegistry.rdf_representations_from(models).join(',') end def generic_type_field diff --git a/app/services/hyrax/admin_set_service.rb b/app/services/hyrax/admin_set_service.rb index a5c177a4a1..bdaa9cac97 100644 --- a/app/services/hyrax/admin_set_service.rb +++ b/app/services/hyrax/admin_set_service.rb @@ -51,9 +51,10 @@ def builder(access) # @return [Hash] admin set id keys and file count values def count_files(admin_sets) file_counts = Hash.new(0) + file_set_models = Hyrax::ModelRegistry.file_set_rdf_representations admin_sets.each do |admin_set| query = "{!join from=member_ids_ssim to=id}isPartOf_ssim:#{admin_set.id}" - file_results = Hyrax::SolrService.get(fq: [query, "{!terms f=has_model_ssim}FileSet,Hyrax::FileSet"], rows: 0) + file_results = Hyrax::SolrService.get(fq: [query, "{!terms f=has_model_ssim}#{file_set_models.join(',')}"], rows: 0) file_counts[admin_set.id] = file_results['response']['numFound'] end file_counts