Module: CollectionObject::DwcExtensions
- Extended by:
- ActiveSupport::Concern
- Includes:
- TaxonworksExtensions, Shared::Dwc::CollectingEventExtensions, Shared::Dwc::TaxonDeterminationExtensions, Shared::IsDwcOccurrence
- Included in:
- CollectionObject, BiologicalCollectionObject
- Defined in:
- app/models/collection_object/dwc_extensions.rb
Defined Under Namespace
Modules: TaxonworksExtensions
Constant Summary
Constants included from Shared::IsDwcOccurrence
Shared::IsDwcOccurrence::DWC_DELIMITER, Shared::IsDwcOccurrence::VIEW_EXCLUSIONS
Instance Method Summary collapse
-
#api_image_link(image) ⇒ Object
TODO: likeley a helper.
- #dwc_associated_media ⇒ Object
- #dwc_associated_taxa ⇒ Object
- #dwc_caste ⇒ Object
- #dwc_catalog_number ⇒ Object
-
#dwc_collection_code ⇒ Object
TODO: optimize by finding all relevant identifiers in one query, then looping through them.
- #dwc_event_time ⇒ Object
- #dwc_higher_classification ⇒ Object
-
#dwc_individual_count ⇒ Object
TODO: handle ranged lots.
-
#dwc_institution_code ⇒ Object
we assert custody, NOT ownership.
-
#dwc_institution_id ⇒ Object
we assert custody, NOT ownership.
-
#dwc_internal_attribute_for(target = :collection_object, dwc_term_name) ⇒ Object
TODO: duplicated in CE extension.
-
#dwc_life_stage ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs.
- #dwc_occurrence_remarks ⇒ Object
- #dwc_occurrence_status ⇒ Object
- #dwc_other_catalog_numbers ⇒ Object
- #dwc_preparations ⇒ Object
- #dwc_record_number ⇒ Object
-
#dwc_sex ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs.
-
#dwc_type_status ⇒ Object
holotype of Ctenomys sociabilis.
-
#dwc_verbatim_label ⇒ Object
use buffered if any if not check CE verbatim_label.
- #is_fossil? ⇒ Boolean
Methods included from Shared::IsDwcOccurrence
#dwc_occurrence_attribute_values, #dwc_occurrence_attributes, #dwc_occurrence_id, #get_dwc_occurrence, #set_dwc_occurrence
Instance Method Details
#api_image_link(image) ⇒ Object
TODO: likeley a helper
156 157 158 159 160 161 162 163 164 165 |
# File 'app/models/collection_object/dwc_extensions.rb', line 156 def api_image_link(image) s = ENV['SERVER_NAME'] if s.nil? s ||= 'http://127.0.0.1:3000' else s = 'https://' + s end s = s + '/api/v1/images/' + image.image_file_fingerprint # An experiment, use md5 as a proxy for id (also unique id) end |
#dwc_associated_media ⇒ Object
146 147 148 |
# File 'app/models/collection_object/dwc_extensions.rb', line 146 def dwc_associated_media images.collect{|i| api_image_link(i) }.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_associated_taxa ⇒ Object
151 152 153 |
# File 'app/models/collection_object/dwc_extensions.rb', line 151 def dwc_associated_taxa dwc_internal_attribute_for(:collection_object, :associatedTaxa) end |
#dwc_caste ⇒ Object
244 245 246 247 |
# File 'app/models/collection_object/dwc_extensions.rb', line 244 def dwc_caste biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:caste]) .pluck(:name)&.join(', ').presence # TODO: Use delimeter! end |
#dwc_catalog_number ⇒ Object
177 178 179 |
# File 'app/models/collection_object/dwc_extensions.rb', line 177 def dwc_catalog_number catalog_number_cached # via delegation end |
#dwc_collection_code ⇒ Object
TODO: optimize by finding all relevant identifiers in one query, then looping through them
169 170 171 |
# File 'app/models/collection_object/dwc_extensions.rb', line 169 def dwc_collection_code catalog_number_namespace&.verbatim_short_name || catalog_number_namespace&.short_name end |
#dwc_event_time ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'app/models/collection_object/dwc_extensions.rb', line 286 def dwc_event_time return unless collecting_event %w{start_time end_time} .map { |t| %w{hour minute second} .map { |p| collecting_event["#{t}_#{p}"] } .map { |p| '%02d' % p if p } # At least two digits } .map { |t| t.compact.join(':') } .reject(&:blank?) .join('/').presence end |
#dwc_higher_classification ⇒ Object
260 261 262 263 264 265 266 |
# File 'app/models/collection_object/dwc_extensions.rb', line 260 def dwc_higher_classification v = taxonomy.values.collect{|a| a.kind_of?(Array) ? a.second : a} v.shift v.pop v.compact v.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_individual_count ⇒ Object
TODO: handle ranged lots
282 283 284 |
# File 'app/models/collection_object/dwc_extensions.rb', line 282 def dwc_individual_count total end |
#dwc_institution_code ⇒ Object
we assert custody, NOT ownership
271 272 273 |
# File 'app/models/collection_object/dwc_extensions.rb', line 271 def dwc_institution_code repository_acronym end |
#dwc_institution_id ⇒ Object
we assert custody, NOT ownership
276 277 278 279 |
# File 'app/models/collection_object/dwc_extensions.rb', line 276 def dwc_institution_id # TODO: identifiers on Repositories repository_url || repository_institutional_LSID end |
#dwc_internal_attribute_for(target = :collection_object, dwc_term_name) ⇒ Object
TODO: duplicated in CE extension
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'app/models/collection_object/dwc_extensions.rb', line 189 def dwc_internal_attribute_for(target = :collection_object, dwc_term_name) return nil if dwc_term_name.nil? case target when :collecting_event return nil unless collecting_event collecting_event.internal_attributes.includes(:predicate) .where( controlled_vocabulary_terms: {uri: ::DWC_ATTRIBUTE_URIS[dwc_term_name.to_sym] }) .pluck(:value)&.join(', ').presence when :collection_object internal_attributes.includes(:predicate) .where( controlled_vocabulary_terms: {uri: ::DWC_ATTRIBUTE_URIS[dwc_term_name.to_sym] }) .pluck(:value)&.join(', ').presence else nil end end |
#dwc_life_stage ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs
233 234 235 236 |
# File 'app/models/collection_object/dwc_extensions.rb', line 233 def dwc_life_stage biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:lifeStage]) .pluck(:name)&.join(', ').presence # `.presence` is a Rails extension end |
#dwc_occurrence_remarks ⇒ Object
141 142 143 |
# File 'app/models/collection_object/dwc_extensions.rb', line 141 def dwc_occurrence_remarks notes.collect{|n| n.text}&.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_occurrence_status ⇒ Object
136 137 138 |
# File 'app/models/collection_object/dwc_extensions.rb', line 136 def dwc_occurrence_status 'present' end |
#dwc_other_catalog_numbers ⇒ Object
181 182 183 184 185 |
# File 'app/models/collection_object/dwc_extensions.rb', line 181 def dwc_other_catalog_numbers i = identifiers.where.not('type ilike ?', 'Identifier::Global::Uuid%').order(:position).to_a i.shift i.map(&:cached).join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_preparations ⇒ Object
299 300 301 |
# File 'app/models/collection_object/dwc_extensions.rb', line 299 def dwc_preparations preparation_type_name end |
#dwc_record_number ⇒ Object
173 174 175 |
# File 'app/models/collection_object/dwc_extensions.rb', line 173 def dwc_record_number record_number_cached # via delegation end |
#dwc_sex ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs
239 240 241 242 |
# File 'app/models/collection_object/dwc_extensions.rb', line 239 def dwc_sex biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:sex]) .pluck(:name)&.join(', ').presence # TODO: Use delimeter! end |
#dwc_type_status ⇒ Object
holotype of Ctenomys sociabilis. Pearson O. P., and M. I. Christie. 1985. Historia Natural, 5(37):388, holotype of Pinus abies | holotype of Picea abies
254 255 256 257 258 |
# File 'app/models/collection_object/dwc_extensions.rb', line 254 def dwc_type_status type_materials.all.collect{|t| ApplicationController.helpers.label_for_type_material(t) }.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_verbatim_label ⇒ Object
use buffered if any if not check CE verbatim_label
130 131 132 133 134 |
# File 'app/models/collection_object/dwc_extensions.rb', line 130 def dwc_verbatim_label b = [buffered_collecting_event, buffered_determinations, buffered_other_labels].compact return b.join("\n\n") if b.present? collecting_event&.verbatim_label.presence end |
#is_fossil? ⇒ Boolean
249 250 251 |
# File 'app/models/collection_object/dwc_extensions.rb', line 249 def is_fossil? biocuration_classes.where(uri: DWC_FOSSIL_URI).any? end |