Skip to content

Commit

Permalink
Merge pull request #172 from collectionspace/authority-date-load
Browse files Browse the repository at this point in the history
Authority date load
  • Loading branch information
kspurgin authored Feb 1, 2024
2 parents 8363a10 + 4a559e3 commit 48d6d43
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 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.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.

Expand Down
2 changes: 1 addition & 1 deletion 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.3)
collectionspace-mapper (5.0.4)
activesupport (= 7.0.4.3)
chronic
collectionspace-client (~> 0.15.0)
Expand Down
31 changes: 19 additions & 12 deletions lib/collectionspace/mapper/data_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -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)
Expand Down Expand Up @@ -133,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)
Expand Down
14 changes: 13 additions & 1 deletion lib/collectionspace/mapper/date_details/data_prepper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/collectionspace/mapper/date_details/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.3"
VERSION = "5.0.4"
end
end

0 comments on commit 48d6d43

Please sign in to comment.