Skip to content

Commit

Permalink
Merge pull request #337 from scientist-softserv/cast-ids-to-strings
Browse files Browse the repository at this point in the history
🐛 Cast ID to String to Account for Valkyrie::ID
  • Loading branch information
jeremyf committed Feb 19, 2024
2 parents fc5438f + 185753e commit b39296d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
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

0 comments on commit b39296d

Please sign in to comment.