Module: Dor

Defined in:
lib/dor/config.rb,
lib/dor/version.rb,
lib/dor-services.rb,
lib/dor/exceptions.rb,
lib/dor/models/set.rb,
lib/dor/models/item.rb,
lib/dor/models/geoable.rb,
lib/dor/workflow/graph.rb,
lib/dor/models/editable.rb,
lib/dor/models/eventable.rb,
lib/dor/models/shelvable.rb,
lib/dor/workflow/process.rb,
lib/dor/models/collection.rb,
lib/dor/models/governable.rb,
lib/dor/models/itemizable.rb,
lib/dor/models/upgradable.rb,
lib/dor/workflow/document.rb,
lib/dor/models/contentable.rb,
lib/dor/models/describable.rb,
lib/dor/models/embargoable.rb,
lib/dor/models/preservable.rb,
lib/dor/models/processable.rb,
lib/dor/models/publishable.rb,
lib/dor/models/versionable.rb,
lib/dor/models/assembleable.rb,
lib/dor/models/discoverable.rb,
lib/dor/models/identifiable.rb,
lib/dor/datastreams/events_ds.rb,
lib/dor/services/suri_service.rb,
lib/dor/models/workflow_object.rb,
lib/dor/services/merge_service.rb,
lib/dor/datastreams/workflow_ds.rb,
lib/dor/services/search_service.rb,
lib/dor/services/cleanup_service.rb,
lib/dor/services/metadata_service.rb,
lib/dor/models/admin_policy_object.rb,
lib/dor/datastreams/geo_metadata_ds.rb,
lib/dor/services/sdr_ingest_service.rb,
lib/dor/datastreams/desc_metadata_ds.rb,
lib/dor/datastreams/role_metadata_ds.rb,
lib/dor/services/registration_service.rb,
lib/dor/services/cleanup_reset_service.rb,
lib/dor/datastreams/content_metadata_ds.rb,
lib/dor/datastreams/embargo_metadata_ds.rb,
lib/dor/datastreams/version_metadata_ds.rb,
lib/dor/services/digital_stacks_service.rb,
lib/dor/datastreams/identity_metadata_ds.rb,
lib/dor/services/reset_workspace_service.rb,
lib/dor/datastreams/workflow_definition_ds.rb,
lib/dor/services/technical_metadata_service.rb,
lib/dor/datastreams/default_object_rights_ds.rb,
lib/dor/datastreams/administrative_metadata_ds.rb

Defined Under Namespace

Modules: Assembleable, BasicItem, Contentable, Describable, Discoverable, Editable, Embargoable, Eventable, Geoable, Governable, Identifiable, Itemizable, Preservable, Processable, Publishable, Shelvable, Upgradable, Versionable, Versioning, Workflow Classes: Abstract, AdminPolicyObject, AdministrativeMetadataDS, CleanupResetService, CleanupService, Collection, Configuration, ContentMetadataDS, DefaultObjectRightsDS, DescMetadataDS, DigitalStacksService, DuplicateIdError, EmbargoMetadataDS, EventsDS, Exception, GeoMetadataDS, IdentityMetadataDS, Item, MergeService, MetadataError, MetadataService, ParameterError, RegistrationService, ResetWorkspaceService, RoleMetadataDS, SdrIngestService, SearchService, Set, SuriService, TechnicalMetadataService, VersionMetadataDS, VersionTag, WorkflowDefinitionDs, WorkflowDs, WorkflowObject

Constant Summary collapse

Config =
Configuration.new(YAML.load(File.read(File.expand_path('../../../config/config_defaults.yml', __FILE__))))
VERSION =
'4.14.1'
INDEX_VERSION_FIELD =
'dor_services_version_facet'
@@registered_classes =
{}

Class Method Summary collapse

Class Method Details

.configure(*args, &block) ⇒ Object


11
12
13
# File 'lib/dor-services.rb', line 11

def configure *args, &block
  Dor::Config.configure *args, &block
end

.ensure_models_loaded!Object


64
65
66
# File 'lib/dor-services.rb', line 64

def ensure_models_loaded!
  [Item, Set, Collection, AdminPolicyObject, WorkflowObject]
end

.find(pid, opts = {}) ⇒ Object

Get objectType information from solr and load the correct class the first time, saving the overhead of using ActiveFedora::Base#adapt_to. It falls back to Dor.load_instance() if the item is not in the index, or is improperly indexed.


33
34
35
# File 'lib/dor-services.rb', line 33

def find pid, opts={}
  self.find_all(%{id:"#{pid}"}, opts).first || self.load_instance(pid)
end

.find_all(query, opts = {}) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dor-services.rb', line 37

def find_all query, opts={}
  ensure_models_loaded!
  af_version = Gem::Version.new(ActiveFedora::VERSION)
  if opts[:lightweight] and af_version < Gem::Version.new('4.0.0.rc9')
    ActiveFedora.logger.warn("Loading of lightweight objects requires ActiveFedora >= 4.0.0")
    opts.delete(:lightweight)
  end

  resp = SearchService.query query, opts
  resp.docs.collect do |solr_doc|
    doc_version = solr_doc[INDEX_VERSION_FIELD].first rescue '0.0.0'
    doc_version = Gem::Version.new(doc_version)
    object_type = Array(solr_doc[ActiveFedora::SolrService.solr_name('objectType',:string)]).first
    object_class = registered_classes[object_type] || ActiveFedora::Base
    if opts[:lightweight] and doc_version >= Gem::Version.new('3.1.0')
      begin
        object_class.load_instance_from_solr solr_doc['id'], solr_doc
      rescue Exception => e
        ActiveFedora.logger.warn("Exception: '#{e.message}' trying to load #{solr_doc['id']} from solr. Loading from Fedora")
        load_instance(solr_doc['id'])
      end
    else
      load_instance solr_doc['id']
    end
  end
end

.load_instance(pid) ⇒ Object

Load an object and inspect its identityMetadata to figure out what class to adapt it to. This is necessary when the object is not indexed, or the index is missing the objectType property.


19
20
21
22
23
24
25
26
# File 'lib/dor-services.rb', line 19

def load_instance pid
  ensure_models_loaded!
  obj = Dor::Abstract.find pid
  return nil if obj.new_object?
  object_type = obj..objectType.first
  object_class = registered_classes[object_type] || Dor::Item
  obj.adapt_to(object_class)
end

.rootObject


68
69
70
# File 'lib/dor-services.rb', line 68

def root
  File.dirname(__FILE__)
end