Module: Hyrax::SolrDocumentBehavior

Extended by:
ActiveSupport::Concern
Includes:
Hydra::Works::MimeTypes, Permissions::Readable, Hyrax::SolrDocument::Characterization, Hyrax::SolrDocument::Export, Hyrax::SolrDocument::Metadata
Defined in:
app/models/concerns/hyrax/solr_document_behavior.rb

Overview

Hyrax extensions for Blacklight‘s generated SolrDocument.

Examples:

using with Blacklight::Solr::Document

class SolrDocument
  include Blacklight::Solr::Document
  include Hyrax::SolrDocumentBehavior
end

See Also:

Constant Summary collapse

ModelWrapper =

alias for backward compatibility

ActiveFedoraDummyModel

Constants included from Hyrax::SolrDocument::Export

Hyrax::SolrDocument::Export::END_NOTE_MAPPINGS

Instance Method Summary collapse

Methods included from Hyrax::SolrDocument::Characterization

#alpha_channels, #byte_order, #capture_device, #color_map, #color_space, #compression, #duration, #file_size, #file_title, #filename, #format_label, #gps_timestamp, #height, #image_producer, #last_modified, #latitude, #longitude, #orientation, #original_checksum, #page_count, #profile_name, #profile_version, #sample_rate, #scanning_software, #well_formed, #width

Methods included from Hyrax::SolrDocument::Export

#end_note_format, #endnote_filename, #export_as_endnote, #persistent_url

Methods included from Permissions::Readable

#private?, #public?, #registered?

Instance Method Details

#admin_set?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 67

def admin_set?
  Hyrax::ModelRegistry.admin_set_classes.include?(hydra_model)
end

#collection?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 55

def collection?
  Hyrax::ModelRegistry.collection_classes.include?(hydra_model)
end

#collection_type_gidObject



108
109
110
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 108

def collection_type_gid
  first(Hyrax.config.collection_type_index_field)
end

#creatorObject



88
89
90
91
92
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 88

def creator
  # TODO: should we replace "hydra_model == AdminSet" with by #admin_set?
  solr_term = hydra_model == AdminSet ? "creator_ssim" : "creator_tesim"
  fetch(solr_term, [])
end

#depositor(default = '') ⇒ Object



83
84
85
86
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 83

def depositor(default = '')
  val = first("depositor_tesim")
  val.presence || default
end

#embargo_enforced?Boolean

Returns:

  • (Boolean)


112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 112

def embargo_enforced?
  return false if embargo_release_date.blank?

  indexed_embargo_visibility = first('visibility_during_embargo_ssim')
  # if we didn't index an embargo visibility, assume the release date means
  # it's enforced
  return true if indexed_embargo_visibility.blank?

  # if the visibility and the visibility during embargo are the same, we're
  # enforcing the embargo
  self['visibility_ssi'] == indexed_embargo_visibility
end

#file_set?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 61

def file_set?
  Hyrax::ModelRegistry.file_set_classes.include?(hydra_model)
end

#hydra_model(classifier: nil) ⇒ Object

Method to return the model



78
79
80
81
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 78

def hydra_model(classifier: nil)
  first('has_model_ssim')&.safe_constantize ||
    model_classifier(classifier).classifier(self).best_model
end

#itemtypeObject

Add a schema.org itemtype



26
27
28
29
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 26

def itemtype
  types = resource_type || []
  ResourceTypesService.microdata_type(types.first)
end

#lease_enforced?Boolean

Returns:

  • (Boolean)


125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 125

def lease_enforced?
  return false if lease_expiration_date.blank?

  indexed_lease_visibility = first('visibility_during_lease_ssim')
  # if we didn't index an embargo visibility, assume the release date means
  # it's enforced
  return true if indexed_lease_visibility.blank?

  # if the visibility and the visibility during lease are the same, we're
  # enforcing the lease
  self['visibility_ssi'] == indexed_lease_visibility
end

#title_or_labelObject



31
32
33
34
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 31

def title_or_label
  return label if title.blank?
  title.join(', ')
end

#to_modelObject

Offer the source model to Rails for some of the Rails methods (e.g. link_to).

Examples:

link_to '...', SolrDocument(:id => 'bXXXXXX5').new => <a href="/dams_object/bXXXXXX5">...</a>


49
50
51
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 49

def to_model
  @model ||= ActiveFedoraDummyModel.new(hydra_model, id)
end

#to_paramObject



36
37
38
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 36

def to_param
  id
end

#to_sObject

rubocop:disable Rails/Delegate



40
41
42
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 40

def to_s # rubocop:disable Rails/Delegate
  title_or_label.to_s
end

#visibilityObject



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 94

def visibility
  @visibility ||= if embargo_enforced?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO
                  elsif lease_enforced?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE
                  elsif public?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
                  elsif registered?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
                  else
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
                  end
end

#work?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 73

def work?
  Hyrax::ModelRegistry.work_classes.include?(hydra_model)
end