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.validation.constraint;
|
10
|
|
11
|
import javax.validation.ConstraintValidator;
|
12
|
import javax.validation.ConstraintValidatorContext;
|
13
|
|
14
|
import org.apache.commons.lang3.StringUtils;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
17
|
import eu.etaxonomy.cdm.validation.annotation.ValidLectotypeSource;
|
18
|
|
19
|
/**
|
20
|
* @author a.mueller
|
21
|
* @since 25.02.2019
|
22
|
*/
|
23
|
public class LectotypeSourceValidator implements ConstraintValidator<ValidLectotypeSource, TypeDesignationBase<?>> {
|
24
|
|
25
|
@Override
|
26
|
public void initialize(ValidLectotypeSource constraintAnnotation) {}
|
27
|
|
28
|
@Override
|
29
|
public boolean isValid(TypeDesignationBase<?> typeDesignation, ConstraintValidatorContext context) {
|
30
|
boolean isValid;
|
31
|
//no citation
|
32
|
if(typeDesignation.getCitation() == null && StringUtils.isBlank(typeDesignation.getCitationMicroReference())){
|
33
|
isValid = true;
|
34
|
//no status
|
35
|
}else if (typeDesignation.getTypeStatus() == null){
|
36
|
isValid = false;
|
37
|
}else{
|
38
|
isValid = typeDesignation.hasDesignationSource();
|
39
|
}
|
40
|
return isValid;
|
41
|
}
|
42
|
}
|