Module: Protonym::SoftValidationExtensions::Instance

Defined in:
app/models/protonym/soft_validation_extensions.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) sv_author_is_not_required



1024
1025
1026
1027
1028
# File 'app/models/protonym/soft_validation_extensions.rb', line 1024

def sv_author_is_not_required
  if self.verbatim_author && (!self.roles.empty? || (self.source && self.verbatim_author == self.source.authority_name))
    soft_validations.add(:verbatim_author, 'Verbatim author is not required, it is derived from the source and taxon name author roles', fix: :sv_fix_author_is_not_required, success_message: 'Taxon name verbatim author was deleted')
  end
end

- (Object) sv_extant_children



987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File 'app/models/protonym/soft_validation_extensions.rb', line 987

def sv_extant_children
  unless self.parent_id.blank?
    if self.is_fossil?
      taxa = Protonym.where(parent_id: self.id)
      z = 0
      unless taxa.empty?
        taxa.find_each do |t|
          soft_validations.add(:base, "Extinct taxon #{self.cached_html} has extant children") if !t.is_fossil? && z == 0
          z = 1
        end
      end
    end
  end
end

- (Object) sv_fix_add_nominotypical_sub



778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'app/models/protonym/soft_validation_extensions.rb', line 778

def sv_fix_add_nominotypical_sub
  rank  = rank_string
  p     = self.parent
  prank = p.rank_string
  if (rank =~ /Family/ && prank =~ /Family/) || (rank =~ /Genus/ && prank =~ /Genus/) || (rank =~ /Species/ && prank =~ /Species/)
    begin
      Protonym.transaction do
        if rank =~ /Family/ && prank =~ /Family/
          name = Protonym.family_group_base(self.parent.name)
          case self.rank_class.rank_name
          when 'subfamily'
            name += 'inae'
          when 'tribe'
            name += 'ini'
          when 'subtribe'
            name += 'ina'
          end
        else
          name = p.name
        end

        t = Protonym.new(name: name, rank_class: rank, verbatim_author: p.verbatim_author, year_of_publication: p.year_of_publication, source: p.source, parent: p)
        t.save
        t.soft_validate
        t.fix_soft_validations
        return true
      end
    rescue ActiveRecord::RecordInvalid # naked rescue is very bad
      return false
    end
  end
end

- (Object) sv_fix_author_is_not_required



1030
1031
1032
1033
# File 'app/models/protonym/soft_validation_extensions.rb', line 1030

def sv_fix_author_is_not_required
  self.update_column(:verbatim_author, nil)
  return true
end

- (Object) sv_fix_coordinated_names_author



229
230
231
232
233
234
235
236
237
238
# File 'app/models/protonym/soft_validation_extensions.rb', line 229

def sv_fix_coordinated_names_author
  return false unless self.verbatim_author.nil?
  list_of_coordinated_names.each do |t|
    if self.verbatim_author.nil? && !t.verbatim_author.nil?
      self.update_column(:verbatim_author, t.verbatim_author)
      return true
    end
  end
  return false
end

- (Object) sv_fix_coordinated_names_gender



266
267
268
269
270
271
272
273
274
275
# File 'app/models/protonym/soft_validation_extensions.rb', line 266

def sv_fix_coordinated_names_gender
  return false unless self.gender_class.nil?
  list_of_coordinated_names.each do |t|
    unless t.gender_class.nil?
      c = self.taxon_name_classifications.create(type: t.gender_class.to_s)
      return true if c.id
    end
  end
  return false
end

- (Object) sv_fix_coordinated_names_original_form



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'app/models/protonym/soft_validation_extensions.rb', line 456

def sv_fix_coordinated_names_original_form
  fixed = false
  return false unless self.original_form.nil?
  list_of_coordinated_names.each do |t|
    if !t.original_form.nil?
      self.original_form = t.original_form
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_original_genus



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'app/models/protonym/soft_validation_extensions.rb', line 306

def sv_fix_coordinated_names_original_genus
  fixed = false
  return false unless self.original_genus.nil?
  list_of_coordinated_names.each do |t|
    if !t.original_genus.nil?
      self.original_genus = t.original_genus
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_original_species



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'app/models/protonym/soft_validation_extensions.rb', line 366

def sv_fix_coordinated_names_original_species
  fixed = false
  return false unless self.original_species.nil?
  list_of_coordinated_names.each do |t|
    if !t.original_species.nil?
      self.original_species = t.original_species
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_original_subgenus



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'app/models/protonym/soft_validation_extensions.rb', line 336

def sv_fix_coordinated_names_original_subgenus
  fixed = false
  return false unless self.original_subgenus.nil?
  list_of_coordinated_names.each do |t|
    if !t.original_subgenus.nil?
      self.original_subgenus = t.original_subgenus
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_original_subspecies



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'app/models/protonym/soft_validation_extensions.rb', line 396

def sv_fix_coordinated_names_original_subspecies
  fixed = false
  return false unless self.original_subspecies.nil?
  list_of_coordinated_names.each do |t|
    if !t.original_subspecies.nil?
      self.original_subspecies = t.original_subspecies
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_original_variety



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'app/models/protonym/soft_validation_extensions.rb', line 426

def sv_fix_coordinated_names_original_variety
  fixed = false
  return false unless self.original_variety.nil?
  list_of_coordinated_names.each do |t|
    if !t.original_variety.nil?
      self.original_variety = t.original_variety
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_part_of_speach



286
287
288
289
290
291
292
293
294
295
# File 'app/models/protonym/soft_validation_extensions.rb', line 286

def sv_fix_coordinated_names_part_of_speach
  return false unless self.part_of_speech_class.nil?
  list_of_coordinated_names.each do |t|
    unless t.part_of_speech_class.nil?
      c = self.taxon_name_classifications.create(type: t.part_of_speech_class.to_s)
      return true if c.id
    end
  end
  return false
end

- (Object) sv_fix_coordinated_names_source



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'app/models/protonym/soft_validation_extensions.rb', line 202

def sv_fix_coordinated_names_source
  fixed = false
  return false unless self.source.nil?
    list_of_coordinated_names.each do |t|
      if !t.source.nil?
        self.source = t.source
        fixed = true
      end
    end
    if fixed
    begin
      Protonym.transaction do
        self.source.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_type_genus



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'app/models/protonym/soft_validation_extensions.rb', line 551

def sv_fix_coordinated_names_type_genus
  fixed = false
  return false unless self.type_genus.nil?
  list_of_coordinated_names.each do |t|
    if !t.type_genus.nil?
      self.type_genus = t.type_genus
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.type_genus.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_type_species



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'app/models/protonym/soft_validation_extensions.rb', line 486

def sv_fix_coordinated_names_type_species
  fixed = false
  return false unless self.type_species.nil?
  list_of_coordinated_names.each do |t|
    if !t.type_species.nil?
      self.type_species = t.type_species
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.type_species.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_type_species_type



519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'app/models/protonym/soft_validation_extensions.rb', line 519

def sv_fix_coordinated_names_type_species_type
  sttnr = self.type_taxon_name_relationship
  return false if sttnr.nil?
  fixed = false
  list_of_coordinated_names.each do |t|
    tttnr = t.type_taxon_name_relationship
    if !tttnr.nil? && sttnr.type != tttnr.type && sttnr.type.safe_constantize.descendants.collect{|i| i.to_s}.include?(tttnr.type.to_s)
      self.type_taxon_name_relationship.type = t.type_taxon_name_relationship.type
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.type_taxon_name_relationship.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_type_specimen



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'app/models/protonym/soft_validation_extensions.rb', line 581

def sv_fix_coordinated_names_type_specimen
  fixed = false
  return false unless self.get_primary_type.empty?
  list_of_coordinated_names.each do |t1|
    types2 = t1.get_primary_type
    if !types2.empty?
      new_type_material = []
      types2.each do |t|
        new_type_material.push({type_type: t.type_type, protonym_id: self.id, biological_object_id: t.biological_object_id, source: t.source})
      end
      self.type_materials.build(new_type_material)
      fixed = true
    end
  end
  if fixed
    begin
      Protonym.transaction do
        self.save
      end
      return true
    rescue
      return false
    end
  end
end

- (Object) sv_fix_coordinated_names_year



246
247
248
249
250
251
252
253
254
255
# File 'app/models/protonym/soft_validation_extensions.rb', line 246

def sv_fix_coordinated_names_year
  return false unless self.year_of_publication.nil?
  list_of_coordinated_names.each do |t|
    if self.year_of_publication.nil? && !t.year_of_publication.nil?
      self.update_column(:year_of_publication, t.year_of_publication)
      return true
    end
  end
  return false
end

- (Object) sv_fix_misspelling_author_is_not_required



1054
1055
1056
1057
# File 'app/models/protonym/soft_validation_extensions.rb', line 1054

def sv_fix_misspelling_author_is_not_required
  self.update_column(:verbatim_author, nil)
  return true
end

- (Object) sv_fix_misspelling_roles_are_not_required



1041
1042
1043
1044
1045
1046
# File 'app/models/protonym/soft_validation_extensions.rb', line 1041

def sv_fix_misspelling_roles_are_not_required
  self.roles.each do |r|
    r.destroy
  end
  return true
end

- (Object) sv_fix_misspelling_year_is_not_required



1065
1066
1067
1068
# File 'app/models/protonym/soft_validation_extensions.rb', line 1065

def sv_fix_misspelling_year_is_not_required
  self.update_column(:year_of_publication, nil)
  return true
end

- (Object) sv_fix_year_is_not_required



1019
1020
1021
1022
# File 'app/models/protonym/soft_validation_extensions.rb', line 1019

def sv_fix_year_is_not_required
  self.update_column(:year_of_publication, nil)
  return true
end

- (Object) sv_homotypic_synonyms



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
# File 'app/models/protonym/soft_validation_extensions.rb', line 830

def sv_homotypic_synonyms
  unless unavailable_or_invalid?
    if self.id == self.lowest_rank_coordinated_taxon.id
      possible_synonyms = []
      if rank_string =~ /Species/
        primary_types = self.get_primary_type
        unless primary_types.empty?
          p                 = primary_types.collect {|t| t.biological_object_id}
          possible_synonyms = Protonym.with_type_material_array(p).without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).not_self(self).with_project(self.project_id)
#              possible_synonyms = Protonym.with_type_material_array(p).that_is_valid.without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).not_self(self).with_project(self.project_id)
        end
      elsif rank_string =~ /Family/ && self.name == Protonym.family_group_base(self.name)
        # do nothing
      else
        type = self.type_taxon_name
        unless type.nil?
          possible_synonyms = Protonym.with_type_of_taxon_names(type.id).not_self(self).with_project(self.project_id)
#              possible_synonyms = Protonym.with_type_of_taxon_names(type.id).that_is_valid.not_self(self).with_project(self.project_id)
        end
      end

      possible_synonyms = reduce_list_of_synonyms(possible_synonyms)
      possible_synonyms.each do |s|
        soft_validations.add(:base, "Missing relationship: #{self.rank_class.rank_name} #{self.cached_html} should be a synonym of #{s.cached_html} #{s.cached_author_year} since they share the same type")
      end
    end
  end
end

- (Object) sv_missing_author



969
970
971
972
973
# File 'app/models/protonym/soft_validation_extensions.rb', line 969

def sv_missing_author
  if self.author_string.nil? && is_available?
    soft_validations.add(:verbatim_author, 'Author is missing', fix: :sv_fix_missing_author, success_message: 'Author was updated')
  end
end

- (Object) sv_missing_etymology



981
982
983
984
985
# File 'app/models/protonym/soft_validation_extensions.rb', line 981

def sv_missing_etymology
  if self.etymology.nil? && self.rank_string =~ /(Genus|Species)/ && is_available?
    soft_validations.add(:etymology, 'Etymology is missing')
  end
end

- (Object) sv_missing_gender



107
108
109
110
111
112
# File 'app/models/protonym/soft_validation_extensions.rb', line 107

def sv_missing_gender
  if is_genus_rank? && self.gender_class.nil? && !self.cached_misspelling && is_available?
    g = genus_suggested_gender
    soft_validations.add(:base, "Gender is not specified#{ g.nil? ? '' : ' (possible gender is ' + g + ')'}")
  end
end

- (Object) sv_missing_original_genus



950
951
952
953
954
# File 'app/models/protonym/soft_validation_extensions.rb', line 950

def sv_missing_original_genus
  if is_genus_or_species_rank? && self.original_genus.nil?
    soft_validations.add(:base, 'Missing relationship: Original genus is not selected')
  end
end

- (Object) sv_missing_part_of_speach



101
102
103
104
105
# File 'app/models/protonym/soft_validation_extensions.rb', line 101

def sv_missing_part_of_speach
  if is_species_rank? && self.part_of_speech_class.nil? && !has_misspelling_relationship? && is_available?
    soft_validations.add(:base, 'Part of speech is not specified. Please select if the name is a noun or an adjective.')
  end
end

- (Object) sv_missing_roles



1009
1010
1011
# File 'app/models/protonym/soft_validation_extensions.rb', line 1009

def sv_missing_roles
  soft_validations.add(:base, 'Taxon name author role is not selected') if self.roles.empty?
end

- (Object) sv_missing_substitute_name



93
94
95
96
97
98
99
# File 'app/models/protonym/soft_validation_extensions.rb', line 93

def sv_missing_substitute_name
  if !self.iczn_set_as_homonym_of.nil? || !TaxonNameClassification.where_taxon_name(self).with_type_string('TaxonNameClassification::Iczn::Available::Invalid::Homonym').empty?
    if self.iczn_set_as_synonym_of.nil? && is_available?
      soft_validations.add(:base, 'Missing relationship: The name is a homonym, but the substitute name is not selected')
    end
  end
end

- (Object) sv_missing_type_genus



87
88
89
90
91
# File 'app/models/protonym/soft_validation_extensions.rb', line 87

def sv_missing_type_genus
  if is_family_rank? && self.type_genus.nil? && is_available?
    soft_validations.add(:base, 'Missing relationship: Type genus is not selected')
  end
end

- (Object) sv_missing_type_species



81
82
83
84
85
# File 'app/models/protonym/soft_validation_extensions.rb', line 81

def sv_missing_type_species
  if is_genus_rank? && self.type_species.nil? && is_available?
    soft_validations.add(:base, 'Missing relationship: Type species is not selected')
  end
end

- (Object) sv_missing_year



975
976
977
978
979
# File 'app/models/protonym/soft_validation_extensions.rb', line 975

def sv_missing_year
  if self.year_integer.nil? && is_available?
    soft_validations.add(:year_of_publication, 'Year is missing', fix: :sv_fix_missing_year, success_message: 'Year was updated')
  end
end

- (Object) sv_misspelling_author_is_not_required



1048
1049
1050
1051
1052
# File 'app/models/protonym/soft_validation_extensions.rb', line 1048

def sv_misspelling_author_is_not_required
  if self.verbatim_author && self.source && (has_misspelling_relationship? || name_is_misapplied?)
    soft_validations.add(:verbatim_author, 'Verbatim author is not required for misspellings and misapplications', fix: :sv_fix_misspelling_author_is_not_required, success_message: 'Verbatim author was deleted')
  end
end

- (Object) sv_misspelling_roles_are_not_required



1035
1036
1037
1038
1039
# File 'app/models/protonym/soft_validation_extensions.rb', line 1035

def sv_misspelling_roles_are_not_required
  if !self.roles.empty? && self.source && (has_misspelling_relationship? || name_is_misapplied?)
    soft_validations.add(:base, 'Taxon name author role is not required for misspellings and misapplications', fix: :sv_fix_misspelling_roles_are_not_required, success_message: 'Roles were deleted')
  end
end

- (Object) sv_misspelling_year_is_not_required



1059
1060
1061
1062
1063
# File 'app/models/protonym/soft_validation_extensions.rb', line 1059

def sv_misspelling_year_is_not_required
  if self.year_of_publication && self.source && (has_misspelling_relationship? || name_is_misapplied?)
    soft_validations.add(:year_of_publication, 'Year is not required for misspellings and misapplications', fix: :sv_fix_misspelling_year_is_not_required, success_message: 'Year was deleted')
  end
end

- (Object) sv_original_combination_relationships



956
957
958
959
960
961
962
963
964
965
966
967
# File 'app/models/protonym/soft_validation_extensions.rb', line 956

def sv_original_combination_relationships
  relationships = self.original_combination_relationships
  unless relationships.empty?
    relationships = relationships.sort_by{|r| r.type_class.order_index }
    ids = relationships.collect{|r| r.subject_taxon_name_id}
    if !ids.include?(self.id)
      soft_validations.add(:base, "Missing relationship: The original rank of #{self.cached_html} is not specified in the original combination.")
    elsif ids.last != self.id
      soft_validations.add(:base, "Invalid original combination relationship: #{self.cached_html} should be moved to the lowest rank")
    end
  end
end

- (Object) sv_parent_priority



811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'app/models/protonym/soft_validation_extensions.rb', line 811

def sv_parent_priority
  if self.rank_class
    rank_group = self.rank_class.parent
    parent = self.parent

    if parent && rank_group == parent.rank_class.parent
      unless unavailable_or_invalid?
        date1 = self.nomenclature_date
        date2 = parent.nomenclature_date
        unless date1.nil? || date2.nil?
          if date1 < date2
            soft_validations.add(:base, "#{self.rank_class.rank_name.capitalize} #{self.cached_html_name_and_author_year} should not be older than parent #{parent.rank_class.rank_name} #{parent.cached_html_name_and_author_year}")
          end
        end
      end
    end
  end
end

- (Object) sv_potential_family_homonyms



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
# File 'app/models/protonym/soft_validation_extensions.rb', line 859

def sv_potential_family_homonyms
  if persisted? && is_family_rank? && is_available?
    if TaxonNameRelationship.where_subject_is_taxon_name(self).homonym_or_suppressed.empty?
      if self.id == self.lowest_rank_coordinated_taxon.id
#            name1 = self.cached_primary_homonym ? self.cached_primary_homonym : nil
#            possible_primary_homonyms = name1 ? Protonym.with_primary_homonym(name1).without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).without_homonym_or_suppressed.not_self(self).with_base_of_rank_class('NomenclaturalRank::Iczn::FamilyGroup').with_project(self.project_id) : []
#            list1 = reduce_list_of_synonyms(possible_primary_homonyms)
#            if !list1.empty?
#              list1.each do |s|
#                soft_validations.add(:base, "Missing relationship: #{self.cached_html_name_and_author_year} should be a homonym or duplicate of #{s.cached_html_name_and_author_year}")
#              end
#            else
          name2 = self.cached_primary_homonym_alternative_spelling ? self.cached_primary_homonym_alternative_spelling : nil
          possible_primary_homonyms_alternative_spelling = name2 ? Protonym.with_primary_homonym_alternative_spelling(name2).without_homonym_or_suppressed.without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).not_self(self).with_base_of_rank_class('NomenclaturalRank::Iczn::FamilyGroup').with_project(self.project_id) : []
          list2 = reduce_list_of_synonyms(possible_primary_homonyms_alternative_spelling)
          if !list2.empty?
            list2.each do |s|
              soft_validations.add(:base, "Missing relationship: #{self.cached_html_name_and_author_year} should be a homonym or duplicate of #{s.cached_html_name_and_author_year}")
            end
          end
 #           end
      end
    end

  end
end

- (Object) sv_potential_genus_homonyms



886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File 'app/models/protonym/soft_validation_extensions.rb', line 886

def sv_potential_genus_homonyms
  if persisted? && is_genus_rank? && is_available?
    if TaxonNameRelationship.where_subject_is_taxon_name(self).homonym_or_suppressed.empty?
      if self.id == self.lowest_rank_coordinated_taxon.id
        name1 = self.cached_primary_homonym ? self.cached_primary_homonym : nil
        possible_primary_homonyms = name1 ? Protonym.with_primary_homonym(name1).without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).without_homonym_or_suppressed.not_self(self).with_base_of_rank_class('NomenclaturalRank::Iczn::GenusGroup').with_project(self.project_id) : []
        list1 = reduce_list_of_synonyms(possible_primary_homonyms)
        if !list1.empty?
          list1.each do |s|
            soft_validations.add(:base, "Missing relationship: #{self.cached_html_name_and_author_year} should be a homonym or duplicate of #{s.cached_html_name_and_author_year}")
          end
        end
      end
    end
  end
end

- (Object) sv_potential_species_homonyms



903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
# File 'app/models/protonym/soft_validation_extensions.rb', line 903

def sv_potential_species_homonyms
  if persisted? && is_species_rank? && is_available?
    if TaxonNameRelationship.where_subject_is_taxon_name(self).homonym_or_suppressed.empty?
      if self.id == self.lowest_rank_coordinated_taxon.id
        name1 = self.cached_primary_homonym ? self.cached_primary_homonym : nil
        possible_primary_homonyms = name1 ? Protonym.with_primary_homonym(name1).without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).without_homonym_or_suppressed.not_self(self).with_base_of_rank_class('NomenclaturalRank::Iczn::SpeciesGroup').with_project(self.project_id) : []
        list1 = reduce_list_of_synonyms(possible_primary_homonyms)
        if !list1.empty?
          list1.each do |s|
            soft_validations.add(:base, "Missing relationship: #{self.cached_html_name_and_author_year} should be a primary homonym or duplicate of #{s.cached_html_name_and_author_year}")
            #  fix: :sv_fix_add_relationship('iczn_set_as_primary_homonym_of'.to_sym, s.id),
            #  success_message: 'Primary homonym relationship was added',
            #  failure_message: 'Fail to add a relationship')
          end
        else
          name2 = self.cached_primary_homonym_alternative_spelling ? self.cached_primary_homonym_alternative_spelling : nil
          possible_primary_homonyms_alternative_spelling = name2 ? Protonym.with_primary_homonym_alternative_spelling(name2).without_homonym_or_suppressed.without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).not_self(self).with_base_of_rank_class('NomenclaturalRank::Iczn::SpeciesGroup').with_project(self.project_id) : []
          list2 = reduce_list_of_synonyms(possible_primary_homonyms_alternative_spelling)
          if !list2.empty?
            list2.each do |s|
              soft_validations.add(:base, "Missing relationship: #{self.cached_html_name_and_author_year} could be a primary homonym of #{s.cached_html_name_and_author_year} (alternative spelling)")
            end
          else
            name3 = self.cached_secondary_homonym ? self.cached_secondary_homonym : nil
            possible_secondary_homonyms = name3 ? Protonym.with_secondary_homonym(name3).without_homonym_or_suppressed.without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).not_self(self).with_base_of_rank_class('NomenclaturalRank::Iczn::SpeciesGroup').with_project(self.project_id) : []
            list3 = reduce_list_of_synonyms(possible_secondary_homonyms)
            if !list3.empty?
              list3.each do |s|
                soft_validations.add(:base, "Missing relationship: #{self.cached_html_name_and_author_year} should be a secondary homonym or duplicate of #{s.cached_html_name_and_author_year}")
              end
            else
              name4 = self.cached_secondary_homonym ? self.cached_secondary_homonym_alternative_spelling : nil
              possible_secondary_homonyms_alternative_spelling = name4 ? Protonym.with_secondary_homonym_alternative_spelling(name4).without_homonym_or_suppressed.without_taxon_name_classification_array(TAXON_NAME_CLASS_NAMES_UNAVAILABLE_AND_INVALID).not_self(self).with_base_of_rank_class('NomenclaturalRank::Iczn::SpeciesGroup').with_project(self.project_id) : []
              list4 = reduce_list_of_synonyms(possible_secondary_homonyms_alternative_spelling)
              if !list4.empty?
                list4.each do |s|
                  soft_validations.add(:base, "Missing relationship: #{self.cached_html_name_and_author_year} could be a secondary homonym of #{s.cached_html_name_and_author_year} (alternative spelling)")
                end
              end
            end
          end
        end
      end
    end
  end
end

- (Object) sv_primary_types



728
729
730
731
732
733
734
735
736
# File 'app/models/protonym/soft_validation_extensions.rb', line 728

def sv_primary_types
  if is_species_rank? && is_available?
    if self.type_materials.primary.empty? && self.type_materials.syntypes.empty?
      soft_validations.add(:base, 'Primary type is not selected')
    elsif self.type_materials.primary.count > 1 || (!self.type_materials.primary.empty? && !self.type_materials.syntypes.empty?)
      soft_validations.add(:base, 'More than one of primary types are selected. Uncheck the specimens which are not primary types for this taxon')
    end
  end
end

- (Object) sv_primary_types_repository



738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'app/models/protonym/soft_validation_extensions.rb', line 738

def sv_primary_types_repository
  if is_species_rank?
    s = self.type_materials
    unless s.empty?
      s.primary.each do |t|
        soft_validations.add(:base, 'Primary type repository is not set') if t.material.try(:repository).nil?
      end
      s.syntypes.each do |t|
        soft_validations.add(:base, 'Syntype repository is not set') if t.material.try(:repository).nil?
      end
    end
  end
end

- (Object) sv_protonym_to_combination



1002
1003
1004
1005
1006
1007
# File 'app/models/protonym/soft_validation_extensions.rb', line 1002

def sv_protonym_to_combination
  if convertable_to_combination?
    soft_validations.add(:base, "Invalid #{self.cached_original_combination_html} could be converted into a Combination",
                         fix: :becomes_combination, success_message: "Protonym #{self.cached_original_combination_html} was successfully converted into a combination", fix_trigger: :requested)
  end
end

- (Object) sv_single_sub_taxon



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'app/models/protonym/soft_validation_extensions.rb', line 752

def sv_single_sub_taxon
  if self.rank_class
    rank = rank_string
    if rank != 'potentially_validating rank' && self.rank_class.nomenclatural_code == :iczn && %w(subspecies subgenus subtribe tribe subfamily).include?(self.rank_class.rank_name)
      sisters = self.parent.descendants.with_rank_class(rank).select{|t| t.id == t.cached_valid_taxon_name_id}
      if rank =~ /Family/
        z = Protonym.family_group_base(self.name)
        search_name = z.nil? ? nil : Protonym::FAMILY_GROUP_ENDINGS.collect{|i| z+i}
        a = sisters.collect{|i| Protonym.family_group_base(i.name) }
        sister_names = a.collect{|z| Protonym::FAMILY_GROUP_ENDINGS.collect{|i| z+i} }.flatten
      else
        search_name = [self.name]
        sister_names = sisters.collect{|i| i.name }
      end
      if search_name.include?(self.parent.name) && sisters.count == 1
        soft_validations.add(:base, "#{self.cached_html} is a single #{self.rank_class.rank_name} in the nominal #{self.parent.rank_class.rank_name} #{self.parent.cached_html}")
      elsif !sister_names.include?(self.parent.name) && !sisters.empty? && self.parent.name == Protonym.family_group_base(self.parent.name) && rank =~ /Family/
        # do nothing
      elsif !sister_names.include?(self.parent.name) && !sisters.empty?
        soft_validations.add(:base, "The parent #{self.parent.rank_class.rank_name} #{self.parent.cached_html} of this #{self.rank_class.rank_name} does not contain nominotypical #{self.rank_class.rank_name} #{self.parent.name}",
                             fix: :sv_fix_add_nominotypical_sub, success_message: "Nominotypical #{self.rank_class.rank_name} #{self.parent.name} was added to nominal #{self.parent.rank_class.rank_name} #{self.parent.name}")
      end
    end
  end
end

- (Object) sv_source_not_older_then_description



65
66
67
68
69
# File 'app/models/protonym/soft_validation_extensions.rb', line 65

def sv_source_not_older_then_description
  if self.source && self.year_of_publication
    soft_validations.add(:base, 'The year of publication of the taxon and the year in the original reference do not match') if self.try(:source).try(:year) != self.year_of_publication
  end
end

- (Object) sv_species_gender_agreement



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/models/protonym/soft_validation_extensions.rb', line 114

def sv_species_gender_agreement
  if is_species_rank?
    s = part_of_speech_name
    if !s.nil? && is_available?
      if %w{adjective participle}.include?(s)
        if !feminine_name.blank? && !masculine_name.blank? && !neuter_name.blank? && name != masculine_name && name != feminine_name && name != neuter_name
          soft_validations.add(:base, 'Species name does not match with either of three alternative forms')
        else
          if feminine_name.blank?
            soft_validations.add(:feminine_name, "The species name is marked as #{part_of_speech_name}, but the name spelling in feminine is not provided")
          else
            e = species_questionable_ending(TaxonNameClassification::Latinized::Gender::Feminine, feminine_name)
            soft_validations.add(:feminine_name, "Name has a non feminine ending: -#{e}") unless e.nil?
          end

          if masculine_name.blank?
            soft_validations.add(:masculine_name, "The species name is marked as #{part_of_speech_name}, but the name spelling in masculine is not provided")
          else
            e = species_questionable_ending(TaxonNameClassification::Latinized::Gender::Masculine, masculine_name)
            soft_validations.add(:masculine_name, "Name has a non masculine ending: -#{e}") unless e.nil?
          end

          if neuter_name.blank?
            soft_validations.add(:neuter_name, "The species name is marked as #{part_of_speech_name}, but the name spelling in neuter is not provided")
          else
            e = species_questionable_ending(TaxonNameClassification::Latinized::Gender::Neuter, neuter_name)
            soft_validations.add(:neuter_name, "Name has a non neuter ending: -#{e}") unless e.nil?
          end
        end
      end
    end
  end
end

- (Object) sv_species_gender_agreement_not_required



148
149
150
151
152
153
154
155
156
157
# File 'app/models/protonym/soft_validation_extensions.rb', line 148

def sv_species_gender_agreement_not_required
  if is_species_rank? && ((!feminine_name.blank? || !masculine_name.blank? || !neuter_name.blank?)) && is_available?
    s = part_of_speech_name
    if !s.nil? && !%w{adjective participle}.include?(s)
      soft_validations.add(:feminine_name, 'Alternative spelling is not required for the name which is not adjective or participle.') unless feminine_name.blank?
      soft_validations.add(:masculine_name, 'Alternative spelling is not required for the name which is not adjective or participle.')  unless masculine_name.blank?
      soft_validations.add(:neuter_name, 'Alternative spelling is not required for the name which is not adjective or participle.')  unless neuter_name.blank?
    end
  end
end

- (Object) sv_type_placement

def sv_fix_coordinated_names

  fixed = false
  gender = self.gender_class
  speech = self.part_of_speech_class

  list_of_coordinated_names.each do |t|
    if t.source.nil? && !t.source.nil?
      self.source = t.source
      fixed = true
    end

    if self.verbatim_author.nil? && !t.verbatim_author.nil?
      self.verbatim_author = t.verbatim_author
      fixed = true
    end

    if self.year_of_publication.nil? && !t.year_of_publication.nil?
      self.year_of_publication = t.year_of_publication
      fixed = true
    end

    t_gender = t.gender_class

    if gender.nil? && !t_gender.nil?
      self.taxon_name_classifications.build(type: t_gender.to_s)
      fixed = true
    end

    t_speech = t.part_of_speech_class

    if speech.nil? && speech != t_speech
      self.taxon_name_classifications.build(type: t_speech.to_s)
      fixed = true
    end

    if self.gender_class.nil? && !t.gender_class.nil?
      self.taxon_name_classifications.build(type: t.gender_class.to_s)
      fixed = true
    end

    if self.original_genus.nil? && !t.original_genus.nil?
      self.original_genus = t.original_genus
      fixed = true
    end

    if self.original_subgenus.nil? && !t.original_subgenus.nil?
      self.original_subgenus = t.original_subgenus
      fixed = true
    end

    if self.original_species.nil? && !t.original_species.nil?
      self.original_species = t.original_species
      fixed = true
    end

    if self.original_subspecies.nil? && !t.original_subspecies.nil?
      self.original_subspecies = t.original_subspecies
      fixed = true
    end

    if self.type_species.nil? && !t.type_species.nil?
      self.type_species = t.type_species
      fixed = true
    end

    if self.type_genus.nil? && !t.type_genus.nil?
      self.type_genus = t.type_genus
      fixed = true
    end

    types1 = self.get_primary_type
    types2 = t.get_primary_type
    if types1.empty? && !types2.empty?
      new_type_material = []
      types2.each do |t|
        new_type_material.push({type_type: t.type_type, protonym_id: t.protonym_id, biological_object_id: t.biological_object_id, source: t.source})
      end
      self.type_materials.build(new_type_material)
      fixed = true
    end

    sttnr = self.type_taxon_name_relationship
    tttnr = t.type_taxon_name_relationship
    unless sttnr.nil? || tttnr.nil?
      if sttnr.type != tttnr.type && sttnr.type.safe_constantize.descendants.collect{|i| i.to_s}.include?(tttnr.type.to_s)
        self.type_taxon_name_relationship.type = t.type_taxon_name_relationship.type
        fixed = true
      end
    end
  end

  if fixed
    begin
      Protonym.transaction do
        self.save
      end
    rescue
      return false
    end
  end
  return fixed
end


712
713
714
715
716
717
# File 'app/models/protonym/soft_validation_extensions.rb', line 712

def sv_type_placement
  # type of this taxon is not included in this taxon
  if !!self.type_taxon_name
    soft_validations.add(:base, "#{self.rank_class.rank_name} #{self.cached_html} has the type #{self.type_taxon_name.rank_class.rank_name} #{self.type_taxon_name.cached_html} classified outside of this taxon") unless self.type_taxon_name.get_valid_taxon_name.ancestors.include?(TaxonName.find(self.cached_valid_taxon_name_id))
  end
end

- (Object) sv_type_placement1



719
720
721
722
723
724
725
726
# File 'app/models/protonym/soft_validation_extensions.rb', line 719

def sv_type_placement1
  # this taxon is a type, but not included in nominal taxon
  if !!self.type_of_taxon_names
    self.type_of_taxon_names.find_each do |t|
      soft_validations.add(:base, "#{self.rank_class.rank_name.capitalize} #{self.cached_html} is the type of #{t.rank_class.rank_name} #{t.cached_html} but it has a parent outside of #{t.cached_html}") unless self.get_valid_taxon_name.ancestors.include?(TaxonName.find(t.cached_valid_taxon_name_id))
    end
  end
end

- (Object) sv_validate_coordinated_names_author



223
224
225
226
227
# File 'app/models/protonym/soft_validation_extensions.rb', line 223

def sv_validate_coordinated_names_author
  list_of_coordinated_names.each do |t|
    soft_validations.add(:verbatim_author, "The author does not match with the author of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_author, success_message: 'Author was updated') unless self.verbatim_author == t.verbatim_author
  end
end

- (Object) sv_validate_coordinated_names_gender



257
258
259
260
261
262
263
264
# File 'app/models/protonym/soft_validation_extensions.rb', line 257

def sv_validate_coordinated_names_gender
  return true unless is_genus_rank?
  list_of_coordinated_names.each do |t|
    if self.gender_class != t.gender_class && is_available?
      soft_validations.add(:base, "The gender status does not match with that of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_gender, success_message: 'Gender was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_original_form



447
448
449
450
451
452
453
454
# File 'app/models/protonym/soft_validation_extensions.rb', line 447

def sv_validate_coordinated_names_original_form
  return true if !is_species_rank? && !self.iczn_set_as_incorrect_original_spelling_of_relationship.blank?
  list_of_coordinated_names.each do |t|
    if self.original_form != t.original_form
      soft_validations.add(:base, "The original form does not match with the original form of coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_original_form, success_message: 'Original form was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_original_genus



297
298
299
300
301
302
303
304
# File 'app/models/protonym/soft_validation_extensions.rb', line 297

def sv_validate_coordinated_names_original_genus
  return true if !is_genus_or_species_rank? && !self.iczn_set_as_incorrect_original_spelling_of_relationship.blank?
  list_of_coordinated_names.each do |t|
    if self.original_genus != t.original_genus
      soft_validations.add(:base, "The original genus does not match with the original genus of coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_original_genus, success_message: 'Original genus was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_original_species



357
358
359
360
361
362
363
364
# File 'app/models/protonym/soft_validation_extensions.rb', line 357

def sv_validate_coordinated_names_original_species
  return true if !is_species_rank? && !self.iczn_set_as_incorrect_original_spelling_of_relationship.blank?
  list_of_coordinated_names.each do |t|
    if self.original_species != t.original_species
      soft_validations.add(:base, "The original species does not match with the original species of coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_original_species, success_message: 'Original species was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_original_subgenus



327
328
329
330
331
332
333
334
# File 'app/models/protonym/soft_validation_extensions.rb', line 327

def sv_validate_coordinated_names_original_subgenus
  return true if !is_genus_or_species_rank? && !self.iczn_set_as_incorrect_original_spelling_of_relationship.blank?
  list_of_coordinated_names.each do |t|
    if self.original_subgenus != t.original_subgenus
      soft_validations.add(:base, "The original subgenus does not match with the original subgenus of coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_original_subgenus, success_message: 'Original subgenus was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_original_subspecies



387
388
389
390
391
392
393
394
# File 'app/models/protonym/soft_validation_extensions.rb', line 387

def sv_validate_coordinated_names_original_subspecies
  return true if !is_species_rank? && !self.iczn_set_as_incorrect_original_spelling_of_relationship.blank?
  list_of_coordinated_names.each do |t|
    if self.original_subspecies != t.original_subspecies
      soft_validations.add(:base, "The original subspecies does not match with the original subspecies of coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_original_subspecies, success_message: 'Original subspecies was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_original_variety



417
418
419
420
421
422
423
424
# File 'app/models/protonym/soft_validation_extensions.rb', line 417

def sv_validate_coordinated_names_original_variety
  return true if !is_species_rank? && !self.iczn_set_as_incorrect_original_spelling_of_relationship.blank?
  list_of_coordinated_names.each do |t|
    if self.original_variety != t.original_variety
      soft_validations.add(:base, "The original variety does not match with the original variety of coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_original_variety, success_message: 'Original variety was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_part_of_speach



277
278
279
280
281
282
283
284
# File 'app/models/protonym/soft_validation_extensions.rb', line 277

def sv_validate_coordinated_names_part_of_speach
  return true unless is_species_rank?
  list_of_coordinated_names.each do |t|
    if self.part_of_speech_class != t.part_of_speech_class && is_available?
      soft_validations.add(:base, "The part of speech status does not match with that of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names, success_message: 'Part of speech was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_source

def sv_validate_coordinated_names

  return true unless is_available?
  r = self.iczn_set_as_incorrect_original_spelling_of_relationship
  list_of_coordinated_names.each do |t|
    soft_validations.add(:base, "The original publication does not match with the original publication of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Original publication was updated') if self.source && t.source && self.source.id != t.source.id
    soft_validations.add(:verbatim_author, "The author does not match with the author of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Author was updated') unless self.verbatim_author == t.verbatim_author
    soft_validations.add(:year_of_publication, "The year of publication does not match with the year of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Year was updated') unless self.year_of_publication == t.year_of_publication
    soft_validations.add(:base, "The gender status does not match with the gender of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Gender was updated') if rank_string =~ /Genus/ && self.gender_class != t.gender_class && !has_misspelling_relationship?
    soft_validations.add(:base, "The part of speech status does not match with the part of speech of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Gender was updated') if rank_string =~ /Species/ && self.part_of_speech_class != t.part_of_speech_class && !has_misspelling_relationship?
    soft_validations.add(:base, "The original genus does not match with the original genus of coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Original genus was updated') if self.original_genus != t.original_genus && r.blank?
    soft_validations.add(:base, "The original subgenus does not match with the original subgenus of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Original subgenus was updated') if self.original_subgenus != t.original_subgenus && r.blank?
    soft_validations.add(:base, "The original species does not match with the original species of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Original species was updated') if self.original_species != t.original_species && r.blank?
    soft_validations.add(:base, "The type species does not match with the type species of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Type species was updated') if self.type_species != t.type_species && !has_misspelling_relationship?
    soft_validations.add(:base, "The type genus does not match with the type genus of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Type genus was updated') if self.type_genus != t.type_genus && !has_misspelling_relationship?
    soft_validations.add(:base, "The type specimen does not match with the type specimen of the coordinated #{t.rank_class.rank_name}",
                         fix: :sv_fix_coordinated_names, success_message: 'Type specimen was updated') if !self.has_same_primary_type(t) && !has_misspelling_relationship?
    sttnr = self.type_taxon_name_relationship
    tttnr = t.type_taxon_name_relationship
    unless sttnr.nil? || tttnr.nil?
      soft_validations.add(:base, "The type species relationship does not match with the type species relationship of the coordinated #{t.rank_class.rank_name}",
                           fix: :sv_fix_coordinated_names, success_message: 'Type species relationship was updated') unless sttnr.type == tttnr.type
    end
  end
end


194
195
196
197
198
199
200
# File 'app/models/protonym/soft_validation_extensions.rb', line 194

def sv_validate_coordinated_names_source
  list_of_coordinated_names.each do |t|
    if ((self.source && t.source && self.source.id != t.source.id) || (self.source.nil? && t.source)) && is_available?
      soft_validations.add(:base, "The original publication does not match with the original publication of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_source, success_message: 'Original publication was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_type_genus



542
543
544
545
546
547
548
549
# File 'app/models/protonym/soft_validation_extensions.rb', line 542

def sv_validate_coordinated_names_type_genus
  return true unless is_family_rank?
  list_of_coordinated_names.each do |t|
    if self.type_genus != t.type_genus && is_available?
      soft_validations.add(:base, "The type genus does not match with the type genus of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_type_genus, success_message: 'Type genus was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_type_species



477
478
479
480
481
482
483
484
# File 'app/models/protonym/soft_validation_extensions.rb', line 477

def sv_validate_coordinated_names_type_species
  return true unless is_genus_rank?
  list_of_coordinated_names.each do |t|
    if self.type_species != t.type_species && is_available?
      soft_validations.add(:base, "The type species does not match with the type species of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_type_species, success_message: 'Type species was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_type_species_type



507
508
509
510
511
512
513
514
515
516
517
# File 'app/models/protonym/soft_validation_extensions.rb', line 507

def sv_validate_coordinated_names_type_species_type
  return true unless is_genus_rank?
  sttnr = self.type_taxon_name_relationship
  return true if sttnr.nil?
  list_of_coordinated_names.each do |t|
    tttnr = t.type_taxon_name_relationship
    if !tttnr.nil? && sttnr.type != tttnr.type
      soft_validations.add(:base, "The type species relationship does not match with the type species relationship of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_type_species_type, success_message: 'Type species relationship was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_type_specimen



572
573
574
575
576
577
578
579
# File 'app/models/protonym/soft_validation_extensions.rb', line 572

def sv_validate_coordinated_names_type_specimen
  return true unless is_species_rank?
  list_of_coordinated_names.each do |t|
    if !self.has_same_primary_type(t)
      soft_validations.add(:base, "The type specimen does not match with the type specimen of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_type_specimen, success_message: 'The type specimen was updated')
    end
  end
end

- (Object) sv_validate_coordinated_names_year



240
241
242
243
244
# File 'app/models/protonym/soft_validation_extensions.rb', line 240

def sv_validate_coordinated_names_year
  list_of_coordinated_names.each do |t|
    soft_validations.add(:year_of_publication, "The year of publication does not match with the year of the coordinated #{t.rank_class.rank_name}", fix: :sv_fix_coordinated_names_year, success_message: 'Year was updated') unless self.year_of_publication == t.year_of_publication
  end
end

- (Object) sv_validate_parent_rank



71
72
73
74
75
76
77
78
79
# File 'app/models/protonym/soft_validation_extensions.rb', line 71

def sv_validate_parent_rank
  if self.rank_class
    if rank_string == 'NomenclaturalRank' || self.parent.rank_string == 'NomenclaturalRank' || !!self.iczn_uncertain_placement_relationship
      true
    elsif !self.rank_class.valid_parents.include?(self.parent.rank_string)
      soft_validations.add(:rank_class, "The rank #{self.rank_class.rank_name} is not compatible with the rank of parent (#{self.parent.rank_class.rank_name}). The name should be marked as 'Incertae sedis'", resolution: 'path_to_edit_protomy')
    end
  end
end

- (Object) sv_year_is_not_required



1013
1014
1015
1016
1017
# File 'app/models/protonym/soft_validation_extensions.rb', line 1013

def sv_year_is_not_required
  if !self.year_of_publication.nil? && self.source && self.year_of_publication == self.source.year
    soft_validations.add(:year_of_publication, 'Year of publication is not required, it is derived from the source', fix: :sv_fix_year_is_not_required, success_message: 'Year of publication was deleted')
  end
end