From 2cf594cee1eeceaff6f9b85dedef5dc5c9b2a1f3 Mon Sep 17 00:00:00 2001 From: Benjamin Kiah Stroud <32469930+bkiahstroud@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:35:30 -0700 Subject: [PATCH] validate missing elements against parsed metadata Before this change, if the raw_metadata contained "Title", which mapped to "title", an error saying that "title was missing" would be thrown. Plus I feel like it makes more sense to validate missing elements using an entry's parsed metadata, since Bulkrax has no control over what the incoming raw_metadata looks like --- app/models/bulkrax/csv_entry.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/models/bulkrax/csv_entry.rb b/app/models/bulkrax/csv_entry.rb index 65666890..072a86f3 100644 --- a/app/models/bulkrax/csv_entry.rb +++ b/app/models/bulkrax/csv_entry.rb @@ -68,7 +68,7 @@ def self.data_for_entry(data, _source_id, parser) end def build_metadata - validate_record + raise StandardError, 'Record not found' if record.nil? self.parsed_metadata = {} add_identifier @@ -82,15 +82,12 @@ def build_metadata sanitize_controlled_uri_values! add_local - self.parsed_metadata - end - - def validate_record - raise StandardError, 'Record not found' if record.nil? - unless importerexporter.parser.required_elements?(record) + unless importerexporter.parser.required_elements?(self.parsed_metadata) raise StandardError, "Missing required elements, missing element(s) are: "\ -"#{importerexporter.parser.missing_elements(record).join(', ')}" + "#{importerexporter.parser.missing_elements(self.parsed_metadata).join(', ')}" end + + self.parsed_metadata end def add_identifier