From d143e122d9dada82024cd79db6fdcc377dd25fb4 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Fri, 2 Feb 2024 19:21:57 -0500 Subject: [PATCH] Include termdisplayname in authority date details CSXML --- .../mapper/date_details/data_prepper.rb | 32 +++++++++-- .../mapper/date_details/handler.rb | 12 +++- .../mapper/handler_full_record.rb | 4 +- .../core_datedetail_check_fields.yml | 56 +++++++++++++++++++ ...ate_detail_datahandler_process_and_map.yml | 56 +++++++++++++++++++ .../citation_publicationdate_1.xml | 7 ++- .../citation_publicationdate_2.xml | 5 ++ 7 files changed, 163 insertions(+), 9 deletions(-) diff --git a/lib/collectionspace/mapper/date_details/data_prepper.rb b/lib/collectionspace/mapper/date_details/data_prepper.rb index 0800a391..df30d6a8 100644 --- a/lib/collectionspace/mapper/date_details/data_prepper.rb +++ b/lib/collectionspace/mapper/date_details/data_prepper.rb @@ -18,6 +18,7 @@ def initialize(data, handler) CollectionSpace::Mapper.structured_date_detailed_fields .map { |field| [field.downcase, field] } .to_h + @authority_data = nil @grouped_data = nil end @@ -25,6 +26,11 @@ def prep unless handler.grouped_fields handler.check_fields(response.merged_data) end + if handler.authority_handler + extract_authority_data + auth_prepped = handler.authority_handler + .prep(authority_data) + end if handler.grouped_handler extract_grouped_data grouped_prepped = handler.grouped_handler.prep(grouped_data) @@ -36,6 +42,7 @@ def prep clean_transformed readd_id combine_data_fields + merge_authority_data(auth_prepped) if authority_data merge_grouped_data(grouped_prepped) if grouped_data response end @@ -43,7 +50,7 @@ def prep private attr_reader :id_field, :target, :target_mapping, :date_fields, - :date_field_lookup, :grouped_data + :date_field_lookup, :grouped_data, :authority_data def date_data @date_data ||= response.merged_data @@ -55,17 +62,22 @@ def non_date_data .reject { |field, _value| date_fields.any?(field) } end + def extract_authority_data + @authority_data = {} + copy_id_field_to(authority_data) + end + def extract_grouped_data @grouped_data = {} - copy_id_field_to_grouped_data + copy_id_field_to(grouped_data) move_grouped_fields_to_grouped_data end - def copy_id_field_to_grouped_data + def copy_id_field_to(data_var) if response.merged_data.key?(id_field) - grouped_data[id_field] = response.merged_data[id_field] + data_var[id_field] = response.merged_data[id_field] elsif response.merged_data.key?("termdisplayname") - grouped_data["termdisplayname"] = + data_var["termdisplayname"] = response.merged_data["termdisplayname"] end end @@ -184,6 +196,16 @@ def authority_short_id ) end + def merge_authority_data(auth_prepped) + added_paths = auth_prepped.xpaths + .reject { |path, xpath| response.xpaths.key?(path) } + + added_paths.each do |path, xpath| + response.xpaths[path] = xpath + response.combined_data[path] = auth_prepped.combined_data[path] + end + end + def merge_grouped_data(grouped_prepped) path = handler.target_path diff --git a/lib/collectionspace/mapper/date_details/handler.rb b/lib/collectionspace/mapper/date_details/handler.rb index cb7a1528..f59b2077 100644 --- a/lib/collectionspace/mapper/date_details/handler.rb +++ b/lib/collectionspace/mapper/date_details/handler.rb @@ -4,7 +4,8 @@ module CollectionSpace module Mapper module DateDetails class Handler < CollectionSpace::Mapper::HandlerFullRecord - attr_reader :grouped_handler, :grouped_fields, :target_path + attr_reader :authority_handler, :grouped_handler, :grouped_fields, + :target_path def check_fields(data) initial = super(data) @@ -40,6 +41,15 @@ def pre_initialize(context) @target_path = nil end + def post_initialize(context) + return unless record.service_type == "authority" + + @authority_handler = CollectionSpace::Mapper::HandlerFullRecord.new( + record_mapper: record_mapper, client: client, cache: termcache, + csid_cache: csidcache + ) + end + def get_prepper_class CollectionSpace::Mapper::DateDetails::DataPrepper end diff --git a/lib/collectionspace/mapper/handler_full_record.rb b/lib/collectionspace/mapper/handler_full_record.rb index d357a96b..c21129d2 100644 --- a/lib/collectionspace/mapper/handler_full_record.rb +++ b/lib/collectionspace/mapper/handler_full_record.rb @@ -131,7 +131,7 @@ def initialize(record_mapper:, client:, cache:, csid_cache:, config: {}) self.config.status_checker = CollectionSpace::Mapper::Tools::RecordStatusServiceBuilder.call(self) - post_initialize + post_initialize(binding) end def add_error(error) @@ -230,7 +230,7 @@ def get_data_validator CollectionSpace::Mapper::DataValidator.new(self) end - def post_initialize + def post_initialize(context) # Defined in subclasses end diff --git a/spec/support/cassettes/core_datedetail_check_fields.yml b/spec/support/cassettes/core_datedetail_check_fields.yml index 95fa057d..ba899e44 100644 --- a/spec/support/cassettes/core_datedetail_check_fields.yml +++ b/spec/support/cassettes/core_datedetail_check_fields.yml @@ -112,4 +112,60 @@ http_interactions: Persons'2023-08-26T02:44:37.565Zproject3personLocal PersonsPersonAuthority recorded_at: Fri, 02 Feb 2024 19:58:07 GMT +- request: + method: get + uri: https://core.dev.collectionspace.org/cspace-services/personauthorities?pgNum=0&pgSz=1&wf_deleted=false + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Authorization: + - Basic YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I= + response: + status: + code: 200 + message: '' + headers: + Date: + - Sat, 03 Feb 2024 00:12:48 GMT + Content-Type: + - application/xml + Content-Length: + - '804' + Connection: + - keep-alive + Vary: + - Access-Control-Request-Headers + - Access-Control-Request-Method + - Origin + Set-Cookie: + - JSESSIONID=FF38AA20D3594DAD241CFCD88D4DDDC0; Path=/cspace-services; Secure; + HttpOnly + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - 1; mode=block + Cache-Control: + - no-cache, no-store, max-age=0, must-revalidate + Pragma: + - no-cache + Expires: + - '0' + Strict-Transport-Security: + - max-age=31536000 ; includeSubDomains + X-Frame-Options: + - DENY + body: + encoding: UTF-8 + string: 0112csid|uri|refName|updatedAt|workflowState|rev|shortIdentifier|sas|displayName|vocabType4bea28cb-83be-4ca1-971b/personauthorities/4bea28cb-83be-4ca1-971burn:cspace:core.collectionspace.org:personauthorities:name(person)'Local + Persons'2023-08-26T02:44:37.565Zproject3personLocal + PersonsPersonAuthority + recorded_at: Sat, 03 Feb 2024 00:12:48 GMT recorded_with: VCR 6.1.0 diff --git a/spec/support/cassettes/date_detail_datahandler_process_and_map.yml b/spec/support/cassettes/date_detail_datahandler_process_and_map.yml index 6408cfc0..4975c216 100644 --- a/spec/support/cassettes/date_detail_datahandler_process_and_map.yml +++ b/spec/support/cassettes/date_detail_datahandler_process_and_map.yml @@ -166,4 +166,60 @@ http_interactions: string: 02500csid|uri|refName|updatedAt|workflowState|rev|shortIdentifier|sas|proposed|deprecated|termStatus|termDisplayName recorded_at: Fri, 02 Feb 2024 19:56:48 GMT +- request: + method: get + uri: https://core.dev.collectionspace.org/cspace-services/personauthorities?pgNum=0&pgSz=1&wf_deleted=false + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Authorization: + - Basic YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I= + response: + status: + code: 200 + message: '' + headers: + Date: + - Sat, 03 Feb 2024 00:12:47 GMT + Content-Type: + - application/xml + Content-Length: + - '804' + Connection: + - keep-alive + Vary: + - Access-Control-Request-Headers + - Access-Control-Request-Method + - Origin + Set-Cookie: + - JSESSIONID=C7CA503A48807439A8055847CCCEB1F0; Path=/cspace-services; Secure; + HttpOnly + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - 1; mode=block + Cache-Control: + - no-cache, no-store, max-age=0, must-revalidate + Pragma: + - no-cache + Expires: + - '0' + Strict-Transport-Security: + - max-age=31536000 ; includeSubDomains + X-Frame-Options: + - DENY + body: + encoding: UTF-8 + string: 0112csid|uri|refName|updatedAt|workflowState|rev|shortIdentifier|sas|displayName|vocabType4bea28cb-83be-4ca1-971b/personauthorities/4bea28cb-83be-4ca1-971burn:cspace:core.collectionspace.org:personauthorities:name(person)'Local + Persons'2023-08-26T02:44:37.565Zproject3personLocal + PersonsPersonAuthority + recorded_at: Sat, 03 Feb 2024 00:12:47 GMT recorded_with: VCR 6.1.0 diff --git a/spec/support/xml/date_details/citation_publicationdate_1.xml b/spec/support/xml/date_details/citation_publicationdate_1.xml index 2f7df758..5561cbf2 100644 --- a/spec/support/xml/date_details/citation_publicationdate_1.xml +++ b/spec/support/xml/date_details/citation_publicationdate_1.xml @@ -12,7 +12,12 @@ 0 - + + + Foo + + + diff --git a/spec/support/xml/date_details/citation_publicationdate_2.xml b/spec/support/xml/date_details/citation_publicationdate_2.xml index 2491b58d..6db1a897 100644 --- a/spec/support/xml/date_details/citation_publicationdate_2.xml +++ b/spec/support/xml/date_details/citation_publicationdate_2.xml @@ -14,6 +14,11 @@ 1 + + + Foo + +