Module: Bulkrax::CsvRow::ParentReference

Defined in:
app/validators/bulkrax/csv_row/parent_reference.rb

Overview

Validates that any parent references in a row point to source identifiers that exist either elsewhere in the same CSV or as existing repository records. Uses context (Set of all source identifiers) to validate references within the CSV, and context (callable) to look up existing records in the same way the importer does at runtime. Uses context (String/Regexp, may be nil) for multi-value splitting.

Class Method Summary collapse

Class Method Details

.call(record, row_index, context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/validators/bulkrax/csv_row/parent_reference.rb', line 13

def self.call(record, row_index, context)
  all_ids = context[:all_ids]
  find_record = context[:find_record_by_source_identifier]

  collect_parent_ids(record, context).each do |parent_id|
    next if all_ids.include?(parent_id)
    next if find_record&.call(parent_id)

    context[:errors] << {
      row: row_index,
      source_identifier: record[:source_identifier],
      severity: 'error',
      category: 'invalid_parent_reference',
      column: 'parent',
      value: parent_id,
      message: I18n.t('bulkrax.importer.guided_import.validation.parent_reference_validator.errors.message',
                      value: parent_id,
                      field: 'source_identifier'),
      suggestion: I18n.t('bulkrax.importer.guided_import.validation.parent_reference_validator.errors.suggestion')
    }
  end
end