2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.validation
.constraint
;
12 import javax
.validation
.ConstraintValidator
;
13 import javax
.validation
.ConstraintValidatorContext
;
15 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
17 import eu
.etaxonomy
.cdm
.validation
.annotation
.NamesWithHomotypicRelationshipsMustBelongToSameGroup
;
20 public class NamesWithHomotypicRelationshipsMustBelongToSameGroupValidator
implements
21 ConstraintValidator
<NamesWithHomotypicRelationshipsMustBelongToSameGroup
, NameRelationship
> {
23 public void initialize(NamesWithHomotypicRelationshipsMustBelongToSameGroup namesWithHomotypicRelationshipsMustBelongToSameGroup
) { }
25 public boolean isValid(NameRelationship nameRelationship
, ConstraintValidatorContext constraintContext
) {
27 if(nameRelationship
.getType().equals(NameRelationshipType
.ALTERNATIVE_NAME()) ||
28 nameRelationship
.getType().equals(NameRelationshipType
.BASIONYM()) ||
29 nameRelationship
.getType().equals(NameRelationshipType
.CONSERVED_AGAINST()) ||
30 nameRelationship
.getType().equals(NameRelationshipType
.EMENDATION()) ||
31 nameRelationship
.getType().equals(NameRelationshipType
.MISSPELLING()) ||
32 nameRelationship
.getType().equals(NameRelationshipType
.ORTHOGRAPHIC_VARIANT()) ||
33 nameRelationship
.getType().equals(NameRelationshipType
.REPLACED_SYNONYM())) {
34 if(!nameRelationship
.getFromName().getHomotypicalGroup().equals(nameRelationship
.getToName().getHomotypicalGroup())) {
36 constraintContext
.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup.message}").addNode("fromName").addNode("homotypicalGroup").addConstraintViolation();
37 constraintContext
.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup.message}").addNode("toName").addNode("homotypicalGroup").addConstraintViolation();