Skip to content

Bulk Changes to Items in Sets

Ryan Wick edited this page Apr 23, 2015 · 8 revisions

Bulk changes to Oregon Digital items are possible from the Rails Console. This page is to provide examples of what's been done and help inform future cleanup work.

Change isPartOf with old URIs to localCollectionName with correct URIs for Baseball items

ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:osu-baseball")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
puts pid
bb = Image.find(:pid => pid).first || Document.find(:pid => pid).first || Audio.find(:pid => pid).first || GenericAsset.find(:pid => pid).first
next if bb.descMetadata.isPartOf.empty?

collection = bb.descMetadata.isPartOf.first.rdf_subject.to_s.gsub('http://data.library.oregonstate.edu/collection/', 'http://opaquenamespace.org/ns/localCollectionName/')
next if collection.nil?

bb.descMetadata.localCollectionName = RDF::URI(collection)
bb.descMetadata.isPartOf.clear

puts "Local Collection: #{collection}"
bb.save!
end

Add Additional Set

Used to add items in OSU Yearbooks set to OSU Historical Publications set as well.

hp = GenericCollection.find(:pid => 'oregondigital:osu-historical-publications').first

ActiveFedora::SolrService.query("desc_metadata__set_sim:#{RSolr.escape("http://oregondigital.org/resource/oregondigital:osu-yearbooks")}", :fl => "id", :rows => 100000).map{|x| x["id"]}.each do |pid|
c1 = Document.find(:pid => pid).first
c1.set << hp
c1.save!
end