Project

General

Profile

Download (2.25 KB) Statistics
| Branch: | Tag: | Revision:
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
	public void initialize(NamesWithHomotypicRelationshipsMustBelongToSameGroup namesWithHomotypicRelationshipsMustBelongToSameGroup) { }
24

    
25
	public boolean isValid(NameRelationship nameRelationship, ConstraintValidatorContext constraintContext) {
26
		boolean valid = true;
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())) {
35
				valid = false;
36
				constraintContext.buildErrorWithMessageTemplate("{eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup.message}").addSubNode("fromName").addSubNode("homotypicalGroup").addError();				
37
				constraintContext.buildErrorWithMessageTemplate("{eu.etaxonomy.cdm.validation.annotation.NamesWithHomotypicRelationshipsMustBelongToSameGroup.message}").addSubNode("toName").addSubNode("homotypicalGroup").addError();
38
			}
39
		}
40
		
41
		return valid;		
42
	}
43
}
(8-8/11)