Skip to content

Commit

Permalink
Fallback-set identifier from data hash if blank
Browse files Browse the repository at this point in the history
This is expected to be temporary. Updates to introduce
record_matchpoint == uri are already underway and change how/where
Response identifier gets set.
  • Loading branch information
kspurgin committed Aug 30, 2024
1 parent 6829e9c commit 4a891ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
11 changes: 10 additions & 1 deletion lib/collectionspace/mapper/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Response
attr_reader :orig_data, :doc,
:record_status, :csid, :uri, :refname,
:terms, :errors, :warnings,
:identifier, :merged_data, :xpaths,
:merged_data, :xpaths,
:split_data, :transformed_data
attr_accessor :combined_data

Expand Down Expand Up @@ -46,6 +46,15 @@ def add_identifier(id)
@identifier = id
end

def identifier
return @identifier unless @identifier.empty?

id_field = handler.record.identifier_field.downcase
return @identifier unless transformed_data.key?(id_field)

transformed_data[id_field][0]
end

def add_error(error)
errors << error
@errors = errors.flatten.compact
Expand Down
26 changes: 13 additions & 13 deletions spec/collectionspace/mapper/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
let(:customcfg) { {delimiter: "|", response_mode: "verbose"} }
let(:processed) { response.map }

context "with some terms found and some terms not found" do
let(:result) { processed.terms.reject { |t| t.found? } }
context "with terms found in cache and instance" do
let(:result) { processed.terms.select { |t| t.missing? } }

vcr_found_opts = {
cassette_name: "datahandler_uncached_found_terms",
Expand All @@ -211,16 +211,17 @@
}
end

it "returns expected found values" do
it "returns no missing terms" do
expect(result.length).to eq(0)
expect(processed.identifier).to eq("20CS.001.0002")
end
end

vcr_unfound_opts = {
cassette_name: "datahandler_uncached_unfound_terms",
record: :new_episodes
}
context "with terms in instance but not in cache, and not in instance",
context "with found term and missing term",
vcr: vcr_unfound_opts do
let(:data) do
{
Expand All @@ -232,8 +233,9 @@
}
end

it "returns expected found values" do
it "returns 1 missing term" do
expect(result.length).to eq(1)
expect(processed.identifier).to eq("20CS.001.0001")
end
end
end
Expand All @@ -250,6 +252,9 @@
# authority - in instance, not in cache
"namedCollection" => "QA TARGET Work"
}
resp1 = CollectionSpace::Mapper::Response.new(data1, handler)
handler.process(resp1)

data2 = {
"objectNumber" => "2",
# vocabulary - now in cache
Expand All @@ -259,16 +264,11 @@
# authority - not in instance, not in cache
"contentConceptAssociated" => "Birbs"
}

resp1 = CollectionSpace::Mapper::Response.new(data1, handler)
resp2 = CollectionSpace::Mapper::Response.new(data2, handler)

handler.process(resp1)

result = handler.process(resp2)
.terms
.select { |t| !t.found? }
expect(result.length).to eq(1)

expect(result.terms.count(&:missing?)).to eq(1)
expect(result.identifier).to eq("2")
end
end

Expand Down

0 comments on commit 4a891ab

Please sign in to comment.