1
|
/**
|
2
|
* Copyright (C) 2019 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.vaadin.data.validator;
|
10
|
|
11
|
import com.vaadin.data.Validator;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
14
|
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
|
15
|
|
16
|
/**
|
17
|
* Validates a {@link TaxonName} for existence of the nomenclatural reference.
|
18
|
*
|
19
|
* Compatible with fields operating on {@link TaxonName}, {@link NameRelationshipDTO},
|
20
|
*
|
21
|
* @author a.kohlbecker
|
22
|
* @since Mar 27, 2019
|
23
|
*
|
24
|
*/
|
25
|
public class NomenclaturalReferenceExistsValidator implements Validator {
|
26
|
|
27
|
|
28
|
private static final long serialVersionUID = -7750232876262922982L;
|
29
|
|
30
|
private String userHint = "";
|
31
|
|
32
|
public NomenclaturalReferenceExistsValidator(String userHint){
|
33
|
this.userHint = userHint;
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* {@inheritDoc}
|
38
|
*/
|
39
|
@Override
|
40
|
public void validate(Object value) throws InvalidValueException {
|
41
|
if(value != null){
|
42
|
if(value instanceof TaxonName){
|
43
|
TaxonName name = (TaxonName)value;
|
44
|
validateName(name);
|
45
|
}
|
46
|
if(value instanceof NameRelationshipDTO){
|
47
|
NameRelationshipDTO nameRelDto = (NameRelationshipDTO)value;
|
48
|
validateName(nameRelDto.getOtherName());
|
49
|
}
|
50
|
}
|
51
|
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* @param name
|
56
|
*/
|
57
|
public void validateName(TaxonName name) {
|
58
|
if(name.getNomenclaturalReference() == null) {
|
59
|
throw new InvalidValueException("The taxon name must have a nomenclatural reference. " + userHint);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
}
|