Skip to content

Commit

Permalink
Include termdisplayname in authority date details CSXML
Browse files Browse the repository at this point in the history
  • Loading branch information
kspurgin committed Feb 3, 2024
1 parent ea35f05 commit d143e12
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 9 deletions.
32 changes: 27 additions & 5 deletions lib/collectionspace/mapper/date_details/data_prepper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ def initialize(data, handler)
CollectionSpace::Mapper.structured_date_detailed_fields
.map { |field| [field.downcase, field] }
.to_h
@authority_data = nil
@grouped_data = nil
end

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)
Expand All @@ -36,14 +42,15 @@ 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

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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion lib/collectionspace/mapper/date_details/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/handler_full_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
56 changes: 56 additions & 0 deletions spec/support/cassettes/core_datedetail_check_fields.yml

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

56 changes: 56 additions & 0 deletions spec/support/cassettes/date_detail_datahandler_process_and_map.yml

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

7 changes: 6 additions & 1 deletion spec/support/xml/date_details/citation_publicationdate_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
</ns2:collectionspace_core>
<ns2:citations_common xmlns:ns2="http://collectionspace.org/services/citation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rev>0</rev>
<citationResourceIdentGroupList>
<citationTermGroupList>
<citationTermGroup>
<termDisplayName>Foo</termDisplayName>
</citationTermGroup>
</citationTermGroupList>
<citationResourceIdentGroupList>
<citationResourceIdentGroup>
<resourceIdent/>
<captureDate>
Expand Down
5 changes: 5 additions & 0 deletions spec/support/xml/date_details/citation_publicationdate_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<ns2:citations_common xmlns:ns2="http://collectionspace.org/services/citation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rev>1</rev>
<citationTermGroupList>
<citationTermGroup>
<termDisplayName>Foo</termDisplayName>
</citationTermGroup>
</citationTermGroupList>
<citationResourceIdentGroupList>
<citationResourceIdentGroup>
<resourceIdent/>
Expand Down

0 comments on commit d143e12

Please sign in to comment.