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

🐛 Cast ID to String to Account for Valkyrie::ID #337

Merged
merged 1 commit into from
Feb 19, 2024
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
9 changes: 6 additions & 3 deletions lib/iiif_print/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ def handle_after_create_fileset(file_set, user)
end

attr_writer :ancestory_identifier_function
# The function, with arity 1, that receives a work and returns it's identifier for the purposes
# of object ancestry.
# The function, with arity 1, that receives a work and returns it's identifier (as a string) for
# the purposes of object ancestry.
#
# @return [Proc]
def ancestory_identifier_function
@ancestory_identifier_function ||= ->(work) { work.id }
# If the work.id is nil, keep it nil. Otherwise cast that id to a string; to deal with the
# `Valkyrie::ID`.
@ancestory_identifier_function ||= ->(work) { work.id&.to_s }
end

attr_writer :excluded_model_name_solr_field_values
Expand Down
12 changes: 10 additions & 2 deletions lib/iiif_print/lineage_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module LineageService
#
# @param object [#in_works] An object that responds to #in_works
# @return [Array<String>]
#
# @note For those implementing their own lineage service, verify that you are not returning
# an array of
def self.ancestor_ids_for(object)
ancestor_ids ||= []
# Yes, we're fetching the works, then compressing those into identifiers. Because in the case
Expand All @@ -24,7 +27,10 @@ def self.ancestor_ids_for(object)
ancestor_ids << ancestry_identifier_for(work)
ancestor_ids += ancestor_ids_for(work) if work.respond_to?(:is_child) && work.is_child
end
ancestor_ids.flatten.compact.uniq
# We must convert these to strings as Valkyrie's identifiers will be cast to hashes when we
# attempt to write the SolrDocument. Also, per documentation we return an Array of strings, not
# an Array that might include Valkyrie::ID objects.
ancestor_ids.flatten.compact.uniq.map(&:to_s)
end

##
Expand Down Expand Up @@ -56,7 +62,9 @@ def self.descendent_member_ids_for(object)
IiifPrint.object_ordered_works(object)&.each do |child|
file_set_ids += descendent_member_ids_for(child)
end
file_set_ids.flatten.uniq.compact
# We must convert these to strings as Valkyrie's identifiers will be cast to hashes when we
# attempt to write the SolrDocument.
file_set_ids.flatten.uniq.compact.map(&:to_s)
end
class << self
alias descendent_file_set_ids_for descendent_member_ids_for
Expand Down
Loading