Sha256: e62619518f5aa1ae22e68d03531fe568e7bd891648ce19226fe3104f9694d772

Contents?: true

Size: 1.07 KB

Versions: 33

Compression:

Stored size: 1.07 KB

Contents

module ActiveFedora
  class FixtureLoader
    attr_accessor :path

    def initialize(path)
      self.path = path
    end 

    def filename_for_pid(pid)
      File.join(path, "#{pid.gsub(":","_")}.foxml.xml")
    end

    def self.delete(pid)
      begin
        ActiveFedora::Base.load_instance(pid).delete
        1
      rescue ActiveFedora::ObjectNotFoundError
        logger.debug "The object #{pid} has already been deleted (or was never created)."
        0
      end
    end

    def reload(pid)
      self.class.delete(pid)
      import_and_index(pid)
    end

    def import_and_index(pid)
      body = self.class.import_to_fedora(filename_for_pid(pid))
      self.class.index(pid)
      body
    end

    def self.index(pid)
        solrizer = Solrizer::Fedora::Solrizer.new 
        solrizer.solrize(pid) 
    end

    def self.import_to_fedora(filename)
      file = File.new(filename, "r")
      result = ActiveFedora::RubydoraConnection.instance.connection.ingest(:file=>file.read)
      raise "Failed to ingest the fixture." unless result
      result.body
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
active-fedora-3.3.2 lib/active_fedora/fixture_loader.rb
active-fedora-3.3.1 lib/active_fedora/fixture_loader.rb
active-fedora-3.3.0 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.2 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.6 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0.pre7 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0.pre6 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0.pre5 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0.pre4 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0.pre3 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0.pre2 lib/active_fedora/fixture_loader.rb
active-fedora-3.2.0.pre1 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.5 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.4 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.3 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.2 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.1 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.0 lib/active_fedora/fixture_loader.rb
active-fedora-3.1.0.rc4 lib/active_fedora/fixture_loader.rb