diff --git a/CHANGELOG.md b/CHANGELOG.md index 283bb25f..40862ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ This project bumps the version number for any changes (including documentation u ## [Unreleased] - i.e. pushed to main branch but not yet tagged as a release +## [6.0.3] - 2024-10-18 +- BUGFIX: Rescue error when record status check finds more than one matching record, and add to Response errors for handling by ingest application + ## [6.0.2] - 2024-09-13 - BUGFIX: DataHandler now handles batch config passed as a String diff --git a/Gemfile.lock b/Gemfile.lock index 617af1ed..f3965a9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,7 +12,7 @@ GIT PATH remote: . specs: - collectionspace-mapper (6.0.2) + collectionspace-mapper (6.0.3) activesupport (= 6.0.4.7) chronic collectionspace-client (~> 0.15.0) diff --git a/lib/collectionspace/mapper/response.rb b/lib/collectionspace/mapper/response.rb index 435eec26..0f2e2656 100644 --- a/lib/collectionspace/mapper/response.rb +++ b/lib/collectionspace/mapper/response.rb @@ -88,7 +88,9 @@ def valid? def set_record_status if handler.batch.check_record_status - result = handler.status_checker.call(status_check_id) + result = get_record_status + return unless result + @record_status = result[:status] @csid = result[:csid] @uri = result[:uri] @@ -243,6 +245,22 @@ def status_check_id identifier end end + + def get_record_status + handler.status_checker.call(status_check_id) + rescue CollectionSpace::Mapper::MultipleCsRecordsFoundError => err + add_error({ + category: "multiple_matching_records_found", + message: err.message + }) + nil + rescue CollectionSpace::Mapper::Error, StandardError => err + add_error({ + category: "unknown", + message: err.message + }) + nil + end end end end diff --git a/lib/collectionspace/mapper/tools/record_status_service_client.rb b/lib/collectionspace/mapper/tools/record_status_service_client.rb index 11653768..5e670321 100644 --- a/lib/collectionspace/mapper/tools/record_status_service_client.rb +++ b/lib/collectionspace/mapper/tools/record_status_service_client.rb @@ -69,14 +69,13 @@ def lookup(value) elsif ct == 1 reportable_result(response.parsed[response_top][response_nested]) elsif ct > 1 - unless use_first? - fail CollectionSpace::Mapper::MultipleCsRecordsFoundError, - ct + if use_first? + item = response.parsed[response_top][response_nested].first + num_found = response.parsed[response_top][response_nested].length + reportable_result(item).merge({multiple_recs_found: num_found}) + else + fail CollectionSpace::Mapper::MultipleCsRecordsFoundError, ct end - - item = response.parsed[response_top][response_nested].first - num_found = response.parsed[response_top][response_nested].length - reportable_result(item).merge({multiple_recs_found: num_found}) end end diff --git a/lib/collectionspace/mapper/version.rb b/lib/collectionspace/mapper/version.rb index c901acf9..68df9526 100644 --- a/lib/collectionspace/mapper/version.rb +++ b/lib/collectionspace/mapper/version.rb @@ -2,6 +2,6 @@ module CollectionSpace module Mapper - VERSION = "6.0.2" + VERSION = "6.0.3" end end diff --git a/spec/collectionspace/mapper/response_spec.rb b/spec/collectionspace/mapper/response_spec.rb index 3c2d122b..f71d3f41 100644 --- a/spec/collectionspace/mapper/response_spec.rb +++ b/spec/collectionspace/mapper/response_spec.rb @@ -115,6 +115,25 @@ expect(response.uri).to eq("uri") expect(response.refname).to eq("refname") end + + context "when multiple records error" do + it "sets status as expected" do + errmsg = "3 matching records found in CollectionSpace. "\ + "Cannot determine which to update." + + handler.config.status_checker = checker + allow(checker).to receive(:call).and_raise( + CollectionSpace::Mapper::MultipleCsRecordsFoundError, 3 + ) + response.set_record_status + expect(response.record_status).to be_nil + expect(response.csid).to be_nil + expect(response.errors).to include({ + category: "multiple_matching_records_found", + message: errmsg + }) + end + end end context "when checking is turned off" do diff --git a/spec/collectionspace/mapper/tools/record_status_service_client_spec.rb b/spec/collectionspace/mapper/tools/record_status_service_client_spec.rb index c62a1450..702d841b 100644 --- a/spec/collectionspace/mapper/tools/record_status_service_client_spec.rb +++ b/spec/collectionspace/mapper/tools/record_status_service_client_spec.rb @@ -71,7 +71,9 @@ context "with default config" do it "raises error" do expect { result }.to raise_error( - CollectionSpace::Mapper::MultipleCsRecordsFoundError + CollectionSpace::Mapper::MultipleCsRecordsFoundError, + "2 matching records found in CollectionSpace. "\ + "Cannot determine which to update." ) end end