2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.validation
.constraint
;
12 import javax
.validation
.ConstraintValidator
;
13 import javax
.validation
.ConstraintValidatorContext
;
15 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
17 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
18 import eu
.etaxonomy
.cdm
.validation
.annotation
.MustHaveAuthority
;
20 public class MustHaveAuthorityValidator
implements
21 ConstraintValidator
<MustHaveAuthority
, NonViralName
> {
23 public void initialize(MustHaveAuthority mustHaveAuthority
) { }
25 public boolean isValid(NonViralName name
, ConstraintValidatorContext constraintContext
) {
28 if(name
.getBasionymAuthorTeam() == null && name
.getAuthorshipCache() == null) {
30 if(name
instanceof BotanicalName
&& name
.getRank().isInfraSpecific()) {
31 if(name
.getSpecificEpithet() != null && name
.getInfraSpecificEpithet() != null && name
.getInfraSpecificEpithet().equals(name
.getSpecificEpithet())) {
32 valid
= true; // is AUTONYM
35 if(name
.getRank().isSpeciesAggregate()) { // Species aggregates don't have authorities
41 if(name
instanceof BotanicalName
&& name
.getRank().isInfraSpecific()) {
42 if(name
.getSpecificEpithet() != null && name
.getInfraSpecificEpithet() != null && name
.getInfraSpecificEpithet().equals(name
.getSpecificEpithet())) {
43 valid
= false; // is AUTONYM
46 if(name
.getRank().isSpeciesAggregate()) { // Species aggregates don't have authorities