From 6075930cc5d0863d197bfa38fc9e64679240bb02 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Mon, 29 Jan 2024 14:55:13 -0800 Subject: [PATCH 1/7] i903 - move bulkrax identifier custom queries into bulkrax move bulkrax identifier custom queries into bulkrax Issue: - https://github.com/scientist-softserv/hykuup_knapsack/issues/136 --- .../valkyrie/find_by_bulkrax_identifier.rb | 35 +++++++++++++++++++ .../find_by_bulkrax_identifier.rb | 29 +++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb create mode 100644 app/services/wings/custom_queries/find_by_bulkrax_identifier.rb diff --git a/app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb b/app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb new file mode 100644 index 00000000..98247568 --- /dev/null +++ b/app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true +module Bulkrax + module Valkyrie + module CustomQueries + ## + # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries + class FindByBulkraxIdentifier + def self.queries + [:find_by_bulkrax_identifier] + end + + def initialize(query_service:) + @query_service = query_service + end + + attr_reader :query_service + delegate :resource_factory, to: :query_service + delegate :orm_class, to: :resource_factory + + ## + # @param identifier String + def find_by_bulkrax_identifier(identifier:) + query_service.run_query(sql_by_bulkrax_identifier, identifier).first + end + + def sql_by_bulkrax_identifier + <<-SQL + SELECT * FROM orm_resources + WHERE metadata -> 'bulkrax_identifier' ->> 0 = ?; + SQL + end + end + end + end +end diff --git a/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb b/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb new file mode 100644 index 00000000..2867dcfe --- /dev/null +++ b/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true +module Wings + module CustomQueries + class FindByBulkraxIdentifier + # Custom query override specific to Wings + # Use: + # Hyrax.custom_queries.find_bulkrax_id(identifier: identifier, models: [ModelClass]) + + def self.queries + [:find_by_bulkrax_identifier] + end + + attr_reader :query_service + delegate :resource_factory, to: :query_service + + def initialize(query_service:) + @query_service = query_service + end + + def find_by_bulkrax_identifier(identifier:, use_valkyrie: true) + af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first + + return af_object unless use_valkyrie + + resource_factory.to_resource(object: af_object) + end + end + end +end From 78e677b1470951d54a4c3e182d64299b82622d34 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 31 Jan 2024 11:02:38 -0800 Subject: [PATCH 2/7] make find_by_source_identifier dynamic Import a csv with child works. The forming of relationships is not working. Part of the problem is the find_by_bulkrax_identifier call. From GBH, this used to be find_by_bulkrax_identifier which not all clients will configure as their source identifier. Instead we need to ask for the source identifier and use that for the sql query. This commit goes along with a PR from Hyku which currently has the find_by_source_identifier.rb files defined. Issue: - https://github.com/scientist-softserv/hykuup_knapsack/issues/128 Co-Authored-By: Kirk Wang --- app/factories/bulkrax/object_factory.rb | 5 +-- .../bulkrax/valkyrie_object_factory.rb | 5 ++- .../concerns/bulkrax/import_behavior.rb | 3 +- app/parsers/bulkrax/application_parser.rb | 4 +-- .../valkyrie/find_by_bulkrax_identifier.rb | 35 ------------------- .../find_by_source_identifier.rb | 35 +++++++++++++++++++ ...tifier.rb => find_by_source_identifier.rb} | 11 +++--- .../find_by_source_identifier_spec.rb | 22 ++++++++++++ 8 files changed, 75 insertions(+), 45 deletions(-) delete mode 100644 app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb create mode 100644 app/services/hyrax/custom_queries/find_by_source_identifier.rb rename app/services/wings/custom_queries/{find_by_bulkrax_identifier.rb => find_by_source_identifier.rb} (76%) create mode 100644 spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb diff --git a/app/factories/bulkrax/object_factory.rb b/app/factories/bulkrax/object_factory.rb index 02af478e..8fce9a47 100644 --- a/app/factories/bulkrax/object_factory.rb +++ b/app/factories/bulkrax/object_factory.rb @@ -28,10 +28,10 @@ class ObjectFactory # rubocop:disable Metrics/ClassLength class_attribute :transformation_removes_blank_hash_values, default: false define_model_callbacks :save, :create - attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :work_identifier_search_field, :related_parents_parsed_mapping, :importer_run_id + attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :work_identifier_search_field, :related_parents_parsed_mapping, :importer_run_id, :entry # rubocop:disable Metrics/ParameterLists - def initialize(attributes:, source_identifier_value:, work_identifier:, work_identifier_search_field:, related_parents_parsed_mapping: nil, replace_files: false, user: nil, klass: nil, importer_run_id: nil, update_files: false) + def initialize(attributes:, source_identifier_value:, work_identifier:, work_identifier_search_field:, related_parents_parsed_mapping: nil, replace_files: false, user: nil, klass: nil, importer_run_id: nil, update_files: false, entry:) @attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes) @replace_files = replace_files @update_files = update_files @@ -42,6 +42,7 @@ def initialize(attributes:, source_identifier_value:, work_identifier:, work_ide @source_identifier_value = source_identifier_value @klass = klass || Bulkrax.default_work_type.constantize @importer_run_id = importer_run_id + @entry = entry end # rubocop:enable Metrics/ParameterLists diff --git a/app/factories/bulkrax/valkyrie_object_factory.rb b/app/factories/bulkrax/valkyrie_object_factory.rb index 5bb9c43c..190e04b9 100644 --- a/app/factories/bulkrax/valkyrie_object_factory.rb +++ b/app/factories/bulkrax/valkyrie_object_factory.rb @@ -30,7 +30,10 @@ def search_by_identifier # 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 = Hyrax.query_service.custom_queries.find_by_bulkrax_identifier(identifier: source_identifier_value) + match = Hyrax.query_service.custom_queries.find_by_source_identifier( + work_identifier: entry.work_identifier, + source_identifier_value: source_identifier_value + ) return match if match rescue => err diff --git a/app/models/concerns/bulkrax/import_behavior.rb b/app/models/concerns/bulkrax/import_behavior.rb index 6e2f3c2d..e3a1a548 100644 --- a/app/models/concerns/bulkrax/import_behavior.rb +++ b/app/models/concerns/bulkrax/import_behavior.rb @@ -185,7 +185,8 @@ def factory user: user, klass: factory_class, importer_run_id: importerexporter.last_run.id, - update_files: update_files) + update_files: update_files, + entry: self) end def factory_class diff --git a/app/parsers/bulkrax/application_parser.rb b/app/parsers/bulkrax/application_parser.rb index 2a46d124..5fe41fe6 100644 --- a/app/parsers/bulkrax/application_parser.rb +++ b/app/parsers/bulkrax/application_parser.rb @@ -68,7 +68,7 @@ def records(_opts = {}) # @return [Symbol] the name of the identifying property in the source system from which we're # importing (e.g. is *not* this application that mounts *this* Bulkrax engine). # - # @see #work_identifier + # @see #source_identifier # @see https://github.com/samvera-labs/bulkrax/wiki/CSV-Importer#source-identifier Bulkrax Wiki regarding source identifier def source_identifier @source_identifier ||= get_field_mapping_hash_for('source_identifier')&.values&.first&.[]('from')&.first&.to_sym || :source_identifier @@ -76,7 +76,7 @@ def source_identifier # @return [Symbol] the name of the identifying property for the system which we're importing # into (e.g. the application that mounts *this* Bulkrax engine) - # @see #source_identifier + # @see #work_identifier def work_identifier @work_identifier ||= get_field_mapping_hash_for('source_identifier')&.keys&.first&.to_sym || :source end diff --git a/app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb b/app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb deleted file mode 100644 index 98247568..00000000 --- a/app/services/bulkrax/valkyrie/find_by_bulkrax_identifier.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true -module Bulkrax - module Valkyrie - module CustomQueries - ## - # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries - class FindByBulkraxIdentifier - def self.queries - [:find_by_bulkrax_identifier] - end - - def initialize(query_service:) - @query_service = query_service - end - - attr_reader :query_service - delegate :resource_factory, to: :query_service - delegate :orm_class, to: :resource_factory - - ## - # @param identifier String - def find_by_bulkrax_identifier(identifier:) - query_service.run_query(sql_by_bulkrax_identifier, identifier).first - end - - def sql_by_bulkrax_identifier - <<-SQL - SELECT * FROM orm_resources - WHERE metadata -> 'bulkrax_identifier' ->> 0 = ?; - SQL - end - end - end - end -end diff --git a/app/services/hyrax/custom_queries/find_by_source_identifier.rb b/app/services/hyrax/custom_queries/find_by_source_identifier.rb new file mode 100644 index 00000000..c6de485f --- /dev/null +++ b/app/services/hyrax/custom_queries/find_by_source_identifier.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Hyrax + module CustomQueries + ## + # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries + class FindBySourceIdentifier + def self.queries + [:find_by_source_identifier] + end + + def initialize(query_service:) + @query_service = query_service + end + + attr_reader :query_service + delegate :resource_factory, to: :query_service + delegate :orm_class, to: :resource_factory + + ## + # @param identifier String + def find_by_source_identifier(work_identifier:, source_identifier_value:) + sql_query = sql_by_source_identifier + query_service.run_query(sql_query, work_identifier, source_identifier_value).first + end + + def sql_by_source_identifier + <<-SQL + SELECT * FROM orm_resources + WHERE metadata -> ? ->> 0 = ?; + SQL + end + end + end +end \ No newline at end of file diff --git a/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb b/app/services/wings/custom_queries/find_by_source_identifier.rb similarity index 76% rename from app/services/wings/custom_queries/find_by_bulkrax_identifier.rb rename to app/services/wings/custom_queries/find_by_source_identifier.rb index 2867dcfe..5a3e2a8c 100644 --- a/app/services/wings/custom_queries/find_by_bulkrax_identifier.rb +++ b/app/services/wings/custom_queries/find_by_source_identifier.rb @@ -1,13 +1,16 @@ # frozen_string_literal: true + +# TODO: Make more dynamic. Possibly move to Bulkrax. + module Wings module CustomQueries - class FindByBulkraxIdentifier + class FindBySourceIdentifier # Custom query override specific to Wings # Use: # Hyrax.custom_queries.find_bulkrax_id(identifier: identifier, models: [ModelClass]) def self.queries - [:find_by_bulkrax_identifier] + [:find_by_source_identifier] end attr_reader :query_service @@ -17,7 +20,7 @@ def initialize(query_service:) @query_service = query_service end - def find_by_bulkrax_identifier(identifier:, use_valkyrie: true) + def find_by_source_identifier(identifier:, use_valkyrie: true) af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first return af_object unless use_valkyrie @@ -26,4 +29,4 @@ def find_by_bulkrax_identifier(identifier:, use_valkyrie: true) end end end -end +end \ No newline at end of file diff --git a/spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb b/spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb new file mode 100644 index 00000000..439ce373 --- /dev/null +++ b/spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +RSpec.describe Hyrax::CustomQueries::FindBySourceIdentifier do + describe '.queries' do + subject { described_class.queries } + let(:query_name) { :find_by_source_identifier } + + it { is_expected.to include(query_name) } + + it 'is registered with the Hyrax.query_service' do + expect(Hyrax.query_service.custom_queries).to respond_to(query_name) + end + + context ':find_by_source_identifier query' do + it 'is valid SQL' do + expect do + Hyrax.query_service.custom_queries.find_by_source_identifier(work_identifier: 'source', source_identifier_value: "testing-bulkrax-1-2-3") + end.not_to raise_error + end + end + end +end \ No newline at end of file From ff02e13a2506f1f2cc24153b8f928c990325fcba Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 31 Jan 2024 11:37:26 -0800 Subject: [PATCH 3/7] remove files: they live in Hyku for now Co-Authored-By: Kirk Wang --- .../find_by_source_identifier.rb | 35 ------------------- .../find_by_source_identifier.rb | 32 ----------------- .../find_by_source_identifier_spec.rb | 22 ------------ 3 files changed, 89 deletions(-) delete mode 100644 app/services/hyrax/custom_queries/find_by_source_identifier.rb delete mode 100644 app/services/wings/custom_queries/find_by_source_identifier.rb delete mode 100644 spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb diff --git a/app/services/hyrax/custom_queries/find_by_source_identifier.rb b/app/services/hyrax/custom_queries/find_by_source_identifier.rb deleted file mode 100644 index c6de485f..00000000 --- a/app/services/hyrax/custom_queries/find_by_source_identifier.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module Hyrax - module CustomQueries - ## - # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries - class FindBySourceIdentifier - def self.queries - [:find_by_source_identifier] - end - - def initialize(query_service:) - @query_service = query_service - end - - attr_reader :query_service - delegate :resource_factory, to: :query_service - delegate :orm_class, to: :resource_factory - - ## - # @param identifier String - def find_by_source_identifier(work_identifier:, source_identifier_value:) - sql_query = sql_by_source_identifier - query_service.run_query(sql_query, work_identifier, source_identifier_value).first - end - - def sql_by_source_identifier - <<-SQL - SELECT * FROM orm_resources - WHERE metadata -> ? ->> 0 = ?; - SQL - end - end - end -end \ No newline at end of file diff --git a/app/services/wings/custom_queries/find_by_source_identifier.rb b/app/services/wings/custom_queries/find_by_source_identifier.rb deleted file mode 100644 index 5a3e2a8c..00000000 --- a/app/services/wings/custom_queries/find_by_source_identifier.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -# TODO: Make more dynamic. Possibly move to Bulkrax. - -module Wings - module CustomQueries - class FindBySourceIdentifier - # Custom query override specific to Wings - # Use: - # Hyrax.custom_queries.find_bulkrax_id(identifier: identifier, models: [ModelClass]) - - def self.queries - [:find_by_source_identifier] - end - - attr_reader :query_service - delegate :resource_factory, to: :query_service - - def initialize(query_service:) - @query_service = query_service - end - - def find_by_source_identifier(identifier:, use_valkyrie: true) - af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first - - return af_object unless use_valkyrie - - resource_factory.to_resource(object: af_object) - end - end - end -end \ No newline at end of file diff --git a/spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb b/spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb deleted file mode 100644 index 439ce373..00000000 --- a/spec/services/hyrax/custom_queries/find_by_source_identifier_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -RSpec.describe Hyrax::CustomQueries::FindBySourceIdentifier do - describe '.queries' do - subject { described_class.queries } - let(:query_name) { :find_by_source_identifier } - - it { is_expected.to include(query_name) } - - it 'is registered with the Hyrax.query_service' do - expect(Hyrax.query_service.custom_queries).to respond_to(query_name) - end - - context ':find_by_source_identifier query' do - it 'is valid SQL' do - expect do - Hyrax.query_service.custom_queries.find_by_source_identifier(work_identifier: 'source', source_identifier_value: "testing-bulkrax-1-2-3") - end.not_to raise_error - end - end - end -end \ No newline at end of file From 29f226461375e6fcd91e0c26b27581cf4471f28a Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 31 Jan 2024 12:42:36 -0800 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=A7=B9=20Place=20custom=20queries=20b?= =?UTF-8?q?ack=20in=20Bulkrax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../find_by_source_identifier.rb | 35 +++++++++++++++++++ .../find_by_source_identifier.rb | 30 ++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 app/services/hyrax/custom_queries/find_by_source_identifier.rb create mode 100644 app/services/wings/custom_queries/find_by_source_identifier.rb diff --git a/app/services/hyrax/custom_queries/find_by_source_identifier.rb b/app/services/hyrax/custom_queries/find_by_source_identifier.rb new file mode 100644 index 00000000..6a7f77ea --- /dev/null +++ b/app/services/hyrax/custom_queries/find_by_source_identifier.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Hyrax + module CustomQueries + ## + # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries + class FindBySourceIdentifier + def self.queries + [:find_by_source_identifier] + end + + def initialize(query_service:) + @query_service = query_service + end + + attr_reader :query_service + delegate :resource_factory, to: :query_service + delegate :orm_class, to: :resource_factory + + ## + # @param identifier String + def find_by_source_identifier(work_identifier:, source_identifier_value:) + sql_query = sql_by_source_identifier + query_service.run_query(sql_query, work_identifier, source_identifier_value).first + end + + def sql_by_source_identifier + <<-SQL + SELECT * FROM orm_resources + WHERE metadata -> ? ->> 0 = ?; + SQL + end + end + end +end diff --git a/app/services/wings/custom_queries/find_by_source_identifier.rb b/app/services/wings/custom_queries/find_by_source_identifier.rb new file mode 100644 index 00000000..630e1899 --- /dev/null +++ b/app/services/wings/custom_queries/find_by_source_identifier.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Wings + module CustomQueries + class FindBySourceIdentifier + # Custom query override specific to Wings + # Use: + # Hyrax.custom_queries.find_bulkrax_id(identifier: identifier, models: [ModelClass]) + + def self.queries + [:find_by_source_identifier] + end + + attr_reader :query_service + delegate :resource_factory, to: :query_service + + def initialize(query_service:) + @query_service = query_service + end + + def find_by_source_identifier(identifier:, use_valkyrie: true) + af_object = ActiveFedora::Base.where("bulkrax_identifier_sim:#{identifier}").first + + return af_object unless use_valkyrie + + resource_factory.to_resource(object: af_object) + end + end + end +end From 9ad140fff4fa7b8ad4d018d26e5fdf31e6d25d5d Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 31 Jan 2024 14:00:52 -0800 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=A7=B9=20remove=20misleading=20commen?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Kirk Wang --- app/services/wings/custom_queries/find_by_source_identifier.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/services/wings/custom_queries/find_by_source_identifier.rb b/app/services/wings/custom_queries/find_by_source_identifier.rb index 630e1899..c51da662 100644 --- a/app/services/wings/custom_queries/find_by_source_identifier.rb +++ b/app/services/wings/custom_queries/find_by_source_identifier.rb @@ -4,8 +4,6 @@ module Wings module CustomQueries class FindBySourceIdentifier # Custom query override specific to Wings - # Use: - # Hyrax.custom_queries.find_bulkrax_id(identifier: identifier, models: [ModelClass]) def self.queries [:find_by_source_identifier] From 5fc49624101bc926ad7a3b86d38a481d20a9e0cb Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 31 Jan 2024 14:31:06 -0800 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=A7=B9=20Entry=20is=20a=20required=20?= =?UTF-8?q?argument=20when=20initializing=20ObjectFactory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix for broken specs Co-Authored-By: Kirk Wang --- spec/factories/bulkrax_object_factories.rb | 3 ++- spec/models/bulkrax/object_factory_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/factories/bulkrax_object_factories.rb b/spec/factories/bulkrax_object_factories.rb index 59e11635..f48b95bc 100644 --- a/spec/factories/bulkrax_object_factories.rb +++ b/spec/factories/bulkrax_object_factories.rb @@ -7,7 +7,8 @@ attributes: {}, source_identifier_value: :source_identifier, work_identifier: :source, - work_identifier_search_field: 'source_sim' + work_identifier_search_field: 'source_sim', + entry: FactoryBot.build(:bulkrax_entry) ) end end diff --git a/spec/models/bulkrax/object_factory_spec.rb b/spec/models/bulkrax/object_factory_spec.rb index 2c888fea..b8ba7a63 100644 --- a/spec/models/bulkrax/object_factory_spec.rb +++ b/spec/models/bulkrax/object_factory_spec.rb @@ -22,7 +22,8 @@ module Bulkrax factory = described_class.new(attributes: attributes, source_identifier_value: 123, work_identifier: "filled_string", - work_identifier_search_field: 'filled_string_sim') + work_identifier_search_field: 'filled_string_sim', + entry: FactoryBot.build(:bulkrax_entry)) factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string] expect(factory.send(:transform_attributes)).to eq(attributes.stringify_keys) end @@ -34,7 +35,8 @@ module Bulkrax factory = described_class.new(attributes: attributes, source_identifier_value: 123, work_identifier: "filled_string", - work_identifier_search_field: 'filled_string_sim') + work_identifier_search_field: 'filled_string_sim', + entry: FactoryBot.build(:bulkrax_entry)) factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string] factory.transformation_removes_blank_hash_values = true expect(factory.send(:transform_attributes)) From 6d0923546d2a98a1b3c0aa3da77b29aeb1379260 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 31 Jan 2024 14:43:09 -0800 Subject: [PATCH 7/7] revert changes to pass Entry arg The object factory already has work_identifier: parser.work_identifier. we don't need the entry argument after all. ref: - https://github.com/samvera/bulkrax/blob/main/app/models/concerns/bulkrax/import_behavior.rb#L181 Co-Authored-By: Kirk Wang --- app/factories/bulkrax/object_factory.rb | 5 ++--- app/factories/bulkrax/valkyrie_object_factory.rb | 2 +- app/models/concerns/bulkrax/import_behavior.rb | 3 +-- spec/factories/bulkrax_object_factories.rb | 3 +-- spec/models/bulkrax/object_factory_spec.rb | 6 ++---- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/factories/bulkrax/object_factory.rb b/app/factories/bulkrax/object_factory.rb index 8fce9a47..02af478e 100644 --- a/app/factories/bulkrax/object_factory.rb +++ b/app/factories/bulkrax/object_factory.rb @@ -28,10 +28,10 @@ class ObjectFactory # rubocop:disable Metrics/ClassLength class_attribute :transformation_removes_blank_hash_values, default: false define_model_callbacks :save, :create - attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :work_identifier_search_field, :related_parents_parsed_mapping, :importer_run_id, :entry + attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier, :work_identifier_search_field, :related_parents_parsed_mapping, :importer_run_id # rubocop:disable Metrics/ParameterLists - def initialize(attributes:, source_identifier_value:, work_identifier:, work_identifier_search_field:, related_parents_parsed_mapping: nil, replace_files: false, user: nil, klass: nil, importer_run_id: nil, update_files: false, entry:) + def initialize(attributes:, source_identifier_value:, work_identifier:, work_identifier_search_field:, 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 @@ -42,7 +42,6 @@ def initialize(attributes:, source_identifier_value:, work_identifier:, work_ide @source_identifier_value = source_identifier_value @klass = klass || Bulkrax.default_work_type.constantize @importer_run_id = importer_run_id - @entry = entry end # rubocop:enable Metrics/ParameterLists diff --git a/app/factories/bulkrax/valkyrie_object_factory.rb b/app/factories/bulkrax/valkyrie_object_factory.rb index 190e04b9..b6a504a3 100644 --- a/app/factories/bulkrax/valkyrie_object_factory.rb +++ b/app/factories/bulkrax/valkyrie_object_factory.rb @@ -31,7 +31,7 @@ def search_by_identifier # 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 = Hyrax.query_service.custom_queries.find_by_source_identifier( - work_identifier: entry.work_identifier, + work_identifier: work_identifier, source_identifier_value: source_identifier_value ) diff --git a/app/models/concerns/bulkrax/import_behavior.rb b/app/models/concerns/bulkrax/import_behavior.rb index e3a1a548..6e2f3c2d 100644 --- a/app/models/concerns/bulkrax/import_behavior.rb +++ b/app/models/concerns/bulkrax/import_behavior.rb @@ -185,8 +185,7 @@ def factory user: user, klass: factory_class, importer_run_id: importerexporter.last_run.id, - update_files: update_files, - entry: self) + update_files: update_files) end def factory_class diff --git a/spec/factories/bulkrax_object_factories.rb b/spec/factories/bulkrax_object_factories.rb index f48b95bc..59e11635 100644 --- a/spec/factories/bulkrax_object_factories.rb +++ b/spec/factories/bulkrax_object_factories.rb @@ -7,8 +7,7 @@ attributes: {}, source_identifier_value: :source_identifier, work_identifier: :source, - work_identifier_search_field: 'source_sim', - entry: FactoryBot.build(:bulkrax_entry) + work_identifier_search_field: 'source_sim' ) end end diff --git a/spec/models/bulkrax/object_factory_spec.rb b/spec/models/bulkrax/object_factory_spec.rb index b8ba7a63..2c888fea 100644 --- a/spec/models/bulkrax/object_factory_spec.rb +++ b/spec/models/bulkrax/object_factory_spec.rb @@ -22,8 +22,7 @@ module Bulkrax factory = described_class.new(attributes: attributes, source_identifier_value: 123, work_identifier: "filled_string", - work_identifier_search_field: 'filled_string_sim', - entry: FactoryBot.build(:bulkrax_entry)) + work_identifier_search_field: 'filled_string_sim') factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string] expect(factory.send(:transform_attributes)).to eq(attributes.stringify_keys) end @@ -35,8 +34,7 @@ module Bulkrax factory = described_class.new(attributes: attributes, source_identifier_value: 123, work_identifier: "filled_string", - work_identifier_search_field: 'filled_string_sim', - entry: FactoryBot.build(:bulkrax_entry)) + work_identifier_search_field: 'filled_string_sim') factory.base_permitted_attributes = %i[empty_array empty_string filled_array filled_string] factory.transformation_removes_blank_hash_values = true expect(factory.send(:transform_attributes))