Sha256: 33ad54978a51b1c656750b43fd3fe8d6043667f84bf655548d945f21ca17ceed

Contents?: true

Size: 1.53 KB

Versions: 36

Compression:

Stored size: 1.53 KB

Contents

module ActiveFedora
  class SolrDigitalObject
    include DigitalObject::DatastreamBootstrap
    attr_reader :pid, :label, :state, :ownerId, :profile, :datastreams, :solr_doc
    attr_accessor :original_class
    def initialize(solr_doc, profile_hash, klass=ActiveFedora::Base)
      @solr_doc = solr_doc
      @pid = solr_doc[SOLR_DOCUMENT_ID]
      @profile = {}
      profile_hash.each_pair { |key,value| @profile[key] = value.to_s if key =~ /^obj/ }
      @profile['objCreateDate'] ||= Time.now.xmlschema
      @profile['objLastModDate'] ||= @profile['objCreateDate']

      @datastreams = {}
      
      dsids = profile_hash['datastreams'].keys
      original_class = klass
      missing = dsids - klass.ds_specs.keys
      missing.each do |dsid|
        #Initialize the datastreams that are in the solr document, but not found in the classes spec.
        mime_type = profile_hash['datastreams'][dsid]['dsMIME']
        ds_class = mime_type =~ /[\/\+]xml$/ ? OmDatastream : Datastream
        @datastreams[dsid] = ds_class.new(self, dsid)
      end

      @label = @profile['objLabel']
      @state = @profile['objState']
      @ownerId = @profile['objOwnerId']
    end
    
    def freeze
      @finished = true
      @profile.freeze
      @datastreams.freeze
      class << self
        #Once this instance is frozen create a repository method just for this one instance.
        define_method :repository do
          ActiveFedora::Base.connection_for_pid(self.pid)
        end
      end
      self
    end
    
    def new?
      false
    end

  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
active-fedora-5.7.1 lib/active_fedora/solr_digital_object.rb
active-fedora-5.7.0 lib/active_fedora/solr_digital_object.rb
active-fedora-6.2.0 lib/active_fedora/solr_digital_object.rb
active-fedora-6.1.1 lib/active_fedora/solr_digital_object.rb
active-fedora-6.1.0 lib/active_fedora/solr_digital_object.rb
active-fedora-5.6.3 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.rc7 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.rc6 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.rc5 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.rc4 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.rc3 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.rc2 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.rc1 lib/active_fedora/solr_digital_object.rb
active-fedora-5.6.2 lib/active_fedora/solr_digital_object.rb
active-fedora-5.6.1 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.pre10 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.pre9 lib/active_fedora/solr_digital_object.rb
active-fedora-5.6.0 lib/active_fedora/solr_digital_object.rb
active-fedora-6.0.0.pre8 lib/active_fedora/solr_digital_object.rb