Project

General

Profile

Download (1.57 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.INonViralName;
17
import eu.etaxonomy.cdm.validation.annotation.NameMustHaveAuthority;
18

    
19
public class MustHaveAuthorityValidator implements
20
		ConstraintValidator<NameMustHaveAuthority, INonViralName> {
21

    
22
	@Override
23
    public void initialize(NameMustHaveAuthority mustHaveAuthority) { }
24

    
25
    @Override
26
    public boolean isValid(INonViralName name, ConstraintValidatorContext constraintContext) {
27
		boolean valid = true;
28

    
29
		if(name.getBasionymAuthorship() == null && name.getAuthorshipCache() == null) {
30
		    valid = false;
31
		    if(name.isInstanceOf(BotanicalName.class) && name.isInfraSpecific()) {
32
			    if(name.isAutonym() ) {
33
				    valid = true; // is AUTONYM
34
			    }
35
		    }
36
		    if(name.isSpeciesAggregate()) { // Species aggregates don't have authorities
37
		    	valid = true;
38
			}
39

    
40
		} else {
41
			valid = true;
42
			if(name.isInstanceOf(BotanicalName.class) && name.isInfraSpecific()) {
43
			    if(name.isAutonym()) {
44
				    valid = false; // is AUTONYM
45
			    }
46
		    }
47
		    if(name.isSpeciesAggregate()) { // Species aggregates don't have authorities
48
			    valid = false;
49
		    }
50
		}
51

    
52
		return valid;
53
	}
54
}
(8-8/16)