Project

General

Profile

Download (1.7 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.taxon.Taxon;
16
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
17
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
18
import eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustBeLowerRankThanParent;
19

    
20
public class ChildTaxaMustBeLowerRankThanParentValidator implements
21
		ConstraintValidator<ChildTaxaMustBeLowerRankThanParent, TaxonRelationship> {
22

    
23
	public void initialize(ChildTaxaMustBeLowerRankThanParent childTaxaMustBeLowerRankThanParent) { }
24

    
25
	public boolean isValid(TaxonRelationship taxonRelationship, ConstraintValidatorContext constraintContext) {
26
		boolean valid = true;
27
		//FIXME Replace by TaxonNode relationship
28
		if(taxonRelationship.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
29
			Taxon parent = taxonRelationship.getToTaxon();
30
			Taxon child = taxonRelationship.getFromTaxon();
31
			
32
			
33
			if(parent.getName().getRank().equals(child.getName().getRank()) || parent.getName().getRank().isLower(child.getName().getRank())) {
34
				valid = false;
35
				constraintContext.buildConstraintViolationWithTemplate("{eu.etaxonomy.cdm.validation.annotation.ChildTaxaMustBeLowerRankThanParent.message}").addNode("fromTaxon").addNode("name").addNode("rank").addConstraintViolation();				
36
			}
37
		}
38
		
39
		return valid;		
40
	}
41
}
(2-2/13)