From 88cb7ac7584064a03b3754b087206e3e18bbbfbe Mon Sep 17 00:00:00 2001 From: tamsin johnson Date: Mon, 21 Nov 2022 11:19:17 -0800 Subject: [PATCH] add configuration for using a custom ObjectFactory (#673) * add configuration for using a custom ObjectFactory this is a first step toward #672 and valkyrie support. we want to be able to drop in an ObjectFactory implementation that finds and saves using Valkyrie instead of ActiveFedora. * fallback to default (#675) Update import_behavior.rb @no-reply what do you think about this change? This is mainly for projects that have Bulkrax already set up and don't have/don't know about the generated config that update to the latest version of Bulkrax. Also, this should fix specs. Co-authored-by: Kirk Wang --- .../concerns/bulkrax/import_behavior.rb | 19 ++++++++++--------- lib/bulkrax.rb | 1 + .../templates/config/initializers/bulkrax.rb | 3 +++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/models/concerns/bulkrax/import_behavior.rb b/app/models/concerns/bulkrax/import_behavior.rb index b272192a..3fd840cd 100644 --- a/app/models/concerns/bulkrax/import_behavior.rb +++ b/app/models/concerns/bulkrax/import_behavior.rb @@ -165,15 +165,16 @@ def active_id_for_authority?(value, field) end def factory - @factory ||= Bulkrax::ObjectFactory.new(attributes: self.parsed_metadata, - source_identifier_value: identifier, - work_identifier: parser.work_identifier, - related_parents_parsed_mapping: parser.related_parents_parsed_mapping, - replace_files: replace_files, - user: user, - klass: factory_class, - importer_run_id: importerexporter.last_run.id, - update_files: update_files) + of = Bulkrax.object_factory || Bulkrax::ObjectFactory + @factory ||= of.new(attributes: self.parsed_metadata, + source_identifier_value: identifier, + work_identifier: parser.work_identifier, + related_parents_parsed_mapping: parser.related_parents_parsed_mapping, + replace_files: replace_files, + user: user, + klass: factory_class, + importer_run_id: importerexporter.last_run.id, + update_files: update_files) end def factory_class diff --git a/lib/bulkrax.rb b/lib/bulkrax.rb index 0d693ca4..75981751 100644 --- a/lib/bulkrax.rb +++ b/lib/bulkrax.rb @@ -16,6 +16,7 @@ class << self :import_path, :multi_value_element_join_on, :multi_value_element_split_on, + :object_factory, :parsers, :qa_controlled_properties, :related_children_field_mapping, diff --git a/lib/generators/bulkrax/templates/config/initializers/bulkrax.rb b/lib/generators/bulkrax/templates/config/initializers/bulkrax.rb index f01eed36..9e3cf8cd 100644 --- a/lib/generators/bulkrax/templates/config/initializers/bulkrax.rb +++ b/lib/generators/bulkrax/templates/config/initializers/bulkrax.rb @@ -10,6 +10,9 @@ # Default is the first returned by Hyrax.config.curation_concerns # config.default_work_type = MyWork + # Factory Class to use when generating and saving objects + config.object_factory = Bulkrax::ObjectFactory + # Path to store pending imports # config.import_path = 'tmp/imports'