1 |
1412a4c4
|
Katja Luther
|
/**
|
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 |
a641fad9
|
ben.clark
|
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 |
a13c5f66
|
Andreas Müller
|
public class CorrectEpithetsForRankValidator implements ConstraintValidator<CorrectEpithetsForRank, NonViralName> {
|
19 |
a641fad9
|
ben.clark
|
|
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 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraGenericEpithet").addConstraintViolation();
|
28 |
a641fad9
|
ben.clark
|
}
|
29 |
|
|
|
30 |
|
|
if(name.getSpecificEpithet() != null) {
|
31 |
|
|
valid = false;
|
32 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("specificEpithet").addConstraintViolation();
|
33 |
a641fad9
|
ben.clark
|
}
|
34 |
|
|
if(name.getInfraSpecificEpithet() != null) {
|
35 |
|
|
valid = false;
|
36 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
37 |
a641fad9
|
ben.clark
|
}
|
38 |
|
|
} else if(name.getRank().isInfraGeneric()) {
|
39 |
|
|
if(name.getInfraGenericEpithet() == null) {
|
40 |
|
|
valid = false;
|
41 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("infraGenericEpithet").addConstraintViolation();
|
42 |
a641fad9
|
ben.clark
|
}
|
43 |
|
|
|
44 |
|
|
if(name.getSpecificEpithet() != null) {
|
45 |
|
|
valid = false;
|
46 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("specificEpithet").addConstraintViolation();
|
47 |
a641fad9
|
ben.clark
|
}
|
48 |
|
|
if(name.getInfraSpecificEpithet() != null) {
|
49 |
|
|
valid = false;
|
50 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
51 |
a641fad9
|
ben.clark
|
}
|
52 |
|
|
} else if(name.getRank().isSpecies()) {
|
53 |
|
|
if(name.getSpecificEpithet() == null) {
|
54 |
|
|
valid = false;
|
55 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("specificEpithet").addConstraintViolation();
|
56 |
a641fad9
|
ben.clark
|
}
|
57 |
|
|
|
58 |
|
|
if(name.getInfraSpecificEpithet() != null) {
|
59 |
|
|
valid = false;
|
60 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNotNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
61 |
a641fad9
|
ben.clark
|
}
|
62 |
|
|
} else if(name.getRank().isInfraSpecific()) {
|
63 |
|
|
if(name.getSpecificEpithet() == null) {
|
64 |
|
|
valid = false;
|
65 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("specificEpithet").addConstraintViolation();
|
66 |
a641fad9
|
ben.clark
|
}
|
67 |
|
|
if(name.getInfraSpecificEpithet() == null) {
|
68 |
|
|
valid = false;
|
69 |
a13c5f66
|
Andreas Müller
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.CorrectEpithetsForRank.epithetNull}").addNode("infraSpecificEpithet").addConstraintViolation();
|
70 |
a641fad9
|
ben.clark
|
}
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
return valid;
|
74 |
|
|
}
|
75 |
|
|
}
|