lib/ddr/models/solr_document.rb in ddr-models-3.0.0.alpha.2 vs lib/ddr/models/solr_document.rb in ddr-models-3.0.0.alpha.3

- old
+ new

@@ -1,28 +1,30 @@ require 'json' module Ddr::Models module SolrDocument extend ActiveSupport::Concern + extend Deprecation + include ObjectApi - included do - alias_method :pid, :id - end - class NotFound < Error; end module ClassMethods - def find(pid_or_uri) - pid = pid_or_uri.sub(/\Ainfo:fedora\//, "") - query = Ddr::Index::QueryBuilder.build { |q| q.id(pid) } + def find(id) + query = Ddr::Index::QueryBuilder.build { |q| q.id(id) } if doc = query.docs.first return doc end - raise NotFound, "SolrDocument not found for \"#{pid_or_uri}\"." + raise NotFound, "SolrDocument not found for \"#{id}\"." end end + def pid + Deprecation.warn(SolrDocument, "Use `id` instead.") + id + end + def inspect "#<#{self.class.name} id=#{id.inspect}>" end def method_missing(name, *args, &block) @@ -73,10 +75,15 @@ def last_virus_check_on get_date(Ddr::Index::Fields::LAST_VIRUS_CHECK_ON) end def datastreams - object_profile["datastreams"] + Deprecation.warn(SolrDocument, "Use `attached_files` instead.") + attached_files + end + + def attached_files + (get_json(Ddr::Index::Fields::ATTACHED_FILES) || {}).with_indifferent_access end def has_datastream?(dsID) datastreams[dsID].present? end