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.HashSet;
|
12
|
import java.util.List;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import javax.validation.ConstraintValidator;
|
16
|
import javax.validation.ConstraintValidatorContext;
|
17
|
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.INameService;
|
21
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
22
|
import eu.etaxonomy.cdm.validation.annotation.NoDuplicateNames;
|
23
|
|
24
|
public class NoDuplicateNamesValidator implements
|
25
|
ConstraintValidator<NoDuplicateNames,TaxonName> {
|
26
|
|
27
|
private static Set<String> includeProperties;
|
28
|
|
29
|
static {
|
30
|
includeProperties = new HashSet<>();
|
31
|
includeProperties.add("genusOrUninomial");
|
32
|
includeProperties.add("infraGenericEpithet");
|
33
|
includeProperties.add("specificEpithet");
|
34
|
includeProperties.add("infraSpecificEpithet");
|
35
|
includeProperties.add("rank");
|
36
|
includeProperties.add("nomenclaturalReference");
|
37
|
includeProperties.add("nomenclaturalMicroReference");
|
38
|
includeProperties.add("basionymAuthorship");
|
39
|
includeProperties.add("exBasionymAuthorship");
|
40
|
includeProperties.add("combinationAuthorship");
|
41
|
includeProperties.add("exCombinationAuthorship");
|
42
|
}
|
43
|
|
44
|
private INameService nameService;
|
45
|
|
46
|
@Autowired
|
47
|
public void setNameService(INameService nameService) {
|
48
|
this.nameService = nameService;
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public void initialize(NoDuplicateNames noDuplicateNames) { }
|
53
|
|
54
|
@Override
|
55
|
public boolean isValid(TaxonName name, ConstraintValidatorContext constraintContext) {
|
56
|
if(name == null) {
|
57
|
return true;
|
58
|
} else {
|
59
|
List<TaxonName> matchingNonViralNames = nameService.list(name, includeProperties, null, null, null, null);
|
60
|
if(matchingNonViralNames.size() > 0) {
|
61
|
if(matchingNonViralNames.size() == 1 && matchingNonViralNames.get(0).equals(name)) {
|
62
|
return true;
|
63
|
} else {
|
64
|
return false;
|
65
|
}
|
66
|
} else {
|
67
|
return true;
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
}
|