Class: Document
- Inherits:
-
Kithe::Work
- Object
- Kithe::Work
- Document
- Includes:
- ActiveModel::Validations, AttrJson::Record::QueryScopes
- Defined in:
- app/models/document.rb,
app/models/document/reference.rb,
app/models/document/bbox_validator.rb,
app/models/document/geom_validator.rb,
app/models/document/controlled_lists.rb,
app/models/document/date_range_validator.rb
Overview
Date Range Validation
Allow: YYYY-YYYY, *-YYYY, YYYY-*, Start YYYY == End YYYY Disallow: YYYX-YYYY, YYYY-, 2000-1999, YYYY-YYYY?
Defined Under Namespace
Classes: BboxValidator, ControlledLists, DateRangeValidator, GeomValidator, Reference
Instance Attribute Summary collapse
-
#skip_callbacks ⇒ Object
Returns the value of attribute skip_callbacks.
Instance Method Summary collapse
-
#a_downloadable_resource? ⇒ Boolean
Downloadable Resouce.
-
#access_json ⇒ Object
End / From GBL.
-
#access_urls ⇒ Object
Institutional Access URLs.
- #apply_downloads(references) ⇒ Object
- #created_at_dt ⇒ Object
- #current_version ⇒ Object
- #date_range_json ⇒ Object
- #dct_references_s_to_csv(key, destination) ⇒ Object
-
#dct_title_s ⇒ Object
Ensures a manually created “title” makes it into the attr_json “title”.
-
#derive_dcat_bbox ⇒ Object
Convert GEOM for Solr Indexing.
- #derive_dcat_centroid ⇒ Object
- #derive_locn_geometry ⇒ Object
-
#derive_polygon ⇒ Object
Convert BBOX to GEOM Polygon.
-
#download_text(format) ⇒ Object
Wraps download text with proper_case_format.
- #gbl_mdModified_dt ⇒ Object
-
#iso_language_mapping ⇒ Object
Convert three char language code to proper string.
- #multiple_downloads_array ⇒ Object
-
#proper_case_format(format) ⇒ Object
From GBL.
-
#references_json ⇒ Object
Index Transformations - *_json functions.
- #set_geometry ⇒ Object
- #solr_year_json ⇒ Object (also: #gbl_indexYear_im)
- #state_machine ⇒ Object
-
#to_csv ⇒ Object
Export Transformations - to_*.
- #to_traject ⇒ Object
Instance Attribute Details
#skip_callbacks ⇒ Object
Returns the value of attribute skip_callbacks.
8 9 10 |
# File 'app/models/document.rb', line 8 def skip_callbacks @skip_callbacks end |
Instance Method Details
#a_downloadable_resource? ⇒ Boolean
Downloadable Resouce
49 50 51 |
# File 'app/models/document.rb', line 49 def a_downloadable_resource? references_json.include?("downloadUrl") end |
#access_json ⇒ Object
End / From GBL
126 127 128 129 130 |
# File 'app/models/document.rb', line 126 def access_json access = {} access_urls.each { |au| access[au.institution_code] = au.access_url } access.to_json end |
#access_urls ⇒ Object
Institutional Access URLs
199 200 201 |
# File 'app/models/document.rb', line 199 def access_urls DocumentAccess.where(friendlier_id: friendlier_id).order(institution_code: :asc) end |
#apply_downloads(references) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/document.rb', line 80 def apply_downloads(references) dct_downloads = references["http://schema.org/downloadUrl"] # Make sure downloads exist! if document_downloads.present? multiple_downloads = multiple_downloads_array if dct_downloads.present? multiple_downloads << {label: download_text(send(GeoblacklightAdmin::Schema.instance.solr_fields[:format])), url: dct_downloads} end references[:"http://schema.org/downloadUrl"] = multiple_downloads end references end |
#created_at_dt ⇒ Object
132 133 134 |
# File 'app/models/document.rb', line 132 def created_at_dt created_at&.utc&.iso8601 end |
#current_version ⇒ Object
194 195 196 |
# File 'app/models/document.rb', line 194 def current_version versions.last.index end |
#date_range_json ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/models/document.rb', line 145 def date_range_json date_ranges = [] unless send(GeoblacklightAdmin::Schema.instance.solr_fields[:date_range]).all?(&:blank?) send(GeoblacklightAdmin::Schema.instance.solr_fields[:date_range]).each do |date_range| start_d, end_d = date_range.split("-") start_d = "*" if start_d == "YYYY" || start_d.nil? end_d = "*" if end_d == "YYYY" || end_d.nil? date_ranges << "[#{start_d} TO #{end_d}]" if start_d.present? end end date_ranges end |
#dct_references_s_to_csv(key, destination) ⇒ Object
186 187 188 189 190 191 192 |
# File 'app/models/document.rb', line 186 def dct_references_s_to_csv(key, destination) send(destination).detect do |ref| ref.category == GeoblacklightAdmin::Schema.instance.dct_references_mappings[key] end.value rescue NoMethodError nil end |
#dct_title_s ⇒ Object
Ensures a manually created “title” makes it into the attr_json “title”
141 142 143 |
# File 'app/models/document.rb', line 141 def dct_title_s title end |
#derive_dcat_bbox ⇒ Object
Convert GEOM for Solr Indexing
236 237 238 239 240 241 242 243 244 |
# File 'app/models/document.rb', line 236 def derive_dcat_bbox if send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).present? # "W,S,E,N" convert to "ENVELOPE(W,E,N,S)" w, s, e, n = send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).split(",") "ENVELOPE(#{w},#{e},#{n},#{s})" else "" end end |
#derive_dcat_centroid ⇒ Object
246 247 248 249 250 251 252 253 |
# File 'app/models/document.rb', line 246 def derive_dcat_centroid if send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).present? w, s, e, n = send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).split(",") "#{(n.to_f + s.to_f) / 2},#{(e.to_f + w.to_f) / 2}" else "" end end |
#derive_locn_geometry ⇒ Object
203 204 205 206 207 208 209 210 211 |
# File 'app/models/document.rb', line 203 def derive_locn_geometry if send(GeoblacklightAdmin::Schema.instance.solr_fields[:geometry]).present? send(GeoblacklightAdmin::Schema.instance.solr_fields[:geometry]) elsif send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).present? derive_polygon else "" end end |
#derive_polygon ⇒ Object
Convert BBOX to GEOM Polygon
214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'app/models/document.rb', line 214 def derive_polygon if send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).present? # Guard against a whole world polygons if send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]) == "-180,-90,180,90" "ENVELOPE(-180,180,90,-90)" else # "W,S,E,N" convert to "POLYGON((W N, E N, E S, W S, W N))" w, s, e, n = send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).split(",") "POLYGON((#{w} #{n}, #{e} #{n}, #{e} #{s}, #{w} #{s}, #{w} #{n}))" end else "" end end |
#download_text(format) ⇒ Object
Wraps download text with proper_case_format
113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/document.rb', line 113 def download_text(format) download_format = proper_case_format(format) prefix = "Original " begin format = download_format rescue # Need to rescue if format doesn't exist end value = prefix + format.to_s value.html_safe end |
#gbl_mdModified_dt ⇒ Object
136 137 138 |
# File 'app/models/document.rb', line 136 def gbl_mdModified_dt updated_at&.utc&.iso8601 end |
#iso_language_mapping ⇒ Object
Convert three char language code to proper string
256 257 258 259 260 261 262 263 264 265 |
# File 'app/models/document.rb', line 256 def iso_language_mapping mapping = [] if send(GeoblacklightAdmin::Schema.instance.solr_fields[:language]).present? send(GeoblacklightAdmin::Schema.instance.solr_fields[:language]).each do |lang| mapping << GeoblacklightAdmin::IsoLanguageCodes.call[lang] end end mapping end |
#multiple_downloads_array ⇒ Object
94 95 96 |
# File 'app/models/document.rb', line 94 def multiple_downloads_array document_downloads.collect { |d| {label: d.label, url: d.value} } end |
#proper_case_format(format) ⇒ Object
From GBL
Looks up properly formatted names for formats
102 103 104 105 106 107 108 |
# File 'app/models/document.rb', line 102 def proper_case_format(format) if I18n.exists?("geoblacklight.formats.#{format.to_s.parameterize(separator: "_")}") I18n.t("geoblacklight.formats.#{format.to_s.parameterize(separator: "_")}") else format end end |
#references_json ⇒ Object
Index Transformations - *_json functions
71 72 73 74 75 76 77 78 |
# File 'app/models/document.rb', line 71 def references_json references = ActiveSupport::HashWithIndifferentAccess.new send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref| references[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = ref.value end references = apply_downloads(references) references.to_json end |
#set_geometry ⇒ Object
229 230 231 232 233 |
# File 'app/models/document.rb', line 229 def set_geometry return unless locn_geometry.blank? && self&.dcat_bbox&.present? self.locn_geometry = derive_polygon end |
#solr_year_json ⇒ Object Also known as: gbl_indexYear_im
158 159 160 161 162 163 |
# File 'app/models/document.rb', line 158 def solr_year_json return [] if send(GeoblacklightAdmin::Schema.instance.solr_fields[:date_range]).blank? start_d, _end_d = send(GeoblacklightAdmin::Schema.instance.solr_fields[:date_range]).first.split("-") [start_d] if start_d.presence end |
#state_machine ⇒ Object
30 31 32 |
# File 'app/models/document.rb', line 30 def state_machine @state_machine ||= DocumentStateMachine.new(self, transition_class: DocumentTransition) end |
#to_csv ⇒ Object
Export Transformations - to_*
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/models/document.rb', line 167 def to_csv attributes = GeoblacklightAdmin::Schema.instance.exportable_fields attributes.map do |key, value| if value[:delimited] send(value[:destination])&.join("|") elsif value[:destination] == "dct_references_s" dct_references_s_to_csv(key, value[:destination]) elsif value[:destination] == "b1g_publication_state_s" send(:current_state) else send(value[:destination]) end end end |
#to_traject ⇒ Object
182 183 184 |
# File 'app/models/document.rb', line 182 def to_traject Kithe::Model.find_by_friendlier_id(friendlier_id).update_index(writer: Traject::DebugWriter.new({})) end |