Class: DatasetRecord::DarwinCore::Occurrence::ImportProtonym
- Inherits:
-
Object
- Object
- DatasetRecord::DarwinCore::Occurrence::ImportProtonym
show all
- Defined in:
- app/models/dataset_record/darwin_core/occurrence.rb
Defined Under Namespace
Classes: CreateIfNotExists, MatchExisting
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.create_if_not_exists ⇒ Object
27
28
29
|
# File 'app/models/dataset_record/darwin_core/occurrence.rb', line 27
def self.create_if_not_exists
@create_if_not_exists ||= CreateIfNotExists.new
end
|
.match_existing ⇒ Object
31
32
33
|
# File 'app/models/dataset_record/darwin_core/occurrence.rb', line 31
def self.match_existing
@match_existing ||= MatchExisting.new
end
|
Instance Method Details
#execute(origins, parent, name) ⇒ Object
35
36
37
38
39
|
# File 'app/models/dataset_record/darwin_core/occurrence.rb', line 35
def execute(origins, parent, name)
protonym = get_protonym(parent, name)
raise DatasetRecord::DarwinCore::InvalidData.new(exception_args(origins, parent, name, protonym)) unless protonym&.persisted?
protonym
end
|
#get_protonym(parent, name) ⇒ Object
41
42
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
|
# File 'app/models/dataset_record/darwin_core/occurrence.rb', line 41
def get_protonym(parent, name)
name = name.except(:rank_class) if name[:rank_class].nil?
%I(name masculine_name feminine_name neuter_name).inject(nil) do |protonym, field|
break protonym unless protonym.nil?
potential_protonyms = Protonym.where(name.slice(:rank_class).merge({ field => name[:name], :parent => parent }))
if potential_protonyms.count > 1
if name[:cached_author]
potential_protonyms_narrowed = potential_protonyms.where(cached_author: name[:cached_author])
if name[:year_of_publication]
potential_protonyms_narrowed = potential_protonyms_narrowed.where(year_of_publication: name[:year_of_publication])
end
if potential_protonyms_narrowed.count == 1
potential_protonyms = potential_protonyms_narrowed
else
potential_protonym_strings = potential_protonyms.map { |proto| "[id: #{proto.id} #{proto.cached_html_name_and_author_year}]" }.join(', ')
raise DatasetRecord::DarwinCore::InvalidData.new(
{ "scientificName" => ["Multiple matches found for name #{name[:name]} and author name #{name[:cached_author]}, year #{name[:year_of_publication]}: #{potential_protonym_strings}"] }
)
end
else
return parent
end
end
p = potential_protonyms.first
if p.nil? && Protonym.where(name.slice(:rank_class).merge({ field => name[:name] })).where(project_id: parent.project_id).exists?
potential_protonyms = Protonym.where(name.slice(:rank_class, :cached_author, :year_of_publication).merge({ field => name[:name] }).compact).with_ancestor(parent)
if potential_protonyms.count > 1
return parent
end
p = potential_protonyms.first
if p.nil? && !parent.cached_is_valid
p = Protonym.where(name.slice(:rank_class).merge!({ field => name[:name] })).with_ancestor(parent.valid_taxon_name).first
end
end
p
end
end
|