Skip to content

Commit

Permalink
♻️ Adjust rescue logic to move closer to error
Browse files Browse the repository at this point in the history
This also adds some consideration for refactoring the queries to instead
use the persistence layer.
  • Loading branch information
jeremyf committed Feb 2, 2024
1 parent 30021c9 commit 60aff98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/factories/bulkrax/object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,18 @@ def update
def find
found = find_by_id if attributes[:id].present?
return found if found.present?
rescue Valkyrie::Persistence::ObjectNotFoundError
return search_by_identifier if attributes[work_identifier].present?
false
else
search_by_identifier if attributes[work_identifier].present?
end

def find_by_id
# TODO: Push logic into Bulkrax.persistence_adapter; maybe
# Rails / Ruby upgrade, we moved from :exists? to :exist? However we want to continue (for a
# bit) to support older versions.
method_name = klass.respond_to?(:exist?) ? :exist? : :exists?
klass.find(attributes[:id]) if klass.send(method_name, attributes[:id])
rescue Valkyrie::Persistence::ObjectNotFoundError
false
end

def find_or_create
Expand All @@ -110,11 +111,13 @@ def find_or_create
end

def search_by_identifier
# TODO: Push logic into Bulkrax.persistence_adapter; maybe
query = { work_identifier_search_field =>
source_identifier_value }
# Query can return partial matches (something6 matches both something6 and something68)
# so we need to weed out any that are not the correct full match. But other items might be
# in the multivalued field, so we have to go through them one at a time.
#
match = klass.where(query).detect { |m| m.send(work_identifier).include?(source_identifier_value) }
return match if match
end
Expand Down
1 change: 1 addition & 0 deletions app/jobs/bulkrax/create_relationships_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def perform(parent_identifier:, importer_run_id:) # rubocop:disable Metrics/AbcS
# save record if members were added
if @parent_record_members_added
parent_record.save!
# TODO: Push logic into Bulkrax.persistence_adapter
# Ensure that the new relationship gets indexed onto the children
if parent_record.is_a?(Valkyrie::Resource)
@child_members_added.each do |child|
Expand Down

0 comments on commit 60aff98

Please sign in to comment.