Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'active-fedora'
require 'json'
def descendant_uris(uri)
begin
resource = Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, uri)
rescue
STDERR.puts "Failed to create resource for uri #{uri}"
return []
end
begin
return [] unless resource.head.rdf_source?
rescue => e
STDERR.puts "Error trying to call resource.head.rdf_source? on #{uri}"
return []
end
begin
duris = resource.graph.query(predicate: ::RDF::Vocab::LDP.contains)
rescue
STDERR.puts "Couldn't get resource.graph.query for #{uri}"
return []
end
duris = duris.map do |descendant|
begin
descendant.object.to_s
rescue
STDERR.puts "Can't call .object.to_s on #{descendant}"
end
end
duris.inject([uri]) {|acc, d| acc.concat(descendant_uris(d))}
end
def reindex_uris(uris)
uris.each do |uri|
begin
ActiveFedora::Base.find(ActiveFedora::Base.uri_to_id(uri)).update_index
rescue => e
STDERR.puts "Trouble reindexing #{uri}: #{e}"
end
end
end
duris = descendant_uris(ActiveFedora::Base.id_to_uri(''))
File.open('decendant_urls.json', 'w:utf-8') do |f|
f.puts duris.to_json
end
duris.shift # take out root
reindex_uris(duris)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment