Module: Shared::DwcRoleAgent

Extended by:
ActiveSupport::Concern
Includes:
DwcOccurrenceHooks
Included in:
Organization
Defined in:
app/models/concerns/shared/dwc_role_agent.rb

Overview

Occurrences whose collector or determiner roles use this agent.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.occurrences_for(agent) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/concerns/shared/dwc_role_agent.rb', line 11

def self.occurrences_for(agent)
  events = agent.roles.where(type: 'Collector', role_object_type: 'CollectingEvent').select(:role_object_id)
  determinations = TaxonDetermination.where(id: agent.roles.where(type: 'Determiner', role_object_type: 'TaxonDetermination').select(:role_object_id))

  scopes = [CollectionObject, FieldOccurrence].map do |model|
    determined_ids = determinations.where(taxon_determination_object_type: model.name).select(:taxon_determination_object_id)
    objects = model.where(collecting_event_id: events).or(model.where(id: determined_ids))
    DwcOccurrence.where(dwc_occurrence_object_type: model.name, dwc_occurrence_object_id: objects.select(:id))
  end
  ::Queries.union(DwcOccurrence, scopes)
end

Instance Method Details

#dwc_occurrences ⇒ Object



7
8
9
# File 'app/models/concerns/shared/dwc_role_agent.rb', line 7

def dwc_occurrences
  Shared::DwcRoleAgent.occurrences_for(self)
end