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
|
package eu.etaxonomy.cdm.validation.constraint;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import javax.validation.ConstraintValidator;
|
14
|
import javax.validation.ConstraintValidatorContext;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
17
|
import eu.etaxonomy.cdm.model.name.Rank;
|
18
|
import eu.etaxonomy.cdm.validation.annotation.CorrectRanksForCode;
|
19
|
|
20
|
/**
|
21
|
* Checks rank is available in the nomenclatural code of the name.
|
22
|
*
|
23
|
* see also #6387
|
24
|
*
|
25
|
* @author a.mueller
|
26
|
* @since 15.10.2021
|
27
|
*/
|
28
|
public class CorrectRanksForCodeValidator implements ConstraintValidator<CorrectRanksForCode, INonViralName> {
|
29
|
|
30
|
@Override
|
31
|
public void initialize(CorrectRanksForCode correctRanksForCode) { }
|
32
|
|
33
|
@Override
|
34
|
public boolean isValid(INonViralName name, ConstraintValidatorContext constraintContext) {
|
35
|
boolean valid = true;
|
36
|
if (name.getRank() != null){
|
37
|
UUID rankUuid = name.getRank().getUuid();
|
38
|
if(isCultivarUuid(rankUuid) && !name.isCultivar()){
|
39
|
valid = false;
|
40
|
}else if (name.isCultivar() && !isCultivarUuid(rankUuid)){
|
41
|
valid = false;
|
42
|
}else if (rankUuid.equals(Rank.uuidSectionZoology) ||
|
43
|
rankUuid.equals(Rank.uuidSubsectionZoology)
|
44
|
) {
|
45
|
if (!name.isZoological()){
|
46
|
valid = false;
|
47
|
}
|
48
|
}else if (rankUuid.equals(Rank.uuidSectionBotany) ||
|
49
|
rankUuid.equals(Rank.uuidSubsectionBotany)
|
50
|
) {
|
51
|
if (!name.isBotanical()){
|
52
|
valid = false;
|
53
|
}
|
54
|
}
|
55
|
//TODO tbc
|
56
|
|
57
|
}
|
58
|
return valid;
|
59
|
}
|
60
|
|
61
|
private boolean isCultivarUuid(UUID rankUuid) {
|
62
|
return rankUuid.equals(Rank.uuidCultivar) ||
|
63
|
rankUuid.equals(Rank.uuidCultivarGroup) ||
|
64
|
rankUuid.equals(Rank.uuidGrexICNCP) ||
|
65
|
rankUuid.equals(Rank.uuidGraftChimaera) ||
|
66
|
rankUuid.equals(Rank.uuidDenominationClass);
|
67
|
}
|
68
|
|
69
|
}
|