Class: Shelver::Replicator
- Inherits:
-
Object
- Object
- Shelver::Replicator
- Includes:
- Stanford::SaltControllerHelper
- Defined in:
- lib/shelver/replicator.rb
Instance Attribute Summary collapse
-
#configs ⇒ Object
Returns the value of attribute configs.
-
#dest_repo ⇒ Object
Returns the value of attribute dest_repo.
Instance Method Summary collapse
-
#create_stub(source_object) ⇒ Object
Creates a stub object in @dest_repo with the datastreams that we need in the stubs.
-
#initialize ⇒ Replicator
constructor
A new instance of Replicator.
- #logger ⇒ Object
- #replicate_object(obj) ⇒ Object
- #replicate_objects ⇒ Object
Constructor Details
#initialize ⇒ Replicator
Returns a new instance of Replicator.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/shelver/replicator.rb', line 11 def initialize config_path = "#{RAILS_ROOT}/config/replicator.yml" raw_configs = YAML::load(File.open(config_path)) @configs = raw_configs[RAILS_ENV] @dest_repo = Fedora::Repository.new(configs["destination"]["fedora"]["url"]) ActiveFedora.fedora_config[:url] = configs["source"]["fedora"]["url"] logger.info("REPLICATOR: re-initializing Fedora with fedora_config: #{ActiveFedora.fedora_config.inspect}") Fedora::Repository.register(ActiveFedora.fedora_config[:url]) logger.info("REPLICATOR: re-initialized Fedora as: #{Fedora::Repository.instance.inspect}") # Register Solr ActiveFedora.solr_config[:url] = configs["source"]["solr"]["url"] logger.info("REPLICATOR: re-initializing ActiveFedora::SolrService with solr_config: #{ActiveFedora.solr_config.inspect}") ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url]) end |
Instance Attribute Details
#configs ⇒ Object
Returns the value of attribute configs.
9 10 11 |
# File 'lib/shelver/replicator.rb', line 9 def configs @configs end |
#dest_repo ⇒ Object
Returns the value of attribute dest_repo.
9 10 11 |
# File 'lib/shelver/replicator.rb', line 9 def dest_repo @dest_repo end |
Instance Method Details
#create_stub(source_object) ⇒ Object
Creates a stub object in @dest_repo with the datastreams that we need in the stubs
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/shelver/replicator.rb', line 83 def create_stub(source_object) begin jp2 = downloadables(source_object, :canonical=>true, :mime_type=>"image/jp2") jp2.new_object = true jp2.control_group = 'M' jp2.blob = jp2.content stub_object = Fedora::FedoraObject.new(:pid=>source_object.pid) dest_repo.save(stub_object) dest_repo.save(jp2) ["properties", "extProperties", "descMetadata", "location"].each do |ds_name| ds = source_object.datastreams[ds_name] ds.new_object = true ds.blob = ds.content dest_repo.save(ds) end rescue #for object without jp2s #this is a temp fix to the downloadables() issue pid = source_object.pid p "> #{pid}" jp2_file = File.new('spec/fixtures/image.jp2') ds = ActiveFedora::Datastream.new(:dsID => "image.jp2", :dsLabel => 'image.jp2', :controlGroup => 'M', :blob => jp2_file) source_object.add_datastream(ds) source_object.save # source_object = Document.load_instance(pid) source_object = ActiveFedora::Base.load_instance(pid) stub_object = Fedora::FedoraObject.new(:pid=>source_object.pid) dest_repo.save(stub_object) jp2 = downloadables(source_object, :canonical=>true, :mime_type=>"image/jp2") jp2.new_object = true jp2.control_group = 'M' jp2.blob = jp2.content stub_object = Fedora::FedoraObject.new(:pid=>source_object.pid) dest_repo.save(stub_object) dest_repo.save(jp2) ["properties", "extProperties", "descMetadata", "location"].each do |ds_name| ds = source_object.datastreams[ds_name] ds.new_object = true ds.blob = ds.content dest_repo.save(ds) end end end |
#logger ⇒ Object
138 139 140 |
# File 'lib/shelver/replicator.rb', line 138 def logger @logger ||= defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT) end |
#replicate_object(obj) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/shelver/replicator.rb', line 68 def replicate_object(obj) #source_doc = Document.load_instance(pid) obj = obj.kind_of?(ActiveFedora::Base) ? obj : Repository.get_object( obj ) p "Indexing object #{obj.pid} with label #{obj.label}" begin unless obj.nil? create_stub(obj) p "Successfully replicated #{obj.pid}" end rescue Exception => e p "unable to create stub. Failed with #{e.inspect}" end end |
#replicate_objects ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/shelver/replicator.rb', line 32 def replicate_objects # retrieve a list of all the pids in the fedora repository num_docs = 1000000 # modify this number to guarantee that all the objects are retrieved from the repository if REPLICATOR_LIST == false pids = Repository.get_pids( num_docs ) puts "Replicating #{pids.length} Fedora objects" pids.each do |pid| unless pid[0].empty? || pid[0].nil? || !pid[0].include?("druid:") puts "Processing #{pid}" replicate_object( pid ) end #unless end #pids.each else if File.exists?(REPLICATOR_LIST) arr_of_pids = FasterCSV.read(REPLICATOR_LIST, :headers=>false) puts "Replicating from list at #{REPLICATOR_LIST}" puts "Replicating #{arr_of_pids.length} Fedora objects" arr_of_pids.each do |row| pid = row[0] replicate_object( pid ) end #FASTERCSV else puts "#{REPLICATOR_LIST} does not exists!" end #if File.exists end #if Index_LISTS end |