Class: Dor::Abstract

Inherits:
ActiveFedora::Base
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/dor/models/abstract.rb

Direct Known Subclasses

AdminPolicyObject, Etd, Item, Set, WorkflowObject

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assign_pid(_obj) ⇒ Object

Overrides the method in ActiveFedora to mint a pid using SURI rather than the default Fedora sequence



57
58
59
60
61
# File 'lib/dor/models/abstract.rb', line 57

def self.assign_pid(_obj)
  return Dor::SuriService.mint_id if Dor::Config.suri.mint_ids

  super
end

.has_object_type(str) ⇒ Object



50
51
52
53
# File 'lib/dor/models/abstract.rb', line 50

def self.has_object_type(str)
  self.object_type = str
  Dor.registered_classes[str] = self
end

Instance Method Details

#adapt_to_cmodelObject

Override ActiveFedora::Core#adapt_to_cmodel (used with associations, among other places) to preferentially use the objectType asserted in the identityMetadata.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dor/models/abstract.rb', line 70

def adapt_to_cmodel
  object_type = .objectType.first
  object_class = Dor.registered_classes[object_type]

  if object_class
    instance_of?(object_class) ? self : adapt_to(object_class)
  else
    begin
      super
    rescue ActiveFedora::ModelNotAsserted
      adapt_to(Dor::Item)
    end
  end
end

#add_collection(collection_or_druid) ⇒ Object



130
131
132
# File 'lib/dor/models/abstract.rb', line 130

def add_collection(collection_or_druid)
  collection_manager.add(collection_or_druid)
end

#allows_modification?Boolean

TODO:

this could be a workflow service endpoint

This is used by Argo and the MergeService

Returns:

  • (Boolean)

    true if the object is in a state that allows it to be modified. States that will allow modification are: has not been submitted for accessioning, has an open version or has sdr-ingest set to hold



110
111
112
# File 'lib/dor/models/abstract.rb', line 110

def allows_modification?
  Dor::StateService.new(pid).allows_modification?
end

#current_versionObject



115
116
117
# File 'lib/dor/models/abstract.rb', line 115

def current_version
  .current_version_id
end

#druid_regexRegex

a regex that can be used to identify a full druid with prefix (e.g. druid:oo000oo0001)

Returns:

  • (Regex)

    a regular expression to identify a full druid



94
95
96
# File 'lib/dor/models/abstract.rb', line 94

def druid_regex
  /druid:#{pid_regex}/
end

#pid_regexRegex

a regex that can be used to identify the last part of a druid (e.g. oo000oo0001)

Returns:

  • (Regex)

    a regular expression to identify the ID part of the druid



87
88
89
# File 'lib/dor/models/abstract.rb', line 87

def pid_regex
  /[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}[0-9]{4}/
end

#read_rights=(rights) ⇒ Object Also known as: set_read_rights



123
124
125
126
# File 'lib/dor/models/abstract.rb', line 123

def read_rights=(rights)
  .set_read_rights(rights)
  unshelve_and_unpublish if rights == 'dark'
end

#reapply_admin_policy_object_defaultsObject Also known as: reapplyAdminPolicyObjectDefaults

set the rights metadata datastream to the content of the APO’s default object rights



139
140
141
# File 'lib/dor/models/abstract.rb', line 139

def reapply_admin_policy_object_defaults
  .content = admin_policy_object.defaultObjectRights.content
end

#remove_collection(collection_or_druid) ⇒ Object



134
135
136
# File 'lib/dor/models/abstract.rb', line 134

def remove_collection(collection_or_druid)
  collection_manager.remove(collection_or_druid)
end

#remove_druid_prefix(druid = id) ⇒ String

Since purl does not use the druid: prefix but much of dor does, use this function to strip the druid: if needed

Returns:

  • (String)

    the druid sans the druid: or if there was no druid: prefix, the entire string you passed



101
102
103
# File 'lib/dor/models/abstract.rb', line 101

def remove_druid_prefix(druid = id)
  PidUtils.remove_druid_prefix(druid)
end

#to_solrObject

Overrides the method in ActiveFedora



64
65
66
# File 'lib/dor/models/abstract.rb', line 64

def to_solr
  resource_indexer.new(resource: self).to_solr
end