Class: DwcOccurrence

Inherits:
ApplicationRecord show all
Includes:
Housekeeping
Defined in:
app/models/dwc_occurrence.rb

Overview

A Darwin Core Record for the Occurence core. Field generated from Ruby dwc-meta, which references the same spec that is used in the IPT, and the Dwc Assistant. Each record references a specific CollectionObject or AssertedDistribution.

Important: This is a cache/index, data here are periodically (regenerated) from multiple tables in TW.

TODO: The basisOfRecord CVTs are not super informative.

We know collection object is definitely 1:1 with PreservedSpecimen, however
AssertedDistribution could be HumanObservation (if source is person), or ... what? if
its a published record.  Seems we need a 'PublishedAssertation', just like we model the data.

DWC attributes are camelCase to facilitate matching dwcClass is a replacement for the Rails reserved 'Class'

All DC attributes (attributes not in DwcOccurrence::TW_ATTRIBUTES) in this table are namespaced to dc (“purl.org/dc/terms/”, “rs.tdwg.org/dwc/terms/”)

Constant Summary

DC_NAMESPACE =
'http://rs.tdwg.org/dwc/terms/'
TW_ATTRIBUTES =

Not yet implemented, but likely needed ? :id

[
  :project_id,
  :created_at,
  :updated_at,
  :created_by_id,
  :updated_by_id,
  :dwc_occurrence_object_type,
  :dwc_occurence_object_id
]
HEADER_CONVERTERS =
{
  'dwcClass' => 'class',
}.freeze

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Class Method Details

+ (Object) collection_objects_join



49
50
51
# File 'app/models/dwc_occurrence.rb', line 49

def self.collection_objects_join
  joins("JOIN collection_objects c on c.id = dwc_occurrences.dwc_occurrence_object_id AND dwc_occurrence_object_type = 'CollectionObject'")
end

+ (Scope) computed_columns

Returns:

  • (Scope)


60
61
62
# File 'app/models/dwc_occurrence.rb', line 60

def self.computed_columns
  select(['id', 'basisOfRecord'] + CollectionObject::DwcExtensions::DWC_OCCURRENCE_MAP.keys)
end

Instance Method Details

- (Object) basis



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/dwc_occurrence.rb', line 64

def basis
  case dwc_occurrence_object_type
  when 'CollectionObject'
    return 'PreservedSpecimen'
  when 'AssertedDistribution'
    case dwc_occurrence_object.source.try(:type)
    when 'Source::Bibtex'
      return 'Occurrence'
    when 'Source::Human'
      return 'HumanObservation'
    end
  end
  'Undefined'
end

- (Object) set_basis_of_record (protected)



85
86
87
# File 'app/models/dwc_occurrence.rb', line 85

def set_basis_of_record
  write_attribute(:basisOfRecord, basis)
end

- (Boolean) stale?

Returns:

  • (Boolean)


79
80
81
# File 'app/models/dwc_occurrence.rb', line 79

def stale?
   dwc_occurrence_object.updated_at > updated_at
end