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?
  hydra_model == Hyrax.config.admin_set_class
end

#collection?Boolean

Returns:

  • (Boolean)

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

def collection?
  hydra_model == Hyrax.config.collection_class
end

#collection_type_gidObject


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

def collection_type_gid
  first(Hyrax.config.collection_type_index_field)
end

#creatorObject


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

def creator
  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

#file_set?Boolean

Returns:

  • (Boolean)

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

def file_set?
  hydra_model == ::FileSet
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

#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


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

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

#work?Boolean

Returns:

  • (Boolean)

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

def work?
  Hyrax.config.curation_concerns.include? hydra_model
end