Sha256: a5c3cbacac743c3bfe26b784e9165bebb33866fca35635b9a5ad67524b643ac3

Contents?: true

Size: 1.96 KB

Versions: 6

Compression:

Stored size: 1.96 KB

Contents

require "active-fedora"
class DcDocument < ActiveFedora::Base
  include ::ActiveFedora::Finders
  include ::ActiveFedora::DatastreamCollections
  include ::ActiveFedora::Relationships
  include Hydra::ModelMethods
  include Cul::Scv::Hydra::ActiveFedora::Model::Common
  alias :file_objects :resources
  
  has_relationship "parts", :cul_member_of, :inbound => true

  def self.load_instance_from_solr(pid,solr_doc=nil)
    if solr_doc.nil?
      result = find_by_solr(pid)
      raise "Object #{pid} not found in solr" if result.nil?
      solr_doc = result.hits.first
      #double check pid and id in record match
      raise "Object #{pid} not found in Solr" unless !result.nil? && !solr_doc.nil? && pid == solr_doc[SOLR_DOCUMENT_ID]
    else
      raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
    end
     
    create_date = solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date).to_s] : solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date)]
    modified_date = solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[::ActiveFedora::SolrService.solr_name(:system_modified, :date).to_s] : solr_doc[::ActiveFedora::SolrService.solr_name(:system_modified, :date)]
    obj = DcDocument.new({:pid=>solr_doc[SOLR_DOCUMENT_ID],:create_date=>create_date,:modified_date=>modified_date})
    obj.new_object = false
      #set by default to load any dependent relationship objects from solr as well
    obj.load_from_solr = true
      #need to call rels_ext once so it exists when iterating over datastreams
    obj.rels_ext
    obj.datastreams.each_value do |ds|
      if ds.respond_to?(:from_solr)
        ds.from_solr(solr_doc) if ds.kind_of?(::ActiveFedora::MetadataDatastream) || ds.kind_of?(::ActiveFedora::NokogiriDatastream) || ( ds.kind_of?(::ActiveFedora::RelsExtDatastream))
      end
    end
    obj
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cul_scv_hydra-0.7.0 app/models/dcdocument.rb
cul_scv_hydra-0.6.4 app/models/dcdocument.rb
cul_scv_hydra-0.6.3 app/models/dcdocument.rb
cul_scv_hydra-0.6.2 app/models/dcdocument.rb
cul_scv_hydra-0.6.1 app/models/dcdocument.rb
cul_scv_hydra-0.6.0 app/models/dcdocument.rb