Sha256: a49254c1cb9978c08497d30fb24cf23a2f7c22ebf2dbe0c35be8e98e98d90707

Contents?: true

Size: 1.26 KB

Versions: 22

Compression:

Stored size: 1.26 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.find(pid, cast: true).delete
        1
      rescue ActiveFedora::ObjectNotFoundError
        ActiveFedora::Base.logger.debug "The object #{pid} has already been deleted (or was never created)." if ActiveFedora::Base.logger
        0
      rescue Errno::ECONNREFUSED => e
        ActiveFedora::Base.logger.debug "Can't connect to Fedora! Are you sure jetty is running?" if ActiveFedora::Base.logger
       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), pid)
      self.class.index(pid)
      body
    end

    def self.index(pid)
      ActiveFedora::Base.find(pid).update_index
    end

    def self.import_to_fedora(filename, pid='0')
      file = File.new(filename, "r")
      result = ActiveFedora::Base.connection_for_pid(pid).ingest(:file=>file.read)
      raise "Failed to ingest the fixture." unless result
      result.body
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
active-fedora-8.7.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.6.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.5.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.4.2 lib/active_fedora/fixture_loader.rb
active-fedora-8.4.1 lib/active_fedora/fixture_loader.rb
active-fedora-7.3.1 lib/active_fedora/fixture_loader.rb
active-fedora-7.3.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.4.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.3.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.2.2 lib/active_fedora/fixture_loader.rb
active-fedora-8.2.1 lib/active_fedora/fixture_loader.rb
active-fedora-8.2.0 lib/active_fedora/fixture_loader.rb
active-fedora-7.2.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.1.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.0.1 lib/active_fedora/fixture_loader.rb
active-fedora-8.0.0 lib/active_fedora/fixture_loader.rb
active-fedora-8.0.0.rc3 lib/active_fedora/fixture_loader.rb
active-fedora-8.0.0.rc2 lib/active_fedora/fixture_loader.rb
active-fedora-8.0.0.rc1 lib/active_fedora/fixture_loader.rb
active-fedora-7.1.2 lib/active_fedora/fixture_loader.rb