1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.validation.constraint;
|
11
|
|
12
|
import javax.validation.ConstraintValidator;
|
13
|
import javax.validation.ConstraintValidatorContext;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
16
|
import eu.etaxonomy.cdm.validation.annotation.NameMustHaveAuthority;
|
17
|
|
18
|
public class MustHaveAuthorityValidator implements
|
19
|
ConstraintValidator<NameMustHaveAuthority, INonViralName> {
|
20
|
|
21
|
@Override
|
22
|
public void initialize(NameMustHaveAuthority mustHaveAuthority) { }
|
23
|
|
24
|
@Override
|
25
|
public boolean isValid(INonViralName name, ConstraintValidatorContext constraintContext) {
|
26
|
boolean valid = true;
|
27
|
|
28
|
if(name.getBasionymAuthorship() == null && name.getAuthorshipCache() == null) {
|
29
|
valid = false;
|
30
|
if(name.isBotanical() && name.isInfraSpecific()) {
|
31
|
if(name.isAutonym() ) {
|
32
|
valid = true; // is AUTONYM
|
33
|
}
|
34
|
}
|
35
|
if(name.isSpeciesAggregate()) { // Species aggregates don't have authorities
|
36
|
valid = true;
|
37
|
}
|
38
|
|
39
|
} else {
|
40
|
valid = true;
|
41
|
if(name.isBotanical() && name.isInfraSpecific()) {
|
42
|
if(name.isAutonym()) {
|
43
|
valid = false; // is AUTONYM
|
44
|
}
|
45
|
}
|
46
|
if(name.isSpeciesAggregate()) { // Species aggregates don't have authorities
|
47
|
valid = false;
|
48
|
}
|
49
|
}
|
50
|
|
51
|
return valid;
|
52
|
}
|
53
|
}
|