Project

General

Profile

Revision ce490fbf

IDce490fbf0475faaa94ae66a1dcc367aa3491d470
Parent ee1b78e8
Child 2a0a678b

Added by Andreas Müller over 1 year ago

fix #8139 add test for valid lectotype source

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/ITypeDesignation.java
11 11

  
12 12
import java.util.Set;
13 13

  
14
import javax.persistence.Transient;
15

  
14 16
/**
15 17
 * @author a.mueller
16 18
 * @since 07.08.2008
......
19 21

  
20 22

  
21 23
    /**
22
     * Returns the boolean value indicating whether <i>this</i> type
23
     * designation has a "lectotype" status (true) or not (false).<BR>
24
     * A lectotype is a type designated as the
25
     * nomenclatural type, when no holotype was indicated at the time of
26
     * publication of the "type-bringing" {@link TaxonName taxon name}, when the
27
     * holotype is found to belong to more than one taxon name,
28
     * or as long as it is missing.
24
     * Shortcut to retrieve the information if the status of
25
     * <i>this</i> is considered to be a "lectotype" status.
26
     * For details see Type {@link TypeDesignationStatusBase#isLectotype()}
29 27
     *
30
     * @see  SpecimenTypeDesignationStatus#isLectotype()
31
     * @see  SpecimenTypeDesignationStatus#HOLOTYPE()
32
     * @see  NameTypeDesignationStatus#isLectotype()
28
     * @see  TypeDesignationStatusBase#isLectotype()
33 29
     */
34

  
30
    @Transient
35 31
    public boolean isLectoType();
36 32

  
37 33
//	/**
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameTypeDesignation.java
12 12
import javax.persistence.Entity;
13 13
import javax.persistence.FetchType;
14 14
import javax.persistence.ManyToOne;
15
import javax.persistence.Transient;
16 15
import javax.xml.bind.annotation.XmlAccessType;
17 16
import javax.xml.bind.annotation.XmlAccessorType;
18 17
import javax.xml.bind.annotation.XmlElement;
......
45 44
 * @see		TypeDesignationBase
46 45
 * @see		SpecimenTypeDesignation
47 46
 * @author	m.doering
48
 * @version 1.0
49 47
 * @since 08-Nov-2007 13:06:38
50 48
 */
51 49
@XmlRootElement(name = "NameTypeDesignation")
......
57 55
})
58 56
@Entity
59 57
@Audited
60
public class NameTypeDesignation extends TypeDesignationBase<NameTypeDesignationStatus> implements ITypeDesignation, Cloneable {
58
public class NameTypeDesignation
59
        extends TypeDesignationBase<NameTypeDesignationStatus>  {
60

  
61 61
	private static final long serialVersionUID = 8478663508862210879L;
62 62
	final static Logger logger = Logger.getLogger(NameTypeDesignation.class);
63 63

  
......
212 212
		this.conservedType = conservedType;
213 213
	}
214 214

  
215
	@Override
216
    @Transient
217
	public boolean isLectoType() {
218
		if (getTypeStatus() == null) {
219
			return false;
220
		}
221
		return getTypeStatus().isLectotype();
222
	}
223 215

  
224 216
	/**
225 217
	 * Returns the boolean value "true" if the use of the species {@link TaxonName taxon name}
......
230 222
	 *
231 223
	 * @see   ReferencedEntityBase#getCitation()
232 224
	 */
233
//	/* (non-Javadoc)
234
//	 * @see eu.etaxonomy.cdm.model.name.ITypeDesignation#isLectoType()
235
//	 */
236
//	public boolean isLectoType() {
237
//		return lectoType;
238
//	}
239
//
240
//	/**
241
//	 * @see   #isLectoType()
242
//	 */
243
//	public void setLectoType(boolean lectoType) {
244
//		this.lectoType = lectoType;
245
//	}
225

  
246 226

  
247 227
//*********************** CLONE ********************************************************/
248 228

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameTypeDesignationStatus.java
201 201
	}
202 202

  
203 203
	/**
204
	 * Returns the boolean value indicating whether <i>this</i> type designation
205
	 * status is itself "lectotype" or a kind of "lectotype" (true) or not
206
	 * (false). Returns false if <i>this</i> type designation status is null.<BR>
207
	 * A lectotype is a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnit specimen or illustration} designated as the
208
	 * nomenclatural type, when no holotype was indicated at the time of
209
	 * publication of the "type-bringing" {@link TaxonName taxon name}, when the
210
	 * holotype is found to be assigned to taxon names belonging to more than
211
	 * one {@link HomotypicalGroup homotypical group}, or as long as it is missing.
212
	 *
213
	 * @see  #LECTOTYPE()
214
	 * @see  #HOLOTYPE()
215
	 * @see  eu.etaxonomy.cdm.model.common.DefinedTermBase#getKindOf()
204
	 * {@inheritDoc}
216 205
	 */
217
	@Transient
206
	@Override
207
    @Transient
218 208
	public boolean isLectotype(){
219 209
		if (
220 210
				this.equals(LECTOTYPE()) ||
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/SpecimenTypeDesignation.java
14 14
import javax.persistence.FetchType;
15 15
import javax.persistence.JoinColumn;
16 16
import javax.persistence.ManyToOne;
17
import javax.persistence.Transient;
18 17
import javax.xml.bind.annotation.XmlAccessType;
19 18
import javax.xml.bind.annotation.XmlAccessorType;
20 19
import javax.xml.bind.annotation.XmlElement;
......
57 56
@Entity
58 57
@Audited
59 58
public class SpecimenTypeDesignation
60
        extends TypeDesignationBase<SpecimenTypeDesignationStatus>
61
        implements ITypeDesignation, Cloneable {
59
        extends TypeDesignationBase<SpecimenTypeDesignationStatus> {
60

  
62 61
	private static final long serialVersionUID = 6481627446997275007L;
63 62
	private static final Logger logger = Logger.getLogger(SpecimenTypeDesignation.class);
64 63

  
......
171 170
		this.typeSpecimen = typeSpecimen;
172 171
	}
173 172

  
174
	@Override
175
    @Transient
176
	public boolean isLectoType() {
177
		if(getTypeStatus() == null){
178
			return false;
179
		}
180
		return getTypeStatus().isLectotype();
181
	}
182 173

  
183 174
//*********************** CLONE ********************************************************/
184 175

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/SpecimenTypeDesignationStatus.java
130 130
        }
131 131
	}
132 132

  
133

  
134
	/**
135
	 * Returns the boolean value indicating whether <i>this</i> type designation
136
	 * status is itself "lectotype" or a kind of "lectotype" (true) or not
137
	 * (false). Returns false if <i>this</i> type designation status is null.<BR>
138
	 * A lectotype is a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnit specimen or illustration} designated as the
139
	 * nomenclatural type, when no holotype was indicated at the time of
140
	 * publication of the "type-bringing" {@link TaxonName taxon name}, when the
141
	 * holotype is found to be assigned to taxon names belonging to more than
142
	 * one {@link HomotypicalGroup homotypical group}, or as long as it is missing.
143
	 *
144
	 * @see  #LECTOTYPE()
145
	 * @see  #HOLOTYPE()
146
	 * @see  eu.etaxonomy.cdm.model.common.DefinedTermBase#getKindOf()
147
	 */
148 133
	@Transient
134
	@Override
149 135
	public boolean isLectotype(){
150 136
		if (this.equals(LECTOTYPE()) ||
151 137
				this.equals(ISOLECTOTYPE()) ||
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TypeDesignationBase.java
18 18
import javax.persistence.InheritanceType;
19 19
import javax.persistence.ManyToMany;
20 20
import javax.persistence.ManyToOne;
21
import javax.persistence.Transient;
21 22
import javax.validation.constraints.NotNull;
22 23
import javax.xml.bind.annotation.XmlElement;
23 24
import javax.xml.bind.annotation.XmlElementWrapper;
......
39 40
import eu.etaxonomy.cdm.model.common.SourcedEntityBase;
40 41
import eu.etaxonomy.cdm.model.reference.Reference;
41 42
import eu.etaxonomy.cdm.validation.Level2;
43
import eu.etaxonomy.cdm.validation.annotation.ValidLectotypeSource;
42 44
import eu.etaxonomy.cdm.validation.annotation.ValidTypeDesignation;
43 45

  
44 46
/**
......
72 74
@Audited
73 75
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
74 76
@ValidTypeDesignation(groups=Level2.class)
77
@ValidLectotypeSource(groups=Level2.class)
75 78
public abstract class TypeDesignationBase<T extends TypeDesignationStatusBase<T>>
76 79
        extends SourcedEntityBase<IdentifiableSource>
77 80
        implements ITypeDesignation {
......
279 282
        return IdentifiableSource.NewInstance(type, idInSource, idNamespace, reference, microReference, originalInfo);
280 283
    }
281 284

  
285

  
286
    @Override
287
    @Transient
288
    public boolean isLectoType() {
289
        if (getTypeStatus() == null) {
290
            return false;
291
        }
292
        return getTypeStatus().isLectotype();
293
    }
294

  
282 295
//*********************** CLONE ********************************************************/
283 296

  
297

  
284 298
    /**
285 299
     * Clones <i>this</i> type designation. This is a shortcut that enables to create
286 300
     * a new instance that differs only slightly from <i>this</i> type designation by
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TypeDesignationStatusBase.java
53 53
@Audited
54 54
public abstract class TypeDesignationStatusBase<T extends TypeDesignationStatusBase<T>>
55 55
        extends OrderedTermBase<T> {
56

  
56 57
	private static final long serialVersionUID = -7204587330204725285L;
57 58
	static Logger logger = Logger.getLogger(TypeDesignationStatusBase.class);
58 59

  
......
91 92
	protected TypeDesignationStatusBase(TermType type, String term, String label, String labelAbbrev) {
92 93
		super(type, term, label, labelAbbrev);
93 94
	}
95

  
96
    /**
97
     * Returns the boolean value indicating whether <i>this</i> type designation
98
     * status is itself "lectotype" or a kind of "lectotype" (<code>true</code>) or not
99
     * (<code>false</code>).<BR>
100
     *
101
     * A lectotype is a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnit specimen or illustration}
102
     * or a {@link TaxonName taxon name}
103
     * designated as the nomenclatural type, when no holotype was indicated at the time of
104
     * publication of the "type-providing" {@link TaxonName taxon name}, when the
105
     * holotype is found to be assigned to taxon names belonging to more than
106
     * one {@link HomotypicalGroup homotypical group}, or as long as it is missing.
107
     *
108
     * @see  #LECTOTYPE()
109
     * @see  #HOLOTYPE()
110
     * @see  eu.etaxonomy.cdm.model.common.DefinedTermBase#getKindOf()
111
     */
112
    public abstract boolean isLectotype();
94 113
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/validation/annotation/ValidLectotypeSource.java
1
/**
2
* Copyright (C) 2019 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
package eu.etaxonomy.cdm.validation.annotation;
10

  
11
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
12
import static java.lang.annotation.ElementType.FIELD;
13
import static java.lang.annotation.ElementType.METHOD;
14
import static java.lang.annotation.ElementType.TYPE;
15
import static java.lang.annotation.RetentionPolicy.RUNTIME;
16

  
17
import java.lang.annotation.Documented;
18
import java.lang.annotation.Retention;
19
import java.lang.annotation.Target;
20

  
21
import javax.validation.Constraint;
22
import javax.validation.Payload;
23

  
24
import eu.etaxonomy.cdm.validation.constraint.LectotypeSourceValidator;
25

  
26
/**
27
 * @author a.mueller
28
 * @since 25.02.2019
29
 */
30
@Target( { TYPE, METHOD, FIELD, ANNOTATION_TYPE})
31
@Retention(RUNTIME)
32
@Constraint(validatedBy = LectotypeSourceValidator.class)
33
@Documented
34
public @interface ValidLectotypeSource {
35

  
36
    String message() default "{eu.etaxonomy.cdm.validation.annotation.LectotypeSource.message}";
37

  
38
    Class<? extends Payload>[] payload() default {};
39

  
40
    Class<?>[] groups() default {};
41
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/validation/constraint/LectotypeSourceValidator.java
1
/**
2
* Copyright (C) 2019 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
package eu.etaxonomy.cdm.validation.constraint;
10

  
11
import javax.validation.ConstraintValidator;
12
import javax.validation.ConstraintValidatorContext;
13

  
14
import org.apache.commons.lang3.StringUtils;
15

  
16
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
17
import eu.etaxonomy.cdm.validation.annotation.ValidLectotypeSource;
18

  
19
/**
20
 * @author a.mueller
21
 * @since 25.02.2019
22
 *
23
 */
24
public class LectotypeSourceValidator implements ConstraintValidator<ValidLectotypeSource, TypeDesignationBase<?>> {
25

  
26
    /**
27
     * {@inheritDoc}
28
     */
29
    @Override
30
    public void initialize(ValidLectotypeSource constraintAnnotation) {}
31

  
32
    /**
33
     * {@inheritDoc}
34
     */
35
    @Override
36
    public boolean isValid(TypeDesignationBase<?> typeDesignation, ConstraintValidatorContext context) {
37
        boolean isValid;
38
        //no citation
39
        if(typeDesignation.getCitation() == null && StringUtils.isBlank(typeDesignation.getCitationMicroReference())){
40
            isValid = true;
41
        //no status
42
        }else if (typeDesignation.getTypeStatus() == null){
43
            isValid = false;
44
        }else{
45
            isValid = typeDesignation.isLectoType();
46
        }
47
        return isValid;
48
    }
49

  
50
}
cdmlib-model/src/main/resources/ValidationMessages.properties
30 30
eu.etaxonomy.cdm.validation.annotation.InReference.JournalShouldNotHaveAnAuthor.message=a journal must not have an author (only article has an author)
31 31
eu.etaxonomy.cdm.validation.annotation.ValidTaxonomicYear.message=a valid taxon name year must be after 1753
32 32
eu.etaxonomy.cdm.validation.annotation.name.ValidTypeDesignation.message = Type designations must belong to a name and must either link to a specimen/name or be flagged as 'not designated'
33
eu.etaxonomy.cdm.validation.annotation.LectotypeSource.message=Lectotype source must only be defined for lectotype (or similar) type designations
33 34
eu.etaxonomy.cdm.validation.annotation.NameMustFollowCode.message = Taxon name must only have attributes set that are available according to their code. E.g. 'acronym name' should only be available for viral names.
cdmlib-model/src/test/java/eu/etaxonomy/cdm/validation/ValidLectotypeSourceTest.java
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;
11

  
12
import org.apache.log4j.Logger;
13
import org.junit.Before;
14
import org.junit.Test;
15

  
16
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
17
import eu.etaxonomy.cdm.model.name.IBotanicalName;
18
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
19
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
20
import eu.etaxonomy.cdm.model.name.Rank;
21
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
22
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
25
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
26
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.validation.constraint.LectotypeSourceValidator;
30

  
31

  
32

  
33
/**
34
 * NOTE: In this test, the words "valid" and "invalid", loaded though
35
 * these terms are when applied to taxonomic names, only mean "passes the
36
 * rules of this validator" or not and should not be confused with the strict
37
 * nomenclatural and taxonomic sense of these words.
38
 *
39
 * @author a.mueller
40
 */
41
public class ValidLectotypeSourceTest extends ValidationTestBase {
42
	@SuppressWarnings("unused")
43
    private static final Logger logger = Logger.getLogger(ValidLectotypeSourceTest.class);
44

  
45
    static Class<?> validatorClass = LectotypeSourceValidator.class;
46
    static Class<?> group = Level2.class;
47

  
48
    private NameTypeDesignation nameDesignation;
49
    private SpecimenTypeDesignation specimenDesignation;
50
    private IBotanicalName name1;
51
    private TaxonName name2;
52
    private DerivedUnit specimen;
53
    private Reference lectotypeSource;
54

  
55

  
56
	@Before
57
	public void setUp() {
58
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
59
		vocabularyStore.initialize();
60

  
61
		name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
62
		name1.setNameCache("Aus aus");
63

  
64
	    name2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
65
	    name2.setNameCache("Aus bus");
66

  
67
	    specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
68

  
69
	    lectotypeSource = ReferenceFactory.newGeneric();
70
	}
71

  
72

  
73
/****************** TESTS *****************************/
74

  
75
    @Test
76
    public void testNameTypeDesignations() {
77

  
78
        //without source  => never invalid
79
        nameDesignation = NameTypeDesignation.NewInstance();
80
        validateHasNoConstraint(nameDesignation, validatorClass, group);
81

  
82
        nameDesignation.setTypeStatus(NameTypeDesignationStatus.AUTOMATIC());
83
        validateHasNoConstraint(nameDesignation, validatorClass, group);
84

  
85
        nameDesignation.setTypeStatus(NameTypeDesignationStatus.LECTOTYPE());
86
        validateHasNoConstraint(nameDesignation, validatorClass, group);
87

  
88
        //with source
89
        nameDesignation.setCitation(lectotypeSource);
90
        nameDesignation.setTypeStatus(null);
91
        validateHasConstraint(nameDesignation, validatorClass, group);
92

  
93
        nameDesignation.setTypeStatus(NameTypeDesignationStatus.AUTOMATIC());
94
        validateHasConstraint(nameDesignation, validatorClass, group);
95

  
96
        nameDesignation.setTypeStatus(NameTypeDesignationStatus.LECTOTYPE());
97
        validateHasNoConstraint(nameDesignation, validatorClass, group);
98

  
99
    }
100

  
101
    @Test
102
    public void testSpecimenTypeDesignations() {
103

  
104
        //without source  => never invalid
105
        specimenDesignation = SpecimenTypeDesignation.NewInstance();
106
        validateHasNoConstraint(specimenDesignation, validatorClass, group);
107

  
108
        specimenDesignation.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
109
        validateHasNoConstraint(specimenDesignation, validatorClass, group);
110

  
111
        specimenDesignation.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
112
        validateHasNoConstraint(specimenDesignation, validatorClass, group);
113

  
114
        //with source
115
        specimenDesignation.setCitation(lectotypeSource);
116
        specimenDesignation.setTypeStatus(null);
117
        validateHasConstraint(specimenDesignation, validatorClass, group);
118

  
119
        specimenDesignation.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
120
        validateHasConstraint(specimenDesignation, validatorClass, group);
121

  
122
        specimenDesignation.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
123
        validateHasNoConstraint(specimenDesignation, validatorClass, group);
124

  
125
    }
126

  
127
}
cdmlib-model/src/test/java/eu/etaxonomy/cdm/validation/ValidTypeDesignationTest.java
33 33
 * nomenclatural and taxonomic sense of these words.
34 34
 *
35 35
 * @author a.mueller
36
 *
37
 *
38 36
 */
39 37
public class ValidTypeDesignationTest extends ValidationTestBase {
40 38
	@SuppressWarnings("unused")
......
55 53
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
56 54
		vocabularyStore.initialize();
57 55

  
58

  
59

  
60 56
		name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
61 57
		name1.setNameCache("Aus aus");
62 58

  
......
64 60
	    name2.setNameCache("Aus bus");
65 61

  
66 62
	    specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
67

  
68

  
69 63
	}
70 64

  
71 65

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)