From 6e1b7a97823433dff0fdb5d2a3c5c1b5ee01cd79 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 5 Apr 2022 18:54:56 -0500 Subject: [PATCH 01/12] get the entry from the current importer --- app/jobs/bulkrax/create_relationships_job.rb | 4 ++-- app/models/concerns/bulkrax/dynamic_record_lookup.rb | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/jobs/bulkrax/create_relationships_job.rb b/app/jobs/bulkrax/create_relationships_job.rb index b5b3b361..971fe9fa 100644 --- a/app/jobs/bulkrax/create_relationships_job.rb +++ b/app/jobs/bulkrax/create_relationships_job.rb @@ -37,11 +37,11 @@ def perform(parent_identifier:, importer_run_id:) end.sort_by(&:order) @importer_run_id = importer_run_id - @parent_record = find_record(parent_identifier) + @parent_record = find_record(parent_identifier, importer_run_id) @child_records = { works: [], collections: [] } pending_relationships.each do |rel| raise ::StandardError, %("#{rel}" needs either a child or a parent to create a relationship) if rel.child_id.nil? || rel.parent_id.nil? - child_record = find_record(rel.child_id) + child_record = find_record(rel.child_id, importer_run_id) child_record.is_a?(::Collection) ? @child_records[:collections] << child_record : @child_records[:works] << child_record end diff --git a/app/models/concerns/bulkrax/dynamic_record_lookup.rb b/app/models/concerns/bulkrax/dynamic_record_lookup.rb index 0332414c..ebb6932f 100644 --- a/app/models/concerns/bulkrax/dynamic_record_lookup.rb +++ b/app/models/concerns/bulkrax/dynamic_record_lookup.rb @@ -7,8 +7,11 @@ module DynamicRecordLookup # # @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier # @return [Work, Collection, nil] Work or Collection if found, otherwise nil - def find_record(identifier) - record = Entry.find_by(identifier: identifier) + def find_record(identifier, importer_run_id) + # account for the possibility that the same record may have successfully or unsuccessfully + # been imported in a different importer + importer_id = ImporterRun.find(importer_run_id).importer_id + record = Entry.find_by(identifier: identifier, importerexporter_id: importer_id) record ||= ::Collection.where(id: identifier).first # rubocop:disable Rails/FindBy if record.blank? available_work_types.each do |work_type| From 811c62d8e6084c8e4c9a73d69dc8fbf10fe5af0c Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Wed, 6 Apr 2022 13:21:11 -0500 Subject: [PATCH 02/12] fix specs related to the create relationships job --- .../bulkrax/create_relationships_job_spec.rb | 4 +-- .../bulkrax/dynamic_record_lookup_spec.rb | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/spec/jobs/bulkrax/create_relationships_job_spec.rb b/spec/jobs/bulkrax/create_relationships_job_spec.rb index 51952ed8..4f47bdfb 100644 --- a/spec/jobs/bulkrax/create_relationships_job_spec.rb +++ b/spec/jobs/bulkrax/create_relationships_job_spec.rb @@ -27,8 +27,8 @@ module Bulkrax before do allow(::Hyrax.config).to receive(:curation_concerns).and_return([Work]) - allow(Entry).to receive(:find_by).with(identifier: child_entry.identifier).and_return(child_entry) - allow(Entry).to receive(:find_by).with(identifier: parent_entry.identifier).and_return(parent_entry) + allow(Entry).to receive(:find_by).with(identifier: child_entry.identifier, importerexporter_id: importer.id).and_return(child_entry) + allow(Entry).to receive(:find_by).with(identifier: parent_entry.identifier, importerexporter_id: importer.id).and_return(parent_entry) allow(parent_entry).to receive(:factory).and_return(parent_factory) allow(child_entry).to receive(:factory).and_return(child_factory) end diff --git a/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb b/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb index ded8998c..a6e5b37c 100644 --- a/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb +++ b/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb @@ -5,6 +5,9 @@ module Bulkrax RSpec.shared_examples 'dynamic record lookup' do let(:importer) { FactoryBot.create(:bulkrax_importer_csv_complex) } + let(:bulkrax_importer_run) { FactoryBot.create(:bulkrax_importer_run, importer: importer) } + let(:importer_id) { importer.id } + let(:importer_run_id) { bulkrax_importer_run.id } before do allow(::Hyrax.config).to receive(:curation_concerns).and_return([Work]) @@ -19,11 +22,11 @@ module Bulkrax let(:source_identifier) { 'bulkrax_identifier_1' } it 'looks through entries, collections, and all work types' do - expect(Entry).to receive(:find_by).with(identifier: source_identifier).once + expect(Entry).to receive(:find_by).with(identifier: source_identifier, importerexporter_id: importer_id).once expect(::Collection).to receive(:where).with(id: source_identifier).once.and_return([]) expect(::Work).to receive(:where).with(id: source_identifier).once.and_return([]) - subject.find_record(source_identifier) + subject.find_record(source_identifier, importer_run_id) end context 'when an entry is found' do @@ -32,19 +35,19 @@ module Bulkrax let(:record) { instance_double(::Work, title: ["Found through Entry's factory"]) } before do - allow(Entry).to receive(:find_by).with(identifier: source_identifier).and_return(entry) + allow(Entry).to receive(:find_by).with(identifier: source_identifier, importerexporter_id: importer_id).and_return(entry) allow(entry).to receive(:factory).and_return(factory) end it "returns the entry's record" do - expect(subject.find_record(source_identifier)).to eq(record) + expect(subject.find_record(source_identifier, importer_run_id)).to eq(record) end it "uses the entry's factory to find its record" do expect(entry).to receive(:factory) expect(factory).to receive(:find) - found_record = subject.find_record(source_identifier) + found_record = subject.find_record(source_identifier, importer_run_id) expect(found_record.title).to eq(record.title) end @@ -52,7 +55,7 @@ module Bulkrax context 'when nothing is found' do it 'returns nil' do - expect(subject.find_record(source_identifier)).to be_nil + expect(subject.find_record(source_identifier, importer_run_id)).to be_nil end end end @@ -61,11 +64,11 @@ module Bulkrax let(:id) { 'xyz6789' } it 'looks through entries, collections, and all work types' do - expect(Entry).to receive(:find_by).with(identifier: id).once + expect(Entry).to receive(:find_by).with(identifier: id, importerexporter_id: importer_id).once expect(::Collection).to receive(:where).with(id: id).once.and_return([]) expect(::Work).to receive(:where).with(id: id).once.and_return([]) - subject.find_record(id) + subject.find_record(id, importer_run_id) end context 'when a collection is found' do @@ -76,7 +79,7 @@ module Bulkrax end it 'returns the collection' do - expect(subject.find_record(id)).to eq(collection) + expect(subject.find_record(id, importer_run_id)).to eq(collection) end end @@ -88,13 +91,13 @@ module Bulkrax end it 'returns the work' do - expect(subject.find_record(id)).to eq(work) + expect(subject.find_record(id, importer_run_id)).to eq(work) end end context 'when nothing is found' do it 'returns nil' do - expect(subject.find_record(id)).to be_nil + expect(subject.find_record(id, importer_run_id)).to be_nil end end end From 5eab0044404d4c40124ac5e9b751108013ded299 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Wed, 6 Apr 2022 13:59:32 -0500 Subject: [PATCH 03/12] update import file set job and spec --- app/jobs/bulkrax/import_file_set_job.rb | 5 ++++- spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/jobs/bulkrax/import_file_set_job.rb b/app/jobs/bulkrax/import_file_set_job.rb index da12d738..5cafaabd 100644 --- a/app/jobs/bulkrax/import_file_set_job.rb +++ b/app/jobs/bulkrax/import_file_set_job.rb @@ -7,7 +7,10 @@ class ImportFileSetJob < ApplicationJob queue_as :import + attr_accessor :importer_run_id + def perform(entry_id, importer_run_id) + @importer_run_id = importer_run_id entry = Entry.find(entry_id) parent_identifier = entry.raw_metadata[entry.related_parents_raw_mapping]&.strip @@ -63,7 +66,7 @@ def check_parent_is_a_work!(parent_identifier) end def find_parent_record(parent_identifier) - @parent_record ||= find_record(parent_identifier) + @parent_record ||= find_record(parent_identifier, importer_run_id) end end end diff --git a/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb b/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb index a6e5b37c..48782699 100644 --- a/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb +++ b/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb @@ -5,9 +5,8 @@ module Bulkrax RSpec.shared_examples 'dynamic record lookup' do let(:importer) { FactoryBot.create(:bulkrax_importer_csv_complex) } - let(:bulkrax_importer_run) { FactoryBot.create(:bulkrax_importer_run, importer: importer) } let(:importer_id) { importer.id } - let(:importer_run_id) { bulkrax_importer_run.id } + let(:importer_run_id) { importer.current_run.id } before do allow(::Hyrax.config).to receive(:curation_concerns).and_return([Work]) From 09fb636360b8f5434f95b0f289ee5f6030b7a063 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Wed, 6 Apr 2022 14:38:51 -0500 Subject: [PATCH 04/12] add a conditional to find_record --- .../concerns/bulkrax/dynamic_record_lookup.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/bulkrax/dynamic_record_lookup.rb b/app/models/concerns/bulkrax/dynamic_record_lookup.rb index ebb6932f..aa70f9ef 100644 --- a/app/models/concerns/bulkrax/dynamic_record_lookup.rb +++ b/app/models/concerns/bulkrax/dynamic_record_lookup.rb @@ -8,10 +8,16 @@ module DynamicRecordLookup # @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier # @return [Work, Collection, nil] Work or Collection if found, otherwise nil def find_record(identifier, importer_run_id) - # account for the possibility that the same record may have successfully or unsuccessfully - # been imported in a different importer - importer_id = ImporterRun.find(importer_run_id).importer_id - record = Entry.find_by(identifier: identifier, importerexporter_id: importer_id) + if importer_run_id + # account for the possibility that the same record may have successfully or unsuccessfully + # been imported in a different importer + importer_id = ImporterRun.find(importer_run_id).importer_id + record = Entry.find_by(identifier: identifier, importerexporter_id: importer_id) + else + # TODO(alishaevn): figure out how to access the importer_run_id in the "create_file_set" method + # so this else can be removed + record = Entry.find_by(identifier: identifier) + end record ||= ::Collection.where(id: identifier).first # rubocop:disable Rails/FindBy if record.blank? available_work_types.each do |work_type| From 1577ee7cd5f0799aa60846ffcb7508cb8b117012 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Wed, 6 Apr 2022 14:46:22 -0500 Subject: [PATCH 05/12] update importer spec again --- spec/jobs/bulkrax/importer_job_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/jobs/bulkrax/importer_job_spec.rb b/spec/jobs/bulkrax/importer_job_spec.rb index b3de81e0..11b3f6de 100644 --- a/spec/jobs/bulkrax/importer_job_spec.rb +++ b/spec/jobs/bulkrax/importer_job_spec.rb @@ -27,7 +27,7 @@ module Bulkrax importer_job.perform(1) expect(importer.current_run.total_work_entries).to eq(10) - expect(importer.current_run.total_collection_entries).to eq(421) + expect(importer.current_run.total_collection_entries).to eq(426) end end From 6ff5f24d336ed2b8e860b2df314076bd230cdc60 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 7 Apr 2022 11:37:42 -0500 Subject: [PATCH 06/12] make importer_run_id an optional param for find_record --- app/models/concerns/bulkrax/dynamic_record_lookup.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/bulkrax/dynamic_record_lookup.rb b/app/models/concerns/bulkrax/dynamic_record_lookup.rb index aa70f9ef..319da03f 100644 --- a/app/models/concerns/bulkrax/dynamic_record_lookup.rb +++ b/app/models/concerns/bulkrax/dynamic_record_lookup.rb @@ -6,8 +6,9 @@ module DynamicRecordLookup # has the provided identifier. # # @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier + # @param importer_run_id [Number] ID of the current_run of this Importer Job # @return [Work, Collection, nil] Work or Collection if found, otherwise nil - def find_record(identifier, importer_run_id) + def find_record(identifier, importer_run_id = nil) if importer_run_id # account for the possibility that the same record may have successfully or unsuccessfully # been imported in a different importer From 32ac4bd9d98ead6baf678315243c6346a0a5d526 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 7 Apr 2022 19:52:59 -0500 Subject: [PATCH 07/12] pass the importer_run_id into the object factory so file sets can find their records --- app/factories/bulkrax/object_factory.rb | 7 ++++--- app/jobs/bulkrax/import_file_set_job.rb | 3 ++- app/models/concerns/bulkrax/import_behavior.rb | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/factories/bulkrax/object_factory.rb b/app/factories/bulkrax/object_factory.rb index cc5a6d79..c18ee888 100644 --- a/app/factories/bulkrax/object_factory.rb +++ b/app/factories/bulkrax/object_factory.rb @@ -7,10 +7,10 @@ class ObjectFactory include DynamicRecordLookup define_model_callbacks :save, :create - attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :related_parents_parsed_mapping + attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :related_parents_parsed_mapping, :importer_run_id # rubocop:disable Metrics/ParameterLists - def initialize(attributes:, source_identifier_value:, work_identifier:, related_parents_parsed_mapping: nil, replace_files: false, user: nil, klass: nil, update_files: false) + def initialize(attributes:, source_identifier_value:, work_identifier:, related_parents_parsed_mapping: nil, replace_files: false, user: nil, klass: nil, importer_run_id: nil, update_files: false) @attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes) @replace_files = replace_files @update_files = update_files @@ -19,6 +19,7 @@ def initialize(attributes:, source_identifier_value:, work_identifier:, related_ @related_parents_parsed_mapping = related_parents_parsed_mapping @source_identifier_value = source_identifier_value @klass = klass || Bulkrax.default_work_type.constantize + @importer_run_id = importer_run_id end # rubocop:enable Metrics/ParameterLists @@ -152,7 +153,7 @@ def update_collection(attrs) # This method is heavily inspired by Hyrax's AttachFilesToWorkJob def create_file_set(attrs) - work = find_record(attributes[related_parents_parsed_mapping].first) + _, work = find_record(attributes[related_parents_parsed_mapping].first, importer_run_id) work_permissions = work.permissions.map(&:to_hash) file_set_attrs = attrs.slice(*object.attributes.keys) object.assign_attributes(file_set_attrs) diff --git a/app/jobs/bulkrax/import_file_set_job.rb b/app/jobs/bulkrax/import_file_set_job.rb index 5cafaabd..0e461838 100644 --- a/app/jobs/bulkrax/import_file_set_job.rb +++ b/app/jobs/bulkrax/import_file_set_job.rb @@ -7,7 +7,7 @@ class ImportFileSetJob < ApplicationJob queue_as :import - attr_accessor :importer_run_id + attr_reader :importer_run_id def perform(entry_id, importer_run_id) @importer_run_id = importer_run_id @@ -67,6 +67,7 @@ def check_parent_is_a_work!(parent_identifier) def find_parent_record(parent_identifier) @parent_record ||= find_record(parent_identifier, importer_run_id) + @parent_record = parent_record.last if parent_record.is_a? Array end end end diff --git a/app/models/concerns/bulkrax/import_behavior.rb b/app/models/concerns/bulkrax/import_behavior.rb index 141d051c..47d6080e 100644 --- a/app/models/concerns/bulkrax/import_behavior.rb +++ b/app/models/concerns/bulkrax/import_behavior.rb @@ -98,6 +98,7 @@ def factory replace_files: replace_files, user: user, klass: factory_class, + importer_run_id: importerexporter.last_run.id, update_files: update_files) end From db91c4815a2904c28036b53fd9dab6052cc625b0 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 7 Apr 2022 19:53:49 -0500 Subject: [PATCH 08/12] return the entry from find_record too --- app/jobs/bulkrax/create_relationships_job.rb | 15 ++++++++----- .../concerns/bulkrax/dynamic_record_lookup.rb | 22 +++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/jobs/bulkrax/create_relationships_job.rb b/app/jobs/bulkrax/create_relationships_job.rb index 971fe9fa..24bc73b7 100644 --- a/app/jobs/bulkrax/create_relationships_job.rb +++ b/app/jobs/bulkrax/create_relationships_job.rb @@ -37,11 +37,11 @@ def perform(parent_identifier:, importer_run_id:) end.sort_by(&:order) @importer_run_id = importer_run_id - @parent_record = find_record(parent_identifier, importer_run_id) + @parent_entry, @parent_record = find_record(parent_identifier, importer_run_id) @child_records = { works: [], collections: [] } pending_relationships.each do |rel| raise ::StandardError, %("#{rel}" needs either a child or a parent to create a relationship) if rel.child_id.nil? || rel.parent_id.nil? - child_record = find_record(rel.child_id, importer_run_id) + _, child_record = find_record(rel.child_id, importer_run_id) child_record.is_a?(::Collection) ? @child_records[:collections] << child_record : @child_records[:works] << child_record end @@ -53,7 +53,7 @@ def perform(parent_identifier:, importer_run_id:) return false # stop current job from continuing to run after rescheduling end - @parent_entry = Bulkrax::Entry.where(identifier: parent_identifier, + @parent_entry ||= Bulkrax::Entry.where(identifier: parent_identifier, importerexporter_id: ImporterRun.find(importer_run_id).importer_id, importerexporter_type: "Bulkrax::Importer").first create_relationships @@ -91,7 +91,8 @@ def collection_parent_work_child related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping, replace_files: false, user: user, - klass: child_record.class + klass: child_record.class, + importer_run_id: importer_run_id ).run # TODO: add counters for :processed_parents and :failed_parents Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations @@ -109,7 +110,8 @@ def collection_parent_collection_child related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping, replace_files: false, user: user, - klass: parent_record.class + klass: parent_record.class, + importer_run_id: importer_run_id ).run # TODO: add counters for :processed_parents and :failed_parents Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations @@ -132,7 +134,8 @@ def work_parent_work_child related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping, replace_files: false, user: user, - klass: parent_record.class + klass: parent_record.class, + importer_run_id: importer_run_id ).run # TODO: add counters for :processed_parents and :failed_parents Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations diff --git a/app/models/concerns/bulkrax/dynamic_record_lookup.rb b/app/models/concerns/bulkrax/dynamic_record_lookup.rb index 319da03f..dc84c8b8 100644 --- a/app/models/concerns/bulkrax/dynamic_record_lookup.rb +++ b/app/models/concerns/bulkrax/dynamic_record_lookup.rb @@ -7,18 +7,14 @@ module DynamicRecordLookup # # @param identifier [String] Work/Collection ID or Bulkrax::Entry source_identifier # @param importer_run_id [Number] ID of the current_run of this Importer Job - # @return [Work, Collection, nil] Work or Collection if found, otherwise nil + # @return [Entry, nil], [Work, Collection, nil] Entry if found, otherwise nil and a Work or Collection if found, otherwise nil def find_record(identifier, importer_run_id = nil) - if importer_run_id - # account for the possibility that the same record may have successfully or unsuccessfully - # been imported in a different importer - importer_id = ImporterRun.find(importer_run_id).importer_id - record = Entry.find_by(identifier: identifier, importerexporter_id: importer_id) - else - # TODO(alishaevn): figure out how to access the importer_run_id in the "create_file_set" method - # so this else can be removed - record = Entry.find_by(identifier: identifier) - end + # check for our entry in our current importer first + importer_id = ImporterRun.find(importer_run_id).importer_id + record = Entry.find_by(identifier: identifier, importerexporter_id: importer_id) || Entry.find_by(identifier: identifier) + + # TODO(alishaevn): discuss whether we are only looking for Collection models here + # use ActiveFedora::Base.find(identifier) instead? record ||= ::Collection.where(id: identifier).first # rubocop:disable Rails/FindBy if record.blank? available_work_types.each do |work_type| @@ -26,7 +22,9 @@ def find_record(identifier, importer_run_id = nil) end end - record.is_a?(Entry) ? record.factory.find : record + # return the found entry here instead of searching for it again in the CreateRelationshipsJob + # also accounts for when the found entry isn't a part of this importer + record.is_a?(Entry) ? [ record, record.factory.find ] : [ nil, record ] end # Check if the record is a Work From 1cdc1ac043df91ef6c7d2cc3f887e8ae065c482e Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 7 Apr 2022 19:54:18 -0500 Subject: [PATCH 09/12] file sets do not have children --- app/models/concerns/bulkrax/file_factory.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/bulkrax/file_factory.rb b/app/models/concerns/bulkrax/file_factory.rb index 3c6311a8..1cf783b6 100644 --- a/app/models/concerns/bulkrax/file_factory.rb +++ b/app/models/concerns/bulkrax/file_factory.rb @@ -45,6 +45,8 @@ def parsed_remote_files end def new_remote_files + return if object.is_a? FileSet + @new_remote_files ||= if object.present? && object.file_sets.present? parsed_remote_files.select do |file| # is the url valid? @@ -101,7 +103,12 @@ def set_removed_filesets end def local_file_sets - @local_file_sets ||= object&.ordered_file_sets + @local_file_sets ||= ordered_file_sets + end + + def ordered_file_sets + # OVERRIDE Hyrda-works 1.2.0 - this method was deprecated in v1.0 + object&.ordered_members.to_a.select(&:file_set?) end def import_files From 4c1732d779c747372cb4bc2510c1a7a65603ad2f Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 7 Apr 2022 20:01:48 -0500 Subject: [PATCH 10/12] rubocop fixes --- app/jobs/bulkrax/create_relationships_job.rb | 4 ++-- app/models/concerns/bulkrax/dynamic_record_lookup.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/bulkrax/create_relationships_job.rb b/app/jobs/bulkrax/create_relationships_job.rb index 24bc73b7..838b4ae5 100644 --- a/app/jobs/bulkrax/create_relationships_job.rb +++ b/app/jobs/bulkrax/create_relationships_job.rb @@ -54,8 +54,8 @@ def perform(parent_identifier:, importer_run_id:) end @parent_entry ||= Bulkrax::Entry.where(identifier: parent_identifier, - importerexporter_id: ImporterRun.find(importer_run_id).importer_id, - importerexporter_type: "Bulkrax::Importer").first + importerexporter_id: ImporterRun.find(importer_run_id).importer_id, + importerexporter_type: "Bulkrax::Importer").first create_relationships pending_relationships.each(&:destroy) rescue ::StandardError => e diff --git a/app/models/concerns/bulkrax/dynamic_record_lookup.rb b/app/models/concerns/bulkrax/dynamic_record_lookup.rb index dc84c8b8..14d04baa 100644 --- a/app/models/concerns/bulkrax/dynamic_record_lookup.rb +++ b/app/models/concerns/bulkrax/dynamic_record_lookup.rb @@ -24,7 +24,7 @@ def find_record(identifier, importer_run_id = nil) # return the found entry here instead of searching for it again in the CreateRelationshipsJob # also accounts for when the found entry isn't a part of this importer - record.is_a?(Entry) ? [ record, record.factory.find ] : [ nil, record ] + record.is_a?(Entry) ? [record, record.factory.find] : [nil, record] end # Check if the record is a Work From 30c8cfccd8031032c87f4c47107240fb29357d93 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 7 Apr 2022 20:08:19 -0500 Subject: [PATCH 11/12] update the specs related to the find_record method --- .../concerns/bulkrax/dynamic_record_lookup_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb b/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb index 48782699..8af3b967 100644 --- a/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb +++ b/spec/models/concerns/bulkrax/dynamic_record_lookup_spec.rb @@ -39,14 +39,14 @@ module Bulkrax end it "returns the entry's record" do - expect(subject.find_record(source_identifier, importer_run_id)).to eq(record) + expect(subject.find_record(source_identifier, importer_run_id)[1]).to eq(record) end it "uses the entry's factory to find its record" do expect(entry).to receive(:factory) expect(factory).to receive(:find) - found_record = subject.find_record(source_identifier, importer_run_id) + _, found_record = subject.find_record(source_identifier, importer_run_id) expect(found_record.title).to eq(record.title) end @@ -54,7 +54,7 @@ module Bulkrax context 'when nothing is found' do it 'returns nil' do - expect(subject.find_record(source_identifier, importer_run_id)).to be_nil + expect(subject.find_record(source_identifier, importer_run_id)[1]).to be_nil end end end @@ -78,7 +78,7 @@ module Bulkrax end it 'returns the collection' do - expect(subject.find_record(id, importer_run_id)).to eq(collection) + expect(subject.find_record(id, importer_run_id)[1]).to eq(collection) end end @@ -90,13 +90,13 @@ module Bulkrax end it 'returns the work' do - expect(subject.find_record(id, importer_run_id)).to eq(work) + expect(subject.find_record(id, importer_run_id)[1]).to eq(work) end end context 'when nothing is found' do it 'returns nil' do - expect(subject.find_record(id, importer_run_id)).to be_nil + expect(subject.find_record(id, importer_run_id)[1]).to be_nil end end end From 7dc4ca2dc34c1447d80af135cf7136f6d0d18558 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 8 Apr 2022 10:58:54 -0500 Subject: [PATCH 12/12] update create relationship job specs --- spec/jobs/bulkrax/create_relationships_job_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/jobs/bulkrax/create_relationships_job_spec.rb b/spec/jobs/bulkrax/create_relationships_job_spec.rb index 4f47bdfb..4b6b5fb7 100644 --- a/spec/jobs/bulkrax/create_relationships_job_spec.rb +++ b/spec/jobs/bulkrax/create_relationships_job_spec.rb @@ -45,7 +45,8 @@ module Bulkrax id: child_record.id, member_of_collections_attributes: { 0 => { id: parent_record.id } } }, - klass: child_record.class + klass: child_record.class, + importer_run_id: importer.current_run.id ) end @@ -150,7 +151,8 @@ module Bulkrax id: parent_record.id, child_collection_id: child_record.id }, - klass: parent_record.class + klass: parent_record.class, + importer_run_id: importer.current_run.id ) end @@ -249,7 +251,8 @@ module Bulkrax id: parent_record.id, work_members_attributes: { 0 => { id: child_record.id } } }, - klass: parent_record.class + klass: parent_record.class, + importer_run_id: importer.current_run.id ) end @@ -366,7 +369,7 @@ module Bulkrax importer_run_id: importer.current_run.id ) - expect(importer.last_run.failed_relationships).to eq(1) + expect(Bulkrax::Importer.find(importer.id).last_run.failed_relationships).to eq(1) end end