From 67b4f331df7c6649556ec50c3a1ad08773c8ab10 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Thu, 1 Feb 2024 16:19:56 -0500 Subject: [PATCH 1/3] Add shortid when processing date details for authorities --- lib/collectionspace/mapper/data_mapper.rb | 25 ++++++++++++------- .../mapper/date_details/data_prepper.rb | 14 ++++++++++- .../mapper/date_details/handler.rb | 6 ++++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/collectionspace/mapper/data_mapper.rb b/lib/collectionspace/mapper/data_mapper.rb index e6bda1b7..d8629fe2 100644 --- a/lib/collectionspace/mapper/data_mapper.rb +++ b/lib/collectionspace/mapper/data_mapper.rb @@ -15,9 +15,6 @@ def initialize(response, handler) @doc = handler.record.xml_template.dup response.xpaths.values.each { |xpath| map(xpath) } - if handler.record.service_type == "authority" - add_short_id - end set_identifier_value clean_doc add_namespaces @@ -29,8 +26,11 @@ def initialize(response, handler) attr_reader :response, :handler, :doc def set_identifier_value - if handler.record.service_type == "relation" + case handler.record.service_type + when "relation" set_relation_id + when "authority" + add_short_id else id_field = handler.record.identifier_field mapping = handler.record.mappings.find do |mapper| @@ -53,15 +53,22 @@ def set_relation_id end def add_short_id - term = response.transformed_data["termdisplayname"][0] ns = handler.record.common_namespace targetnode = doc.xpath("/document/#{ns}").first child = Nokogiri::XML::Node.new("shortIdentifier", doc) - child.content = - CollectionSpace::Mapper::Identifiers::AuthorityShortIdentifier.call( - term - ) + + shortid = + if response.transformed_data.key?("shortidentifier") + response.transformed_data["shortidentifier"] + else + term = response.split_data["termdisplayname"][0] + CollectionSpace::Mapper::Identifiers::AuthorityShortIdentifier.call( + term + ) + end + child.content = shortid targetnode.add_child(child) + response.add_identifier(shortid) end def map(xpath) diff --git a/lib/collectionspace/mapper/date_details/data_prepper.rb b/lib/collectionspace/mapper/date_details/data_prepper.rb index 8cf33bdd..8d30ac13 100644 --- a/lib/collectionspace/mapper/date_details/data_prepper.rb +++ b/lib/collectionspace/mapper/date_details/data_prepper.rb @@ -137,8 +137,20 @@ def clean_transformed end def readd_id - response.transformed_data[id_field] = + id = case id_field + when "shortidentifier" + readd_authority_id + else response.split_data[id_field] + end + response.transformed_data[id_field] = id + end + + def readd_authority_id + term = response.split_data["termdisplayname"][0] + CollectionSpace::Mapper::Identifiers::AuthorityShortIdentifier.call( + term + ) end end end diff --git a/lib/collectionspace/mapper/date_details/handler.rb b/lib/collectionspace/mapper/date_details/handler.rb index 7af24815..8390f3b2 100644 --- a/lib/collectionspace/mapper/date_details/handler.rb +++ b/lib/collectionspace/mapper/date_details/handler.rb @@ -22,12 +22,16 @@ def get_date_handler end def known_fields - [ + base = [ record.identifier_field, "date_field_group", CollectionSpace::Mapper.structured_date_detailed_fields ].flatten .map(&:downcase) + return base unless record.service_type == "authority" + + base << "termdisplayname" + base end end end From bdb0b06bedfea793e6448886b6608a58d7c85f6a Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Thu, 1 Feb 2024 16:20:23 -0500 Subject: [PATCH 2/3] noblame: Whitespace and/or formatting changes only --- lib/collectionspace/mapper/data_mapper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/collectionspace/mapper/data_mapper.rb b/lib/collectionspace/mapper/data_mapper.rb index d8629fe2..96738e30 100644 --- a/lib/collectionspace/mapper/data_mapper.rb +++ b/lib/collectionspace/mapper/data_mapper.rb @@ -140,9 +140,9 @@ def simple_map(xpath, parent, thisdata) xpath.mappings.group_by { |mapping| mapping.fieldname } .keys .each do |fieldname| - data = thisdata.fetch(fieldname, nil) - populate_simple_field_data(fieldname, data, parent) if data - end + data = thisdata.fetch(fieldname, nil) + populate_simple_field_data(fieldname, data, parent) if data + end end def populate_simple_field_data(field_name, data, parent) From 4a559e39af9f9d71c4c5a986e1e80c2b56f5dd41 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Thu, 1 Feb 2024 16:22:28 -0500 Subject: [PATCH 3/3] Bump version; update changelog --- CHANGELOG.md | 3 +++ Gemfile.lock | 2 +- lib/collectionspace/mapper/version.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09d60983..1ecb2c07 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 +## [5.0.4] - 2024-02-01 +- Ensure `shortid` field is populated when mapping date details for authorities + ## [5.0.3] - 2024-01-26 - Add `null_value_string_handling` batch configuration option, with ability to switch to creating empty string nodes, rather than deleting nodes. diff --git a/Gemfile.lock b/Gemfile.lock index e8f36e9e..f99f5a45 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,7 +12,7 @@ GIT PATH remote: . specs: - collectionspace-mapper (5.0.3) + collectionspace-mapper (5.0.4) activesupport (= 7.0.4.3) chronic collectionspace-client (~> 0.15.0) diff --git a/lib/collectionspace/mapper/version.rb b/lib/collectionspace/mapper/version.rb index eddc4d15..43418bbe 100644 --- a/lib/collectionspace/mapper/version.rb +++ b/lib/collectionspace/mapper/version.rb @@ -2,6 +2,6 @@ module CollectionSpace module Mapper - VERSION = "5.0.3" + VERSION = "5.0.4" end end