Skip to content

Instantly share code, notes, and snippets.

@awead
Last active February 8, 2019 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awead/b4092b971adb773b3c2f09f2e1c412e6 to your computer and use it in GitHub Desktop.
Save awead/b4092b971adb773b3c2f09f2e1c412e6 to your computer and use it in GitHub Desktop.
PBCore xml export
def save_xml_file(id)
av = ArchivalVideo.find(id)
av.summary = av.abstract if av.summary == [""]
xml = av.to_pbcore_xml
license = Array.wrap(av.license).first
if license.present?
prs = Nokogiri::XML::Node.new("pbcoreRightsSummary", xml)
xml.at("/xmlns:pbcoreDescriptionDocument").add_child(prs)
rs = Nokogiri::XML::Node.new("rightsSummary", xml)
rs.content = license
xml.at("/xmlns:pbcoreDescriptionDocument/xmlns:pbcoreRightsSummary").add_child(rs)
end
File.write("#{id.gsub(/:/, "_")}.xml", xml.to_s)
rescue StandardError => exception
File.write("#{id.gsub(/:/, "_")}_failed.txt", exception.to_s)
end
results = ActiveFedora::SolrService.query("active_fedora_model_ssi:ArchivalVideo", fl: ["id"], rows: 1000000)
ids = results.map { |result| result["id"] }
ids.map { |id| save_xml_file(id) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment