Last active
February 8, 2019 06:26
-
-
Save awead/b4092b971adb773b3c2f09f2e1c412e6 to your computer and use it in GitHub Desktop.
PBCore xml export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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