Module: Ddr::Models::SolrDocument

Extended by:
ActiveSupport::Concern, Deprecation
Defined in:
lib/ddr/models/solr_document.rb

Defined Under Namespace

Modules: ClassMethods Classes: NotFound

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ddr/models/solr_document.rb', line 38

def method_missing(name, *args, &block)
  if args.empty? && !block
    begin
      field = Ddr::Index::Fields.get(name)
    rescue NameError
    # pass
    else
      # Preserves the default behavior of the deprecated method
      # Blacklight::Solr::Document#get, which this procedure
      # effectively replaces.
      val = self[field]
      return val.is_a?(Array) ? val.join(", ") : val
    end
  end
  super
end

Instance Method Details

#admin_policyObject



109
110
111
112
113
# File 'lib/ddr/models/solr_document.rb', line 109

def admin_policy
  if has_admin_policy?
    self.class.find(admin_policy_uri)
  end
end

#admin_policy_pidObject Also known as: admin_policy_id



103
104
105
106
# File 'lib/ddr/models/solr_document.rb', line 103

def admin_policy_pid
  uri = admin_policy_uri
  uri &&= ActiveFedora::Base.pid_from_uri(uri)
end

#admin_policy_uriObject



99
100
101
# File 'lib/ddr/models/solr_document.rb', line 99

def admin_policy_uri
  is_governed_by
end

#association(name) ⇒ Object



178
179
180
# File 'lib/ddr/models/solr_document.rb', line 178

def association(name)
  get_pid(ActiveFedora::SolrService.solr_name(name, :symbol))
end

#caption_extensionObject



273
274
275
276
277
278
279
280
281
282
# File 'lib/ddr/models/solr_document.rb', line 273

def caption_extension
  if captionable?
    extensions = Ddr::Models.preferred_file_extensions
    if extensions.include? caption_type
      extensions[caption_type]
    else
      caption_extension_default
    end
  end
end

#caption_pathObject



284
285
286
287
288
# File 'lib/ddr/models/solr_document.rb', line 284

def caption_path
  if captionable?
    Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::CAPTION]["dsLocation"])
  end
end

#caption_typeObject



267
268
269
270
271
# File 'lib/ddr/models/solr_document.rb', line 267

def caption_type
  if captionable?
    datastreams[Ddr::Datastreams::CAPTION]["dsMIME"]
  end
end

#captionable?Boolean

Returns:

  • (Boolean)


263
264
265
# File 'lib/ddr/models/solr_document.rb', line 263

def captionable?
  has_datastream?(Ddr::Datastreams::CAPTION)
end

#childrenObject



322
323
324
# File 'lib/ddr/models/solr_document.rb', line 322

def children
  children_query.docs rescue []
end

#content_checksumObject



162
163
164
# File 'lib/ddr/models/solr_document.rb', line 162

def content_checksum
  content_ds["dsChecksum"] rescue nil
end

#content_dsObject



152
153
154
# File 'lib/ddr/models/solr_document.rb', line 152

def content_ds
  datastreams[Ddr::Datastreams::CONTENT]
end

#content_mime_typeObject Also known as: content_type



156
157
158
# File 'lib/ddr/models/solr_document.rb', line 156

def content_mime_type
  content_ds["dsMIME"] rescue nil
end

#controller_nameObject



182
183
184
# File 'lib/ddr/models/solr_document.rb', line 182

def controller_name
  active_fedora_model.tableize
end

#datastreamsObject



87
88
89
# File 'lib/ddr/models/solr_document.rb', line 87

def datastreams
  object_profile["datastreams"]
end

#effective_permissions(agents) ⇒ Object



202
203
204
# File 'lib/ddr/models/solr_document.rb', line 202

def effective_permissions(agents)
  Ddr::Auth::EffectivePermissions.call(self, agents)
end

#finding_aidObject

DRY HasAdminMetadata



234
235
236
237
238
# File 'lib/ddr/models/solr_document.rb', line 234

def finding_aid
  if ead_id
    FindingAid.new(ead_id)
  end
end

#has_admin_policy?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/ddr/models/solr_document.rb', line 95

def has_admin_policy?
  admin_policy_uri.present?
end

#has_children?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/ddr/models/solr_document.rb', line 115

def has_children?
  ActiveFedora::SolrService.class_from_solr_document(self).reflect_on_association(:children).present?
end

#has_content?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/ddr/models/solr_document.rb', line 140

def has_content?
  has_datastream?(Ddr::Datastreams::CONTENT)
end

#has_datastream?(dsID) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/ddr/models/solr_document.rb', line 91

def has_datastream?(dsID)
  datastreams[dsID].present?
end

#has_extracted_text?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/ddr/models/solr_document.rb', line 148

def has_extracted_text?
  has_datastream?(Ddr::Datastreams::EXTRACTED_TEXT)
end

#has_intermediate_file?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/ddr/models/solr_document.rb', line 144

def has_intermediate_file?
  has_datastream?(Ddr::Datastreams::INTERMEDIATE_FILE)
end

#has_parent?Boolean

Returns:

  • (Boolean)


215
216
217
# File 'lib/ddr/models/solr_document.rb', line 215

def has_parent?
  parent_uri.present?
end

#has_target?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/ddr/models/solr_document.rb', line 174

def has_target?
  targets_count > 0
end

#has_thumbnail?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/ddr/models/solr_document.rb', line 136

def has_thumbnail?
  has_datastream?(Ddr::Datastreams::THUMBNAIL)
end

#identifierObject



127
128
129
130
# File 'lib/ddr/models/solr_document.rb', line 127

def identifier
  # We want the multivalued version here
  self[ActiveFedora::SolrService.solr_name(:identifier, :stored_searchable, type: :text)]
end

#inspectObject



34
35
36
# File 'lib/ddr/models/solr_document.rb', line 34

def inspect
  "#<#{self.class.name} id=#{id.inspect}>"
end

#intermediate_extensionObject



252
253
254
255
256
257
258
259
260
261
# File 'lib/ddr/models/solr_document.rb', line 252

def intermediate_extension
  if has_intermediate_file?
    extensions = Ddr::Models.preferred_file_extensions
    if extensions.include? intermediate_type
      extensions[intermediate_type]
    else
      intermediate_extension_default
    end
  end
end

#intermediate_pathObject



246
247
248
249
250
# File 'lib/ddr/models/solr_document.rb', line 246

def intermediate_path
  if has_intermediate_file?
    Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::INTERMEDIATE_FILE]["dsLocation"])
  end
end

#intermediate_typeObject



240
241
242
243
244
# File 'lib/ddr/models/solr_document.rb', line 240

def intermediate_type
  if has_intermediate_file?
    datastreams[Ddr::Datastreams::INTERMEDIATE_FILE]["dsMIME"]
  end
end

#labelObject



119
120
121
# File 'lib/ddr/models/solr_document.rb', line 119

def label
  object_profile["objLabel"]
end

#last_fixity_check_onObject



79
80
81
# File 'lib/ddr/models/solr_document.rb', line 79

def last_fixity_check_on
  get_date(Ddr::Index::Fields::LAST_FIXITY_CHECK_ON)
end

#last_virus_check_onObject



83
84
85
# File 'lib/ddr/models/solr_document.rb', line 83

def last_virus_check_on
  get_date(Ddr::Index::Fields::LAST_VIRUS_CHECK_ON)
end

#multires_image_file_pathsObject



225
226
227
228
229
230
231
# File 'lib/ddr/models/solr_document.rb', line 225

def multires_image_file_paths
  if structure
    structure_docs.map { |doc| doc.multires_image_file_path }.compact
  else
    []
  end
end

#object_create_dateObject



71
72
73
# File 'lib/ddr/models/solr_document.rb', line 71

def object_create_date
  parse_date(object_profile["objCreateDate"])
end

#object_modified_dateObject



75
76
77
# File 'lib/ddr/models/solr_document.rb', line 75

def object_modified_date
  parse_date(object_profile["objLastModDate"])
end

#object_profileObject



63
64
65
# File 'lib/ddr/models/solr_document.rb', line 63

def object_profile
  @object_profile ||= get_json(Ddr::Index::Fields::OBJECT_PROFILE)
end

#object_stateObject



67
68
69
# File 'lib/ddr/models/solr_document.rb', line 67

def object_state
  object_profile["objState"]
end

#parentObject



219
220
221
222
223
# File 'lib/ddr/models/solr_document.rb', line 219

def parent
  if has_parent?
    self.class.find(parent_uri)
  end
end

#parent_uriObject



211
212
213
# File 'lib/ddr/models/solr_document.rb', line 211

def parent_uri
  is_part_of || is_member_of_collection
end

#research_helpObject



206
207
208
209
# File 'lib/ddr/models/solr_document.rb', line 206

def research_help
  research_help_contact = self[Ddr::Index::Fields::RESEARCH_HELP_CONTACT] || inherited_research_help_contact
  Ddr::Models::Contact.call(research_help_contact) if research_help_contact
end

#rightsObject

FIXME - Probably need a more general solution mapping object reader methods to index field names.



318
319
320
# File 'lib/ddr/models/solr_document.rb', line 318

def rights
  self["rights_tesim"]
end

#rights_statementObject Also known as: effective_license



186
187
188
# File 'lib/ddr/models/solr_document.rb', line 186

def rights_statement
  @rights_statement ||= RightsStatement.call(self)
end

#rolesObject



192
193
194
# File 'lib/ddr/models/solr_document.rb', line 192

def roles
  @roles ||= Ddr::Auth::Roles::DetachedRoleSet.from_json(access_role)
end

#safe_idObject



59
60
61
# File 'lib/ddr/models/solr_document.rb', line 59

def safe_id
  id.sub(/:/, "-")
end

#sourceObject



132
133
134
# File 'lib/ddr/models/solr_document.rb', line 132

def source
  self[ActiveFedora::SolrService.solr_name(:source, :stored_searchable, type: :text)]
end

#streamable?Boolean

Returns:

  • (Boolean)


290
291
292
# File 'lib/ddr/models/solr_document.rb', line 290

def streamable?
  has_datastream?(Ddr::Datastreams::STREAMABLE_MEDIA)
end

#streamable_media_extensionObject



294
295
296
297
298
299
300
301
302
303
# File 'lib/ddr/models/solr_document.rb', line 294

def streamable_media_extension
  if streamable?
    extensions = Ddr::Models.preferred_file_extensions
    if extensions.include? streamable_media_type
      extensions[streamable_media_type]
    else
      streamable_media_extension_default
    end
  end
end

#streamable_media_pathObject



311
312
313
314
315
# File 'lib/ddr/models/solr_document.rb', line 311

def streamable_media_path
  if streamable?
    Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::STREAMABLE_MEDIA]["dsLocation"])
  end
end

#streamable_media_typeObject



305
306
307
308
309
# File 'lib/ddr/models/solr_document.rb', line 305

def streamable_media_type
  if streamable?
    datastreams[Ddr::Datastreams::STREAMABLE_MEDIA]["dsMIME"]
  end
end

#structureObject



196
197
198
199
200
# File 'lib/ddr/models/solr_document.rb', line 196

def structure
  JSON.parse(fetch(Ddr::Index::Fields::STRUCTURE))
rescue
  nil
end

#targetsObject



166
167
168
# File 'lib/ddr/models/solr_document.rb', line 166

def targets
  @targets ||= ActiveFedora::SolrService.query(targets_query)
end

#targets_countObject



170
171
172
# File 'lib/ddr/models/solr_document.rb', line 170

def targets_count
  @targets_count ||= ActiveFedora::SolrService.count(targets_query)
end

#title_displayObject



123
124
125
# File 'lib/ddr/models/solr_document.rb', line 123

def title_display
  title
end

#to_partial_pathObject



55
56
57
# File 'lib/ddr/models/solr_document.rb', line 55

def to_partial_path
  'document'
end