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:

Defined Under Namespace

Classes: ModelWrapper

Constant Summary

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)

116
117
118
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 116

def admin_set?
  hydra_model == ::AdminSet
end

#collection?Boolean

Returns:

  • (Boolean)

104
105
106
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 104

def collection?
  hydra_model == ::Collection
end

#collection_type_gidObject


150
151
152
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 150

def collection_type_gid
  first(Hyrax.config.collection_type_index_field)
end

#creatorObject


131
132
133
134
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 131

def creator
  solr_term = hydra_model == AdminSet ? "creator_ssim" : "creator_tesim"
  fetch(solr_term, [])
end

#depositor(default = '') ⇒ Object


126
127
128
129
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 126

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

#file_set?Boolean

Returns:

  • (Boolean)

110
111
112
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 110

def file_set?
  hydra_model == ::FileSet
end

#hydra_model(classifier: ActiveFedora.model_mapper) ⇒ Object

Method to return the model


121
122
123
124
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 121

def hydra_model(classifier: ActiveFedora.model_mapper)
  "::#{first('has_model_ssim')}".safe_constantize ||
    classifier.classifier(self).best_model
end

#itemtypeObject

Add a schema.org itemtype


24
25
26
27
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 24

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

#title_or_labelObject


29
30
31
32
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 29

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>

98
99
100
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 98

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

#to_paramObject


34
35
36
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 34

def to_param
  id
end

#to_sObject

rubocop:disable Rails/Delegate


38
39
40
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 38

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

#visibilityObject


136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 136

def visibility
  @visibility ||= if embargo_release_date.present?
                    Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO
                  elsif lease_expiration_date.present?
                    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