Module: Shared::IsDwcOccurrence

Extended by:
ActiveSupport::Concern
Included in:
AssertedDistribution, CollectionObject, CollectionObject::BiologicalCollectionObject
Defined in:
app/models/concerns/shared/is_dwc_occurrence.rb

Overview

Shared code for data classes that can be indexed/serialized as DwcOccurrence records

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DWC_DELIMITER =

These probably belong in a global helper

' | '
VIEW_EXCLUSIONS =
[
  :footprintWKT
]

Instance Method Summary collapse

Instance Method Details

#dwc_occurrence_attribute_values(mode = :all) ⇒ Array

Returns an array of the values presently computed for this occurrence.

Returns:

  • (Array)

    an array of the values presently computed for this occurrence



99
100
101
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 99

def dwc_occurrence_attribute_values(mode = :all)
  [id, dwc_occurrence.id] + self.class.dwc_attribute_vector(mode)[2..-1].collect{|a| a.name}.collect{|f| dwc_occurrence.send(f) }
end

#dwc_occurrence_attributes(taxonworks_fields = true) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 76

def dwc_occurrence_attributes(taxonworks_fields = true)
  a = {}
  self.class::DWC_OCCURRENCE_MAP.each do |k,v|
    a[k] = send(v)
  end

  a[:occurrenceID] = dwc_occurrence_id

  if taxonworks_fields
    a[:project_id] = project_id

    # TODO: semantics of these may need to be revisited, particularly updated_by_id
    a[:created_by_id] = created_by_id
    a[:updated_by_id] = updated_by_id

    a[:updated_at] = Time.now # !! Not applied via this key, but kept for reference, see `touch` in `set_dwc_occurrence`
  end

  a
end

#dwc_occurrence_idObject



72
73
74
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 72

def dwc_occurrence_id
  dwc_occurrence&.occurrence_identifier&.cached
end

#get_dwc_occurrenceDwcOccurrence

Returns does not rebuild if exists.

Returns:



105
106
107
108
109
110
111
112
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 105

def get_dwc_occurrence
  # TODO: why are extra queries fired if this is fired?
  if dwc_occurrence_persisted?
    dwc_occurrence
  else
    set_dwc_occurrence
  end
end

#set_dwc_occurrenceDwcOccurrence

Returns always touches the database.

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 50

def set_dwc_occurrence
  retried = false
  begin
    if dwc_occurrence_persisted?
      dwc_occurrence.generate_uuid_if_required
      dwc_occurrence.update_columns(dwc_occurrence_attributes)
      dwc_occurrence.touch(:updated_at)
    else
      create_dwc_occurrence!(dwc_occurrence_attributes)
    end
  rescue ActiveRecord::ActiveRecordError
    unless retried
      retried = true
      dwc_occurrence&.reload
      retry
    else
      raise
    end
  end
  dwc_occurrence
end