Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue/handle record status check error appropriately #178

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion lib/collectionspace/mapper/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
13 changes: 6 additions & 7 deletions lib/collectionspace/mapper/tools/record_status_service_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/collectionspace/mapper/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module CollectionSpace
module Mapper
VERSION = "6.0.2"
VERSION = "6.0.3"
end
end
19 changes: 19 additions & 0 deletions spec/collectionspace/mapper/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading