Module: Ddr::Models::SolrDocument

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

Instance Method Summary collapse

Instance Method Details

#active_fedora_modelObject



20
21
22
# File 'lib/ddr/models/solr_document.rb', line 20

def active_fedora_model
  get(Ddr::IndexFields::ACTIVE_FEDORA_MODEL)
end

#admin_policy_pidObject



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

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

#admin_policy_uriObject



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

def admin_policy_uri
  get(Ddr::IndexFields::IS_GOVERNED_BY)
end

#association(name) ⇒ Object



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

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

#content_checksumObject



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

def content_checksum
  content_ds["dsChecksum"] rescue nil
end

#content_dsObject



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

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

#content_mime_typeObject Also known as: content_type



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

def content_mime_type
  content_ds["dsMIME"] rescue nil
end

#content_sizeObject



125
126
127
# File 'lib/ddr/models/solr_document.rb', line 125

def content_size
  get(Ddr::IndexFields::CONTENT_SIZE)
end

#content_size_humanObject



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

def content_size_human
  get(Ddr::IndexFields::CONTENT_SIZE_HUMAN)
end

#controller_nameObject



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

def controller_name
  active_fedora_model.tableize
end

#datastreamsObject



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

def datastreams
  object_profile["datastreams"]
end

#effective_licenseObject



180
181
182
# File 'lib/ddr/models/solr_document.rb', line 180

def effective_license
  @effective_license ||= license || inherited_license || {}
end

#has_admin_policy?Boolean

Returns:

  • (Boolean)


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

def has_admin_policy?
  admin_policy_uri.present?
end

#has_children?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/ddr/models/solr_document.rb', line 81

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

#has_content?Boolean

Returns:

  • (Boolean)


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

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

#has_datastream?(dsID) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#has_default_rights?Boolean

Returns:

  • (Boolean)


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

def has_default_rights?
  has_datastream?(Ddr::Datastreams::DEFAULT_RIGHTS)
end

#has_target?Boolean

Returns:

  • (Boolean)


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

def has_target?
  targets_count > 0
end

#has_thumbnail?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/ddr/models/solr_document.rb', line 107

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

#identifierObject



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

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

#inherited_licenseObject



161
162
163
164
165
166
167
168
169
170
# File 'lib/ddr/models/solr_document.rb', line 161

def inherited_license
  if admin_policy_pid
    query = ActiveFedora::SolrService.construct_query_for_pids([admin_policy_pid])
    results = ActiveFedora::SolrService.query(query)
    doc = results.map { |result| ::SolrDocument.new(result) }.first
    { title: doc.get(Ddr::IndexFields::DEFAULT_LICENSE_TITLE),
      description: doc.get(Ddr::IndexFields::DEFAULT_LICENSE_DESCRIPTION),
      url: doc.get(Ddr::IndexFields::DEFAULT_LICENSE_URL) }
  end
end

#internal_uriObject



24
25
26
# File 'lib/ddr/models/solr_document.rb', line 24

def internal_uri
  get(Ddr::IndexFields::INTERNAL_URI)
end

#labelObject



85
86
87
# File 'lib/ddr/models/solr_document.rb', line 85

def label
  object_profile["objLabel"]
end

#last_fixity_check_onObject



44
45
46
# File 'lib/ddr/models/solr_document.rb', line 44

def last_fixity_check_on
  get_date(Ddr::IndexFields::LAST_FIXITY_CHECK_ON)
end

#last_fixity_check_outcomeObject



48
49
50
# File 'lib/ddr/models/solr_document.rb', line 48

def last_fixity_check_outcome
  get(Ddr::IndexFields::LAST_FIXITY_CHECK_OUTCOME)
end

#last_virus_check_onObject



52
53
54
# File 'lib/ddr/models/solr_document.rb', line 52

def last_virus_check_on
  get_date(Ddr::IndexFields::LAST_VIRUS_CHECK_ON)
end

#last_virus_check_outcomeObject



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

def last_virus_check_outcome
  get(Ddr::IndexFields::LAST_VIRUS_CHECK_OUTCOME)
end

#licenseObject



172
173
174
175
176
177
178
# File 'lib/ddr/models/solr_document.rb', line 172

def license
  if get(Ddr::IndexFields::LICENSE_TITLE) || get(Ddr::IndexFields::LICENSE_DESCRIPTION) || get(Ddr::IndexFields::LICENSE_URL)
    { title: get(Ddr::IndexFields::LICENSE_TITLE),
      description: get(Ddr::IndexFields::LICENSE_DESCRIPTION),
      url: get(Ddr::IndexFields::LICENSE_URL) }
  end
end

#object_create_dateObject



36
37
38
# File 'lib/ddr/models/solr_document.rb', line 36

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

#object_modified_dateObject



40
41
42
# File 'lib/ddr/models/solr_document.rb', line 40

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

#object_profileObject



28
29
30
# File 'lib/ddr/models/solr_document.rb', line 28

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

#object_stateObject



32
33
34
# File 'lib/ddr/models/solr_document.rb', line 32

def object_state
  object_profile["objState"]
end

#permanent_idObject



184
185
186
# File 'lib/ddr/models/solr_document.rb', line 184

def permanent_id
  get(Ddr::IndexFields::PERMANENT_ID)
end

#principal_has_role?(principal, role) ⇒ Boolean

Returns:

  • (Boolean)


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

def principal_has_role?(principal, role)
  (Array(self["admin_metadata__#{role}_ssim"]) & Array(principal)).any?
end

#safe_idObject



16
17
18
# File 'lib/ddr/models/solr_document.rb', line 16

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

#sourceObject



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

def source
  get(ActiveFedora::SolrService.solr_name(:source, :stored_searchable, type: :text))
end

#targetsObject



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

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

#targets_countObject



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

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

#titleObject Also known as: title_display



89
90
91
# File 'lib/ddr/models/solr_document.rb', line 89

def title
  get(Ddr::IndexFields::TITLE)
end

#to_partial_pathObject



12
13
14
# File 'lib/ddr/models/solr_document.rb', line 12

def to_partial_path
  'document'
end