From 9268bbb262aaafee7fb098b36fd362044d6eccbc Mon Sep 17 00:00:00 2001 From: Benjamin Kiah Stroud <32469930+bkiahstroud@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:26:44 -0800 Subject: [PATCH] split pattern is accessed from the parser instead of config Transfer responsibility of accessing the split pattern from the config to the ApplicationParser. This enables the default split pattern to be overwritten Hyku will soon get an `Account` setting that allows for per-tenant overrides for the default split pattern. This change enables that feature The default value is still set in the config. Existing installations should see no difference in behavior; this change is backwards-compatible --- app/matchers/bulkrax/application_matcher.rb | 2 +- app/models/bulkrax/csv_entry.rb | 4 ++-- app/parsers/bulkrax/application_parser.rb | 4 ++++ app/parsers/bulkrax/csv_parser.rb | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/matchers/bulkrax/application_matcher.rb b/app/matchers/bulkrax/application_matcher.rb index 0f7c7cca..1d4dc3c0 100644 --- a/app/matchers/bulkrax/application_matcher.rb +++ b/app/matchers/bulkrax/application_matcher.rb @@ -33,7 +33,7 @@ def result(_parser, content) def process_split if self.split.is_a?(TrueClass) - @result = @result.split(Bulkrax.multi_value_element_split_on) + @result = @result.split(ApplicationParser.multi_value_element_split_on) elsif self.split @result = @result.split(Regexp.new(self.split)) @result = @result.map(&:strip).select(&:present?) diff --git a/app/models/bulkrax/csv_entry.rb b/app/models/bulkrax/csv_entry.rb index 65666890..f829d71e 100644 --- a/app/models/bulkrax/csv_entry.rb +++ b/app/models/bulkrax/csv_entry.rb @@ -129,7 +129,7 @@ def add_ingested_metadata def add_file self.parsed_metadata['file'] ||= [] if record['file']&.is_a?(String) - self.parsed_metadata['file'] = record['file'].split(Bulkrax.multi_value_element_split_on) + self.parsed_metadata['file'] = record['file'].split(parser.multi_value_element_split_on) elsif record['file'].is_a?(Array) self.parsed_metadata['file'] = record['file'] end @@ -350,7 +350,7 @@ def collection_identifiers return [] unless parent_field_mapping.present? && record[parent_field_mapping].present? identifiers = [] - split_references = record[parent_field_mapping].split(Bulkrax.multi_value_element_split_on) + split_references = record[parent_field_mapping].split(parser.multi_value_element_split_on) split_references.each do |c_reference| matching_collection_entries = importerexporter.entries.select do |e| (e.raw_metadata&.[](source_identifier) == c_reference) && diff --git a/app/parsers/bulkrax/application_parser.rb b/app/parsers/bulkrax/application_parser.rb index 161a6740..e529dd30 100644 --- a/app/parsers/bulkrax/application_parser.rb +++ b/app/parsers/bulkrax/application_parser.rb @@ -34,6 +34,10 @@ def self.import_supported? true end + def self.multi_value_element_split_on + Bulkrax.multi_value_element_split_on + end + def initialize(importerexporter) @importerexporter = importerexporter @headers = [] diff --git a/app/parsers/bulkrax/csv_parser.rb b/app/parsers/bulkrax/csv_parser.rb index 03159ebb..d11afc35 100644 --- a/app/parsers/bulkrax/csv_parser.rb +++ b/app/parsers/bulkrax/csv_parser.rb @@ -338,7 +338,7 @@ def file_paths file_mapping = Bulkrax.field_mappings.dig(self.class.to_s, 'file', :from)&.first&.to_sym || :file next if r[file_mapping].blank? - r[file_mapping].split(Bulkrax.multi_value_element_split_on).map do |f| + r[file_mapping].split(multi_value_element_split_on).map do |f| file = File.join(path_to_files, f.tr(' ', '_')) if File.exist?(file) # rubocop:disable Style/GuardClause file @@ -366,7 +366,7 @@ def unique_collection_identifier(collection_hash) entry_uid ||= if Bulkrax.fill_in_blank_source_identifiers.present? Bulkrax.fill_in_blank_source_identifiers.call(self, records.find_index(collection_hash)) else - collection_hash[:title].split(Bulkrax.multi_value_element_split_on).first + collection_hash[:title].split(multi_value_element_split_on).first end entry_uid