Skip to content

Commit

Permalink
Replace daogrp handling with arc-aware version
Browse files Browse the repository at this point in the history
Fixes #530

In <daogrp>s, xlink:actuate and xlink:show attributes related to the
<daoloc> can be (must be, according to standard) located on <arc>
elements within the <daogrp>, connected via:

  arc#xlink:to -> daoloc#xlink:label

They're at the same level of nesting and have no ordering guarantees, so
this code stops at the <daogrp>, constructs a fragment from its inner_xml,
and processes the whole <daogrp> at once.

This commit also includes a partial improvement to title handling, in
that it looks for an explicit title on the <daogrp>
  • Loading branch information
pobocks authored and marktriggs committed Nov 9, 2016
1 parent e673139 commit 21c10bf
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions backend/app/converters/ead_converter.rb
Expand Up @@ -783,30 +783,51 @@ def make_nested_note(note_name, tag)

with 'daogrp' do
title = ''
ancestor(:resource, :archival_object ) { |ao| title << ao.title + ' Digital Object' }

unless title = att('title')
ancestor(:resource, :archival_object ) { |ao| title << ao.title + ' Digital Object' }
end

make :digital_object, {
:digital_object_id => SecureRandom.uuid,
:title => title,
} do |obj|
ancestor(:resource, :archival_object) do |ao|
ao.instances.push({'instance_type' => 'digital_object', 'digital_object' => {'ref' => obj.uri}})
end
end
end

end
# Actuate and Show values applicable to <daoloc>s can come from <arc> elements,
# so daogrp contents need to be handled together
dg_contents = Nokogiri::XML::DocumentFragment.parse(inner_xml)

# Hashify arc attrs keyed by xlink:to
arc_by_to_val = dg_contents.xpath('arc').map {|arc|
if arc['xlink:to']
[arc['xlink:to'], arc]
else
nil
end
}.reject(&:nil?).reduce({}) {|hsh, (k, v)| hsh[k] = v;hsh}

with 'daoloc' do
ancestor(:digital_object) do |dobj|
dobj.file_versions << {
:file_uri => att('href'),
:xlink_show_attribute => att('show'),
:file_format_name => att('role')
}
end
end

dg_contents.xpath('daoloc').each do |daoloc|
arc = arc_by_to_val[daoloc['xlink:label']] || {}

fv_attrs = {}

# attrs on <arc>
fv_attrs[:xlink_show_attribute] = arc['xlink:show'] if arc['xlink:show']
fv_attrs[:xlink_actuate_attribute] = arc['xlink:actuate'] if arc['xlink:actuate']

# attrs on <daoloc>
fv_attrs[:file_uri] = daoloc['xlink:href'] if daoloc['xlink:href']
fv_attrs[:use_statement] = daoloc['xlink:role'] if daoloc['xlink:role']

obj.file_versions << fv_attrs
end
obj
end
end
end


Expand Down

0 comments on commit 21c10bf

Please sign in to comment.