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

Allinson flex support #175

Merged
merged 8 commits into from
Mar 10, 2023
Merged
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 @@ -91,7 +91,7 @@ def get_solr_docs(presenter)
parent_id_and_child_ids = child_ids << parent_id
query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids(parent_id_and_child_ids)
solr_hits = ActiveFedora::SolrService.query(query, fq: "-has_model_ssim:FileSet", rows: 100_000)
solr_hits.map { |solr_hit| ::SolrDocument.new(solr_hit) }
solr_hits.flat_map { |solr_hit| ActiveFedora::SolrService.query("id:#{solr_hit.id}", rows: 100_000) }
end
end
end
39 changes: 37 additions & 2 deletions lib/iiif_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def iiif_print_config?
# @see Hyrax::IiifManifestPresenter#manifest_metadata
def self.manifest_metadata_for(work:,
version: config.default_iiif_manifest_version,
fields: default_fields_for(work),
fields: defined?(AllinsonFlex) ? allinson_flex_fields_for(work) : default_fields_for(work),
current_ability:,
base_url:)
Metadata.build_metadata_for(work: work,
Expand All @@ -128,9 +128,44 @@ def self.default_fields_for(_work, fields: config.metadata_fields)
fields.map do |field|
Field.new(
name: field.first,
label: Hyrax::Renderers::AttributeRenderer.new(field, nil).label,
label: Hyrax::Renderers::AttributeRenderer.new(field.first, nil).label,
options: field.last
)
end
end

def self.allinson_flex_fields_for(_work, fields: allinson_flex_fields)
fields.map do |field|
# currently only supports the faceted option
# Why the `render_as:`? This was originally derived from Hyku default attributes
# @see https://github.com/samvera/hyku/blob/c702844de4c003eaa88eb5a7514c7a1eae1b289e/app/views/hyrax/base/_attribute_rows.html.erb#L3
options = field.indexing.include?('facetable') ? { render_as: :faceted } : nil
Field.new(
name: field.name,
label: field.value,
options: options
)
end
end

# sql query method was refactored to active record
# original query:
# AllinsonFlex::ProfileProperty
# .find_by_sql(
# "SELECT DISTINCT allinson_flex_profile_texts.value AS label, " \
# "allinson_flex_profile_properties.name AS name " \
# "FROM allinson_flex_profile_properties " \
# "JOIN allinson_flex_profile_texts " \
# "ON allinson_flex_profile_properties.id = " \
# "allinson_flex_profile_texts.profile_property_id " \
# "WHERE allinson_flex_profile_texts.name = 'display_label'"
# )
# In this ActiveRecord query, allinson_flex_profile_properties.indexing was added
def self.allinson_flex_fields
@allinson_flex_fields ||= AllinsonFlex::ProfileProperty
.joins(:texts)
.where(allinson_flex_profile_texts: { name: 'display_label' })
.distinct
.select(:name, :value, :indexing)
end
end
11 changes: 6 additions & 5 deletions lib/iiif_print/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ def build_metadata

def build_metadata_for_v2
fields.map do |field|
label = Hyrax::Renderers::AttributeRenderer.new(field.name, nil).label
if field.name == :collection && member_of_collection?
viewable_collections = Hyrax::CollectionMemberService.run(work, @current_ability)
next if viewable_collections.empty?
{ 'label' => label,
{ 'label' => field.label,
'value' => make_collection_link(viewable_collections) }
else
next if field_is_empty?(field)
{ 'label' => label,
{ 'label' => field.label,
'value' => cast_to_value(field_name: field.name, options: field.options) }
end
end.compact
Expand All @@ -58,7 +57,8 @@ def build_metadata_for_v3
end

def field_is_empty?(field)
Array(work.try(field.name)).empty?
# TODO: we are assuming tesim, might want to account for other suffixes in the future
Array(work.try(field.name) || work["#{field.name}_tesim"]).empty?
laritakr marked this conversation as resolved.
Show resolved Hide resolved
end

def member_of_collection?
Expand All @@ -85,7 +85,8 @@ def cast_to_value(field_name:, options:)
end

def values_for(field_name:)
Array(work.send(field_name))
# TODO: we are assuming tesim, might want to account for other suffixes in the future
Array(work.try(field_name) || work["#{field_name}_tesim"])
laritakr marked this conversation as resolved.
Show resolved Hide resolved
end

def make_collection_link(collection_documents)
Expand Down
12 changes: 1 addition & 11 deletions spec/iiif_print/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
RSpec.describe IiifPrint::Metadata do
let(:base_url) { "https://my.dev.test" }
let(:solr_document) { SolrDocument.new(attributes) }
let(:fields) do
metadata_fields.map do |field|
SampleField.new(
name: field.first,
label: Hyrax::Renderers::AttributeRenderer.new(field, nil).label,
options: field.last
)
end
end
let(:fields) { IiifPrint.default_fields_for(fields: metadata_fields) }
let(:metadata_fields) do
{
title: {},
Expand All @@ -20,8 +12,6 @@
}
end

SampleField = Struct.new(:name, :label, :options, keyword_init: true)

describe ".build_metadata_for" do
subject(:manifest_metadata) do
described_class.build_metadata_for(
Expand Down