Project

General

Profile

Download (1.91 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.BotanicalName;
16
import eu.etaxonomy.cdm.model.name.NonViralName;
17
import eu.etaxonomy.cdm.model.name.Rank;
18
import eu.etaxonomy.cdm.validation.annotation.MustHaveAuthority;
19

    
20
public class MustHaveAuthorityValidator implements
21
		ConstraintValidator<MustHaveAuthority, NonViralName> {
22

    
23
	public void initialize(MustHaveAuthority mustHaveAuthority) { }
24

    
25
	public boolean isValid(NonViralName name, ConstraintValidatorContext constraintContext) {
26
		boolean valid = true;
27
		
28
		if(name.getBasionymAuthorTeam() == null && name.getAuthorshipCache() == null) {
29
		    valid = false;
30
		    if(name instanceof BotanicalName && name.getRank().isInfraSpecific()) {
31
			    if(name.getSpecificEpithet() != null && name.getInfraSpecificEpithet() != null && name.getInfraSpecificEpithet().equals(name.getSpecificEpithet())) {
32
				    valid = true; // is AUTONYM
33
			    } 
34
		    } 
35
		    if(name.getRank().isSpeciesAggregate()) { // Species aggregates don't have authorities
36
		    	valid = true;
37
			    }
38
		    
39
		    } else {
40
			valid = true;
41
			if(name instanceof BotanicalName && name.getRank().isInfraSpecific()) {
42
			    if(name.getSpecificEpithet() != null && name.getInfraSpecificEpithet() != null && name.getInfraSpecificEpithet().equals(name.getSpecificEpithet())) {
43
				    valid = false; // is AUTONYM
44
			    } 
45
		    } 
46
		    if(name.getRank().isSpeciesAggregate()) { // Species aggregates don't have authorities
47
			    valid = false;
48
		    }
49
		}
50
		
51
		return valid;		
52
	}
53
}
(6-6/10)