Class: AssertedEnvironment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AssertedEnvironment
- Includes:
- Housekeeping, Shared::Citations, Shared::DataAttributes, Shared::DwcOccurrenceHooks, Shared::Identifiers, Shared::IsData, Shared::Notes, Shared::Tags
- Defined in:
- app/models/asserted_environment.rb
Overview
An AssertedEnvironment is the assertion that an environment, drawn from the Environment Ontology (ENVO), characterizes some record - see ENVIRONMENT_ASSERTABLE_TYPES for what those records can be.
Unlike AnatomicalPart, AssertedEnvironment does not accept a free-text
name - only ENVO-backed uri/uri_label pairs are permitted (see
Vendor::Envo). This is deliberate - we want to see how well ENVO alone can
hold up rather than accumulate uncontrolled local terms.
position provides a simple ordering, not a category - each larger
position is understood to be some refinement of the ones before it (e.g.
"terrestrial biome" then "temperate forest biome").
Instance Attribute Summary collapse
-
#asserted_environment_object_id ⇒ Integer
polymorphic object ID.
-
#asserted_environment_object_type ⇒ String
polymorphic object type.
-
#cached ⇒ String
cached uri_label.
-
#position ⇒ Integer
for acts_as_list, scoped to the asserted environment object; larger values are refinements of smaller ones.
-
#project_id ⇒ Integer
the project ID.
-
#uri ⇒ Object
Override the :uri defined by Identifiers, which otherwise shadows the asserted_environment's own
uricolumn/validations. -
#uri_label ⇒ String
the label of the ENVO term at uri.
Instance Method Summary collapse
- #asserted_environment_object_has_allowed_type ⇒ Object protected
-
#dwc_occurrences ⇒ Scope
DwcOccurrence records potentially affected by this asserted environment; only CollectingEvent assertions feed dwc:habitat (see Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object types have no corresponding DwcOccurrence records to rebuild.
- #set_cached ⇒ Object protected
- #uri_is_an_envo_term ⇒ Object protected
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_in_use?, #similar
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Shared::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uuid, #visible_identifiers_for
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
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
Instance Attribute Details
#asserted_environment_object_id ⇒ Integer
polymorphic object ID
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/asserted_environment.rb', line 43 class AssertedEnvironment < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DataAttributes include Shared::Identifiers # Override the :uri defined by Identifiers, which otherwise shadows the # asserted_environment's own `uri` column/validations. Bad, same as # AnatomicalPart. def uri self[:uri] end include Shared::Notes include Shared::Tags include Shared::DwcOccurrenceHooks include Shared::IsData acts_as_list scope: [:project_id, :asserted_environment_object_type, :asserted_environment_object_id] belongs_to :asserted_environment_object, polymorphic: true after_save :set_cached validates_presence_of :asserted_environment_object validates_presence_of :uri validates_presence_of :uri_label validate :asserted_environment_object_has_allowed_type validate :uri_is_an_envo_term validates_uniqueness_of :uri, scope: [ :project_id, :asserted_environment_object_type, :asserted_environment_object_id ] # @return [Scope] # DwcOccurrence records potentially affected by this asserted environment; # only CollectingEvent assertions feed dwc:habitat (see # Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object # types have no corresponding DwcOccurrence records to rebuild. def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end protected def set_cached update_column(:cached, uri_label) end def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end end |
#asserted_environment_object_type ⇒ String
polymorphic object type
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/asserted_environment.rb', line 43 class AssertedEnvironment < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DataAttributes include Shared::Identifiers # Override the :uri defined by Identifiers, which otherwise shadows the # asserted_environment's own `uri` column/validations. Bad, same as # AnatomicalPart. def uri self[:uri] end include Shared::Notes include Shared::Tags include Shared::DwcOccurrenceHooks include Shared::IsData acts_as_list scope: [:project_id, :asserted_environment_object_type, :asserted_environment_object_id] belongs_to :asserted_environment_object, polymorphic: true after_save :set_cached validates_presence_of :asserted_environment_object validates_presence_of :uri validates_presence_of :uri_label validate :asserted_environment_object_has_allowed_type validate :uri_is_an_envo_term validates_uniqueness_of :uri, scope: [ :project_id, :asserted_environment_object_type, :asserted_environment_object_id ] # @return [Scope] # DwcOccurrence records potentially affected by this asserted environment; # only CollectingEvent assertions feed dwc:habitat (see # Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object # types have no corresponding DwcOccurrence records to rebuild. def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end protected def set_cached update_column(:cached, uri_label) end def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end end |
#cached ⇒ String
cached uri_label
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/asserted_environment.rb', line 43 class AssertedEnvironment < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DataAttributes include Shared::Identifiers # Override the :uri defined by Identifiers, which otherwise shadows the # asserted_environment's own `uri` column/validations. Bad, same as # AnatomicalPart. def uri self[:uri] end include Shared::Notes include Shared::Tags include Shared::DwcOccurrenceHooks include Shared::IsData acts_as_list scope: [:project_id, :asserted_environment_object_type, :asserted_environment_object_id] belongs_to :asserted_environment_object, polymorphic: true after_save :set_cached validates_presence_of :asserted_environment_object validates_presence_of :uri validates_presence_of :uri_label validate :asserted_environment_object_has_allowed_type validate :uri_is_an_envo_term validates_uniqueness_of :uri, scope: [ :project_id, :asserted_environment_object_type, :asserted_environment_object_id ] # @return [Scope] # DwcOccurrence records potentially affected by this asserted environment; # only CollectingEvent assertions feed dwc:habitat (see # Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object # types have no corresponding DwcOccurrence records to rebuild. def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end protected def set_cached update_column(:cached, uri_label) end def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end end |
#position ⇒ Integer
for acts_as_list, scoped to the asserted environment object; larger values are refinements of smaller ones
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/asserted_environment.rb', line 43 class AssertedEnvironment < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DataAttributes include Shared::Identifiers # Override the :uri defined by Identifiers, which otherwise shadows the # asserted_environment's own `uri` column/validations. Bad, same as # AnatomicalPart. def uri self[:uri] end include Shared::Notes include Shared::Tags include Shared::DwcOccurrenceHooks include Shared::IsData acts_as_list scope: [:project_id, :asserted_environment_object_type, :asserted_environment_object_id] belongs_to :asserted_environment_object, polymorphic: true after_save :set_cached validates_presence_of :asserted_environment_object validates_presence_of :uri validates_presence_of :uri_label validate :asserted_environment_object_has_allowed_type validate :uri_is_an_envo_term validates_uniqueness_of :uri, scope: [ :project_id, :asserted_environment_object_type, :asserted_environment_object_id ] # @return [Scope] # DwcOccurrence records potentially affected by this asserted environment; # only CollectingEvent assertions feed dwc:habitat (see # Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object # types have no corresponding DwcOccurrence records to rebuild. def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end protected def set_cached update_column(:cached, uri_label) end def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end end |
#project_id ⇒ Integer
the project ID
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/asserted_environment.rb', line 43 class AssertedEnvironment < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DataAttributes include Shared::Identifiers # Override the :uri defined by Identifiers, which otherwise shadows the # asserted_environment's own `uri` column/validations. Bad, same as # AnatomicalPart. def uri self[:uri] end include Shared::Notes include Shared::Tags include Shared::DwcOccurrenceHooks include Shared::IsData acts_as_list scope: [:project_id, :asserted_environment_object_type, :asserted_environment_object_id] belongs_to :asserted_environment_object, polymorphic: true after_save :set_cached validates_presence_of :asserted_environment_object validates_presence_of :uri validates_presence_of :uri_label validate :asserted_environment_object_has_allowed_type validate :uri_is_an_envo_term validates_uniqueness_of :uri, scope: [ :project_id, :asserted_environment_object_type, :asserted_environment_object_id ] # @return [Scope] # DwcOccurrence records potentially affected by this asserted environment; # only CollectingEvent assertions feed dwc:habitat (see # Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object # types have no corresponding DwcOccurrence records to rebuild. def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end protected def set_cached update_column(:cached, uri_label) end def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end end |
#uri ⇒ Object
Override the :uri defined by Identifiers, which otherwise shadows the
asserted_environment's own uri column/validations. Bad, same as
AnatomicalPart.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/asserted_environment.rb', line 43 class AssertedEnvironment < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DataAttributes include Shared::Identifiers # Override the :uri defined by Identifiers, which otherwise shadows the # asserted_environment's own `uri` column/validations. Bad, same as # AnatomicalPart. def uri self[:uri] end include Shared::Notes include Shared::Tags include Shared::DwcOccurrenceHooks include Shared::IsData acts_as_list scope: [:project_id, :asserted_environment_object_type, :asserted_environment_object_id] belongs_to :asserted_environment_object, polymorphic: true after_save :set_cached validates_presence_of :asserted_environment_object validates_presence_of :uri validates_presence_of :uri_label validate :asserted_environment_object_has_allowed_type validate :uri_is_an_envo_term validates_uniqueness_of :uri, scope: [ :project_id, :asserted_environment_object_type, :asserted_environment_object_id ] # @return [Scope] # DwcOccurrence records potentially affected by this asserted environment; # only CollectingEvent assertions feed dwc:habitat (see # Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object # types have no corresponding DwcOccurrence records to rebuild. def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end protected def set_cached update_column(:cached, uri_label) end def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end end |
#uri_label ⇒ String
the label of the ENVO term at uri
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/asserted_environment.rb', line 43 class AssertedEnvironment < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DataAttributes include Shared::Identifiers # Override the :uri defined by Identifiers, which otherwise shadows the # asserted_environment's own `uri` column/validations. Bad, same as # AnatomicalPart. def uri self[:uri] end include Shared::Notes include Shared::Tags include Shared::DwcOccurrenceHooks include Shared::IsData acts_as_list scope: [:project_id, :asserted_environment_object_type, :asserted_environment_object_id] belongs_to :asserted_environment_object, polymorphic: true after_save :set_cached validates_presence_of :asserted_environment_object validates_presence_of :uri validates_presence_of :uri_label validate :asserted_environment_object_has_allowed_type validate :uri_is_an_envo_term validates_uniqueness_of :uri, scope: [ :project_id, :asserted_environment_object_type, :asserted_environment_object_id ] # @return [Scope] # DwcOccurrence records potentially affected by this asserted environment; # only CollectingEvent assertions feed dwc:habitat (see # Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object # types have no corresponding DwcOccurrence records to rebuild. def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end protected def set_cached update_column(:cached, uri_label) end def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end end |
Instance Method Details
#asserted_environment_object_has_allowed_type ⇒ Object (protected)
99 100 101 102 103 104 105 |
# File 'app/models/asserted_environment.rb', line 99 def asserted_environment_object_has_allowed_type t = asserted_environment_object_type&.to_s # STRING (not symbol) if !ENVIRONMENT_ASSERTABLE_TYPES.include?(t) errors.add(t || :base, " - the type of this asserted environment's object can only be one of #{ENVIRONMENT_ASSERTABLE_TYPES}, not '#{t}'") end end |
#dwc_occurrences ⇒ Scope
Returns DwcOccurrence records potentially affected by this asserted environment; only CollectingEvent assertions feed dwc:habitat (see Shared::Dwc::CollectingEventExtensions#dwc_habitat), so other object types have no corresponding DwcOccurrence records to rebuild.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/asserted_environment.rb', line 79 def dwc_occurrences return DwcOccurrence.none unless asserted_environment_object_type == 'CollectingEvent' a = DwcOccurrence .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'") .where(co: {collecting_event_id: asserted_environment_object_id}) b = DwcOccurrence .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'") .where(fo: {collecting_event_id: asserted_environment_object_id}) ::Queries.union(DwcOccurrence, [a, b]) end |
#set_cached ⇒ Object (protected)
95 96 97 |
# File 'app/models/asserted_environment.rb', line 95 def set_cached update_column(:cached, uri_label) end |
#uri_is_an_envo_term ⇒ Object (protected)
107 108 109 110 111 |
# File 'app/models/asserted_environment.rb', line 107 def uri_is_an_envo_term return if uri.blank? errors.add(:uri, 'must be an ENVO term URI') unless Vendor::Envo.valid_uri?(uri) end |