Skip to content

Commit

Permalink
make find_by_source_identifier dynamic
Browse files Browse the repository at this point in the history
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:
- scientist-softserv/hykuup_knapsack#128

Co-Authored-By: Kirk Wang <k3wang@gmail.com>
  • Loading branch information
ShanaLMoore and kirkkwang committed Jan 31, 2024
1 parent 6075930 commit d28b42a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/factories/bulkrax/object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion app/factories/bulkrax/valkyrie_object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/bulkrax/import_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/parsers/bulkrax/application_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ 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
end

# @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
Expand Down

0 comments on commit d28b42a

Please sign in to comment.