Sha256: 4f14bbcf9050e80a95b8b63888c3914a319f1872e777588a47a9ba43fe52a3fc
Contents?: true
Size: 1.99 KB
Versions: 15
Compression:
Stored size: 1.99 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 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 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 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 = Array(solr_doc.fetch(field_name, default)) case attribute.type when :date val.map{|v| Date.parse v} else val end end def new_record? false end def uri "solr:#{pid}" end end end
Version data entries
15 entries across 15 versions & 1 rubygems