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.NonViralName;
|
16
|
import eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank;
|
17
|
|
18
|
public class CorrectEpithetsForRankValidator implements ConstraintValidator<CorrectEpithetsForRank, NonViralName> {
|
19
|
|
20
|
public void initialize(CorrectEpithetsForRank correctEpithetsForRank) { }
|
21
|
|
22
|
public boolean isValid(NonViralName name, ConstraintValidatorContext constraintContext) {
|
23
|
boolean valid = true;
|
24
|
if(name.getRank().isSupraGeneric() || name.getRank().isGenus()) {
|
25
|
if(name.getInfraGenericEpithet() != null) {
|
26
|
valid = false;
|
27
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraGenericEpithet").addConstraintViolation();
|
28
|
}
|
29
|
|
30
|
if(name.getSpecificEpithet() != null) {
|
31
|
valid = false;
|
32
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("specificEpithet").addConstraintViolation();
|
33
|
}
|
34
|
if(name.getInfraSpecificEpithet() != null) {
|
35
|
valid = false;
|
36
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
37
|
}
|
38
|
} else if(name.getRank().isInfraGeneric()) {
|
39
|
if(name.getInfraGenericEpithet() == null) {
|
40
|
valid = false;
|
41
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("infraGenericEpithet").addConstraintViolation();
|
42
|
}
|
43
|
|
44
|
if(name.getSpecificEpithet() != null) {
|
45
|
valid = false;
|
46
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("specificEpithet").addConstraintViolation();
|
47
|
}
|
48
|
if(name.getInfraSpecificEpithet() != null) {
|
49
|
valid = false;
|
50
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
51
|
}
|
52
|
} else if(name.getRank().isSpecies()) {
|
53
|
if(name.getSpecificEpithet() == null) {
|
54
|
valid = false;
|
55
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("specificEpithet").addConstraintViolation();
|
56
|
}
|
57
|
|
58
|
if(name.getInfraSpecificEpithet() != null) {
|
59
|
valid = false;
|
60
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
61
|
}
|
62
|
} else if(name.getRank().isInfraSpecific()) {
|
63
|
if(name.getSpecificEpithet() == null) {
|
64
|
valid = false;
|
65
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("specificEpithet").addConstraintViolation();
|
66
|
}
|
67
|
if(name.getInfraSpecificEpithet() == null) {
|
68
|
valid = false;
|
69
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
70
|
}
|
71
|
}
|
72
|
|
73
|
return valid;
|
74
|
}
|
75
|
}
|