Skip to content

Commit

Permalink
Merge pull request #170 from collectionspace/repeatable-field-in-group
Browse files Browse the repository at this point in the history
Repeatable field in group
  • Loading branch information
kspurgin authored Dec 20, 2023
2 parents 2a2cc90 + 324273a commit 97a5000
Show file tree
Hide file tree
Showing 13 changed files with 547 additions and 33 deletions.
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

## [5.0.2] - 2023-12-19
- BUGFIX for [#148](https://github.com/collectionspace/collectionspace-mapper/issues/148)

## [5.0.1] - 2023-04-25
- BUGFIX for [#165](https://github.com/collectionspace/collectionspace-mapper/issues/165)

Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GIT
PATH
remote: .
specs:
collectionspace-mapper (5.0.1)
collectionspace-mapper (5.0.2)
activesupport (= 7.0.4.3)
chronic
collectionspace-client (~> 0.15.0)
Expand Down Expand Up @@ -96,15 +96,15 @@ GEM
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.1)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rspec-support (3.12.1)
rubocop (1.56.1)
base64 (~> 0.1.1)
json (~> 2.3)
Expand Down
19 changes: 14 additions & 5 deletions lib/collectionspace/mapper/data_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ def populate_subgroup_field_data(field, data, target)

def subgrouplist_target(parent_path, group_index, subgroup_path, subgroup)
grp_target = doc.xpath("//#{parent_path}")[group_index]
target_xpath = "#{subgroup_path.join("/")}/#{subgroup}"
target_xpath = if subgroup_path.empty?
subgroup
else
"#{subgroup_path.join("/")}/#{subgroup}"
end
grp_target.xpath(target_xpath)
end

Expand Down Expand Up @@ -274,9 +278,9 @@ def assign_subgroup_values_to_group_hash_data(groups, field, subgroups)
def map_subgroup(xpath, thisdata)
parent_path = xpath.parent
parent_set = doc.xpath("//#{parent_path}")
subgroup_path = xpath.mappings[0].fullpath.gsub(
"#{xpath.parent}/", ""
).split("/")
subgroup_path = xpath.path
.delete_prefix("#{parent_path}/")
.split("/")
subgroup = subgroup_path.pop

# create a hash of subgroup data split up and structured for mapping
Expand Down Expand Up @@ -309,7 +313,12 @@ def map_subgroup(xpath, thisdata)

groups.each do |i, _data|
max_ct.times do
target = doc.xpath("//#{parent_path}/#{subgroup_path.join("/")}")
targetpath = if subgroup_path.empty?
parent_path
else
"#{parent_path}/#{subgroup_path.join("/")}"
end
target = doc.xpath("//#{targetpath}")
target[i].add_child(Nokogiri::XML::Node.new(subgroup, doc))
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 = "5.0.1"
VERSION = "5.0.2"
end
end
6 changes: 3 additions & 3 deletions spec/collectionspace/mapper/column_mappings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end

describe "#known_columns" do
let(:mapper) { "core_7-1-0_collectionobject" }
let(:mapper) { "core_7-2-0_collectionobject" }

it "returns list of downcased datacolumns" do
expect(mappings.known_columns).to include("objectnumber")
Expand All @@ -58,7 +58,7 @@
end

describe "#<<" do
let(:mapper) { "core_7-1-0_collectionobject" }
let(:mapper) { "core_7-2-0_collectionobject" }

let(:added_field) do
{
Expand All @@ -80,7 +80,7 @@
end

describe "#lookup" do
let(:mapper) { "core_7-1-0_collectionobject" }
let(:mapper) { "core_7-2-0_collectionobject" }

it "returns ColumnMapping for column name" do
result = mappings.lookup("numberType").fieldname
Expand Down
12 changes: 11 additions & 1 deletion spec/collectionspace/mapper/data_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
vcr: "core_domain_check" do
let(:profile) { "core" }
context "with collectionobject" do
let(:mapper) { "core_6-1-0_collectionobject" }
let(:mapper) { "core_7-2-0_collectionobject" }

context "overflow subgroup record with uneven subgroup values" do
# skip: "subgroup complications" do
Expand All @@ -78,6 +78,16 @@
it_behaves_like "Mapped"
end

# Tests repeating field value within repeatable field group
context "with rights in field group" do
let(:datahash_path) do
"spec/support/datahashes/core/collectionobject6.json"
end
let(:fixture_path) { "core/collectionobject6.xml" }

it_behaves_like "Mapped"
end

context "overflow subgroup record with even subgroup values" do
let(:datahash_path) do
"spec/support/datahashes/core/collectionobject3.json"
Expand Down
2 changes: 2 additions & 0 deletions spec/refnames.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ def cacheable_refnames(domain)
"urn:cspace:DOMAIN:vocabularies:name(publishto):item:name(none)'None'"],
["vocabularies", "publishto", "Omeka",
"urn:cspace:DOMAIN:vocabularies:name(publishto):item:name(omeka)'Omeka'"],
["vocabularies", "rightsinrestriction", "Don't release owner data to third parties",
"urn:cspace:DOMAIN:vocabularies:name(rightsinrestriction):item:name(dnr)'Don't release owner data to third parties'"],
["vocabularies", "scarstrat", "boiling water",
"urn:cspace:DOMAIN:vocabularies:name(scarstrat):item:name(boilingwater)'boiling water'"],
["vocabularies", "scarstrat", "cold strat",
Expand Down
54 changes: 54 additions & 0 deletions spec/support/cassettes/core_domain_check.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions spec/support/cassettes/vocab_publishto_All.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/support/datahashes/core/collectionobject2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"measuredPart": "unframed",
"dimensionSummary": "8.5 x 11",
"dimension": "height| width",
"measuredByOrganization": "Organization 1",
"measuredByOrganizationLocal": "Organization 1",
"value": "8.5| 11",
"measurementUnit": "inches"
}
7 changes: 7 additions & 0 deletions spec/support/datahashes/core/collectionobject6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"objectNumber": "TEST6",
"rightinrestriction": "Don't release owner data to third parties",
"agreementsigned": "2013-03-08",
"agreementreceived": "2013-03-09",
"rightinnote": "Note text here"
}
Loading

0 comments on commit 97a5000

Please sign in to comment.