Class: ObservationMatrixRowItem::Dynamic::TaxonName

Inherits:
ObservationMatrixRowItem::Dynamic show all
Defined in:
app/models/observation_matrix_row_item/dynamic/taxon_name.rb

Overview

The intent is to capture all OTUs, CollectionObjects (via Determinations), and Extracts (via taxon_name_id) linked through a TaxonName Hierarchy

Constant Summary

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary

Attributes inherited from ObservationMatrixRowItem

#observation_matrix_id, #observation_object_id, #observation_object_type, #position

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ObservationMatrixRowItem::Dynamic

#is_dynamic?

Methods inherited from ObservationMatrixRowItem

batch_create, batch_create_from_pinboard, batch_create_from_tags, #cleanup_matrix_rows, #cleanup_single_matrix_row, create_for_pinboard_items, create_for_tags, #decrement_matrix_row_reference_count, #find_or_build_row, human_name, #increment_matrix_row_reference_count, #matrix_row_item_object, #object_is?, subclass_attributes, #update_matrix_rows, #update_single_matrix_row

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Notes

#concatenated_notes_string, #reject_notes

Methods included from Shared::Tags

#reject_tags, #tag_with, #tagged?, #tagged_with?

Methods included from Shared::Identifiers

#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uri, #uuid

Methods included from Shared::Citations

#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Class Method Details

.cleanup(taxon_name_id, otu_id) ⇒ Object



28
29
30
31
32
33
# File 'app/models/observation_matrix_row_item/dynamic/taxon_name.rb', line 28

def self.cleanup(taxon_name_id, otu_id)
  to_check = ::TaxonName.find(observation_object_id).self_and_ancestors.pluck(:id)
  self.where(taxon_name_id: to_check).each do |mri|
    mri.update_matrix_rows
  end
end

Instance Method Details

#observation_objectsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/observation_matrix_row_item/dynamic/taxon_name.rb', line 7

def observation_objects
  a = ::Otu.joins(:taxon_name).where(taxon_name: observation_object.self_and_descendants)
  b = ::Queries::CollectionObject::Filter.new(
    taxon_name_id: observation_object_id,
    descendants: true,
    project_id:).all
  c = ::Queries::Extract::Filter.new(
    taxon_name_id: observation_object_id,
    descendants: true,
    project_id:).all

  if a.count > 10000 or b.count > 10000 or c.count > 10000
    return []
  end

  a.to_a + b.to_a + c.to_a
end

#taxon_name_is_uniqueObject (private)



37
38
39
40
41
42
43
# File 'app/models/observation_matrix_row_item/dynamic/taxon_name.rb', line 37

def taxon_name_is_unique
  errors.add(:observation_object, 'is already taken') if ObservationMatrixRowItem::Dynamic::TaxonName.where.not(id:)
    .where(
      observation_object:,
      observation_matrix_id:,
    ).any?
end

#value_of_observation_object_typeObject (private)



45
46
47
# File 'app/models/observation_matrix_row_item/dynamic/taxon_name.rb', line 45

def value_of_observation_object_type
  errors.add(:observation_object) if observation_object_type != 'TaxonName'
end