Class: ActiveFedora::SolrDigitalObject

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
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.



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

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
  self.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

#fetch(field, default = []) ⇒ Object

Raises:

  • (KeyError)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_fedora/solr_digital_object.rb', line 46

def fetch(field, default=[])
  attribute = original_class.defined_attributes[field]
  field_name = attribute.primary_solr_name
  raise KeyError, "Tried to fetch `#{field}' from solr, but it isn't indexed." unless field_name
  val = solr_doc.fetch field_name, default
  case attribute.type
  when :date
    val.is_a?(Array) ? val.map{|v| Date.parse v} : Date.parse(val)
  else
    val
  end
end

#freezeObject



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

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_record?Boolean Also known as: new?

Returns:

  • (Boolean)


59
60
61
# File 'lib/active_fedora/solr_digital_object.rb', line 59

def new_record?
  false
end

#uriObject



65
66
67
# File 'lib/active_fedora/solr_digital_object.rb', line 65

def uri
  "solr:#{pid}"
end