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

♻️ Favor using Model Registry over hard-coding #6714

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
)
Expand Down
2 changes: 0 additions & 2 deletions app/models/hyrax/model_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/models/hyrax/statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion app/presenters/hyrax/iiif_manifest_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
6 changes: 5 additions & 1 deletion app/presenters/hyrax/member_presenter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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\"")
Expand All @@ -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
4 changes: 1 addition & 3 deletions app/search_builders/hyrax/filter_by_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/services/hyrax/admin_set_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down