Class: DatasetRecord::DarwinCore::Occurrence::ImportProtonym::CreateIfNotExists

Inherits:
Object
  • Object
show all
Defined in:
app/models/dataset_record/darwin_core/occurrence.rb

Class Method Summary collapse

Class Method Details

.execute(origins, parent, name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/dataset_record/darwin_core/occurrence.rb', line 27

def self.execute(origins, parent, name)
  name.delete(:rank_class) if name[:rank_class].nil?
  Protonym.create_with(
    {also_create_otu: true}.merge!(name.except(:rank_class, :name))
  ).find_or_create_by(name.slice(:rank_class, :name).merge!({ parent: parent })).tap do |protonym|
    unless protonym&.persisted?
      raise DatasetRecord::DarwinCore::InvalidData.new({
        origins[name.object_id] => name[:rank_class].present? ?
        protonym.errors.messages.values.flatten :
        ["Rank for #{name[:name]} could not be determined. Please create this taxon name manually and retry."]
      })
    end
  end
end