Sha256: b7f68e9b0cd073570e27c179c1497d4daadfbe6adfb71b6f9bc70778c47f4b19

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 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
        logger.debug "The object #{pid} has already been deleted (or was never created)."
        0
      rescue Errno::ECONNREFUSED => e
        logger.debug "Can't connect to Fedora! Are you sure jetty is running?"
       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

11 entries across 11 versions & 1 rubygems

Version Path
active-fedora-7.0.4 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.3 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.2 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.1 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.0 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.0.rc3 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.0.rc2 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.0.rc1 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.0.pre3 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.0.pre2 lib/active_fedora/fixture_loader.rb
active-fedora-7.0.0.pre1 lib/active_fedora/fixture_loader.rb