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
|
|
10
|
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.NameRelationship;
|
16
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
17
|
import eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup;
|
18
|
|
19
|
|
20
|
public class NamesWithHomotypicRelationshipsMustBelongToSameGroupValidator implements
|
21
|
ConstraintValidator<NamesWithHomotypicRelationshipsMustBelongToSameGroup, NameRelationship> {
|
22
|
|
23
|
@Override
|
24
|
public void initialize(NamesWithHomotypicRelationshipsMustBelongToSameGroup namesWithHomotypicRelationshipsMustBelongToSameGroup) { }
|
25
|
|
26
|
@Override
|
27
|
public boolean isValid(NameRelationship nameRelationship, ConstraintValidatorContext constraintContext) {
|
28
|
boolean valid = true;
|
29
|
if(nameRelationship.getType().equals(NameRelationshipType.ALTERNATIVE_NAME()) ||
|
30
|
nameRelationship.getType().equals(NameRelationshipType.BASIONYM()) ||
|
31
|
nameRelationship.getType().equals(NameRelationshipType.CONSERVED_AGAINST()) ||
|
32
|
nameRelationship.getType().equals(NameRelationshipType.EMENDATION()) ||
|
33
|
nameRelationship.getType().equals(NameRelationshipType.MISSPELLING()) ||
|
34
|
nameRelationship.getType().equals(NameRelationshipType.ORTHOGRAPHIC_VARIANT()) ||
|
35
|
nameRelationship.getType().equals(NameRelationshipType.REPLACED_SYNONYM())) {
|
36
|
if (nameRelationship.getFromName() != null && nameRelationship.getToName() != null){
|
37
|
if(!nameRelationship.getFromName().getHomotypicalGroup().equals(nameRelationship.getToName().getHomotypicalGroup())) {
|
38
|
valid = false;
|
39
|
constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup.message}").addNode("fromName").addNode("homotypicalGroup").addConstraintViolation();
|
40
|
//remove duplicate violation as it does not give more information
|
41
|
// constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup.message}").addNode("toName").addNode("homotypicalGroup").addConstraintViolation();
|
42
|
}
|
43
|
}
|
44
|
}
|
45
|
|
46
|
return valid;
|
47
|
}
|
48
|
}
|