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 collapse

DC_NAMESPACE =
'http://rs.tdwg.org/dwc/terms/'.freeze
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
].freeze
HEADER_CONVERTERS =
{
  'dwcClass' => 'class',
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Housekeeping

#has_polymorphic_relationship?

Class Method Details

.collection_objects_joinObject



49
50
51
52
53
54
55
# File 'app/models/dwc_occurrence.rb', line 49

def self.collection_objects_join
  a = arel_table
  b = ::CollectionObject.arel_table 
  j = a.join(b).on(a[:dwc_occurrence_object_type].eq('CollectionObject').and(a[:dwc_occurrence_object_id].eq(b[:id])))
  joins(j.join_sources)
#    joins("JOIN collection_objects on collection_objects.id = dwc_occurrences.dwc_occurrence_object_id AND dwc_occurrence_object_type = 'CollectionObject'")
end

.computed_columnsScope

Returns:

  • (Scope)


64
65
66
# File 'app/models/dwc_occurrence.rb', line 64

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

Instance Method Details

#basisObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/dwc_occurrence.rb', line 68

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

#set_basis_of_recordObject (protected)



89
90
91
# File 'app/models/dwc_occurrence.rb', line 89

def set_basis_of_record
  write_attribute(:basisOfRecord, basis)
end

#stale?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/dwc_occurrence.rb', line 83

def stale?
  dwc_occurrence_object.updated_at > updated_at
end