Class: ActiveFedora::SolrDigitalObject

Inherits:
Object
  • Object
show all
Includes:
DigitalObject::DatastreamBootstrap
Defined in:
lib/active_fedora/solr_digital_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DigitalObject::DatastreamBootstrap

#datastream_object_for

Constructor Details

#initialize(solr_doc, profile_hash, klass = ActiveFedora::Base) ⇒ SolrDigitalObject

Returns a new instance of SolrDigitalObject.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_fedora/solr_digital_object.rb', line 9

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

Instance Attribute Details

#datastreamsObject (readonly)

Returns the value of attribute datastreams.



6
7
8
# File 'lib/active_fedora/solr_digital_object.rb', line 6

def datastreams
  @datastreams
end

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'lib/active_fedora/solr_digital_object.rb', line 6

def label
  @label
end

#original_classObject

Returns the value of attribute original_class.



7
8
9
# File 'lib/active_fedora/solr_digital_object.rb', line 7

def original_class
  @original_class
end

#ownerIdObject (readonly)

Returns the value of attribute ownerId.



6
7
8
# File 'lib/active_fedora/solr_digital_object.rb', line 6

def ownerId
  @ownerId
end

#pidObject (readonly)

Returns the value of attribute pid.



6
7
8
# File 'lib/active_fedora/solr_digital_object.rb', line 6

def pid
  @pid
end

#profileObject (readonly)

Returns the value of attribute profile.



6
7
8
# File 'lib/active_fedora/solr_digital_object.rb', line 6

def profile
  @profile
end

#solr_docObject (readonly)

Returns the value of attribute solr_doc.



6
7
8
# File 'lib/active_fedora/solr_digital_object.rb', line 6

def solr_doc
  @solr_doc
end

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/active_fedora/solr_digital_object.rb', line 6

def state
  @state
end

Instance Method Details

#freezeObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_fedora/solr_digital_object.rb', line 34

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

#new?Boolean Also known as: new_record?

Returns:

  • (Boolean)


47
48
49
# File 'lib/active_fedora/solr_digital_object.rb', line 47

def new?
  false
end

#uriObject



52
53
54
# File 'lib/active_fedora/solr_digital_object.rb', line 52

def uri
  "solr:#{pid}"
end