Project

General

Profile

Download (11.8 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.model.name;
11

    
12
import java.util.HashSet;
13
import java.util.Set;
14

    
15
import javax.persistence.Entity;
16
import javax.persistence.FetchType;
17
import javax.persistence.Inheritance;
18
import javax.persistence.InheritanceType;
19
import javax.persistence.ManyToMany;
20
import javax.persistence.ManyToOne;
21
import javax.persistence.Transient;
22
import javax.validation.constraints.NotNull;
23
import javax.xml.bind.annotation.XmlElement;
24
import javax.xml.bind.annotation.XmlElementWrapper;
25
import javax.xml.bind.annotation.XmlIDREF;
26
import javax.xml.bind.annotation.XmlRootElement;
27
import javax.xml.bind.annotation.XmlSchemaType;
28
import javax.xml.bind.annotation.XmlSeeAlso;
29
import javax.xml.bind.annotation.XmlType;
30

    
31
import org.apache.log4j.Logger;
32
import org.hibernate.annotations.Cascade;
33
import org.hibernate.annotations.CascadeType;
34
import org.hibernate.envers.Audited;
35
import org.hibernate.search.annotations.IndexedEmbedded;
36

    
37
import eu.etaxonomy.cdm.model.common.CdmBase;
38
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
39
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
40
import eu.etaxonomy.cdm.model.common.SourcedEntityBase;
41
import eu.etaxonomy.cdm.model.reference.Reference;
42
import eu.etaxonomy.cdm.validation.Level2;
43
import eu.etaxonomy.cdm.validation.annotation.ValidLectotypeSource;
44
import eu.etaxonomy.cdm.validation.annotation.ValidTypeDesignation;
45

    
46
/**
47
 * The (abstract) class representing a typification of one or several {@link TaxonName taxon names}.<BR>
48
 * All taxon names which have a {@link Rank rank} "species aggregate" or lower
49
 * can only be typified by specimens (a {@link SpecimenTypeDesignation specimen type designation}), but taxon
50
 * names with a higher rank might be typified by an other taxon name with
51
 * rank "species" or "genus" (a {@link NameTypeDesignation name type designation}).
52
 *
53
 * @see		TaxonName
54
 * @see		NameTypeDesignation
55
 * @see		SpecimenTypeDesignation
56
 * @author  a.mueller
57
 * @since 07.08.2008
58
 */
59
@XmlRootElement(name = "TypeDesignationBase")
60
@XmlType(name = "TypeDesignationBase", propOrder = {
61
    "typeStatus",
62
    "notDesignated",
63
    "typifiedNames",
64
    "citation",
65
    "citationMicroReference",
66
    "registrations",
67
})
68
@XmlSeeAlso({
69
    NameTypeDesignation.class,
70
    SpecimenTypeDesignation.class,
71
    TextualTypeDesignation.class
72
})
73
@Entity
74
@Audited
75
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
76
@ValidTypeDesignation(groups=Level2.class)
77
@ValidLectotypeSource(groups=Level2.class)
78
public abstract class TypeDesignationBase<T extends TypeDesignationStatusBase<T>>
79
        extends SourcedEntityBase<IdentifiableSource>
80
        implements ITypeDesignation {
81

    
82
    private static final long serialVersionUID = 4838214337140859787L;
83

    
84
    @SuppressWarnings("unused")
85
    private static final Logger logger = Logger.getLogger(TypeDesignationBase.class);
86

    
87
    @XmlElement(name = "IsNotDesignated")
88
    private boolean notDesignated;
89

    
90
    @XmlElement(name = "TypeStatus")
91
    @XmlIDREF
92
    @XmlSchemaType(name = "IDREF")
93
    @ManyToOne(fetch = FetchType.LAZY, targetEntity = TypeDesignationStatusBase.class)
94
    private T typeStatus;
95

    
96
    //the lectotype (or similar) reference
97
    @XmlElement(name = "Citation")
98
    @XmlIDREF
99
    @XmlSchemaType(name = "IDREF")
100
    @ManyToOne(fetch = FetchType.LAZY)
101
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
102
    private Reference citation;
103

    
104
    //Details of the lectotype reference.
105
    @XmlElement(name = "CitationMicroReference")
106
    private String citationMicroReference;
107

    
108
    @XmlElementWrapper(name = "TypifiedNames")
109
    @XmlElement(name = "TypifiedName")
110
    @XmlIDREF
111
    @XmlSchemaType(name = "IDREF")
112
    @ManyToMany(fetch = FetchType.LAZY , mappedBy="typeDesignations")
113
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
114
    private Set<TaxonName> typifiedNames = new HashSet<>();
115

    
116
    //******* REGISTRATION *****************/
117

    
118
    @XmlElementWrapper(name = "Registrations")
119
    @XmlElement(name = "Registration")
120
    @XmlIDREF
121
    @XmlSchemaType(name = "IDREF")
122
    @ManyToMany(mappedBy="typeDesignations", fetch= FetchType.LAZY)
123
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
124
    @NotNull
125
    @IndexedEmbedded(depth=1)
126
    private Set<Registration> registrations = new HashSet<>();
127

    
128

    
129
// **************** CONSTRUCTOR *************************************/
130

    
131
    protected TypeDesignationBase(){
132
        super();
133
    }
134

    
135
    /**
136
     * Class constructor: creates a new type designation
137
     * (including its {@link Reference reference source} and eventually
138
     * the taxon name string originally used by this reference when establishing
139
     * the former designation).
140
     *
141
     * @param citation				the reference source for the new designation
142
     * @param citationMicroReference	the string with the details describing the exact localisation within the reference
143
     * @param originalNameString	the taxon name string used originally in the reference source for the new designation
144
     * @see							#TypeDesignationBase()
145
     * @see							#isNotDesignated()
146
     * @see							TaxonName#getTypeDesignations()
147
     */
148
    protected TypeDesignationBase(Reference citation, String citationMicroReference, String originalNameString) {
149
        this(citation, citationMicroReference, originalNameString, false);
150
    }
151

    
152
    /**
153
     * Class constructor: creates a new type designation
154
     * (including its {@link Reference reference source} and eventually
155
     * the taxon name string originally used by this reference when establishing
156
     * the former designation).
157
     *
158
     * @param citation				the reference source for the new designation
159
     * @param citationMicroReference	the string with the details describing the exact localisation within the reference
160
     * @param originalNameString	the taxon name string used originally in the reference source for the new designation
161
     * @param isNotDesignated		the boolean flag indicating whether there is no type at all for
162
     * 								<i>this</i> type designation
163
     * @see							#TypeDesignationBase()
164
     * @see							#isNotDesignated()
165
     * @see							TaxonName#getTypeDesignations()
166
     */
167
    protected TypeDesignationBase(Reference citation, String citationMicroReference, String originalNameString, boolean notDesignated){
168
        super();
169
        this.notDesignated = notDesignated;
170
        this.citationMicroReference = citationMicroReference;
171
        this.citation = citation;
172
    }
173

    
174

    
175
// **************** METHODS *************************************/
176

    
177

    
178
    /**
179
     * Returns the {@link TypeDesignationStatusBase type designation status} for <i>this</i> specimen type
180
     * designation. This status describes which of the possible categories of
181
     * types like "holotype", "neotype", "syntype" or "isotype" applies to <i>this</i>
182
     * specimen type designation.
183
     */
184
    public T getTypeStatus(){
185
        return (CdmBase.deproxy(this.typeStatus));  //otherwise for some error we get an error in TypeDesignationDaoHibernateImplTest
186
    }
187
    /**
188
     * @see  #getTypeStatus()
189
     */
190
    public void setTypeStatus(T typeStatus){
191
        this.typeStatus = typeStatus;
192
    }
193

    
194
    /**
195
     * Returns the boolean value "true" if it is known that a type does not
196
     * exist and therefore the {@link TaxonName taxon name} to which <i>this</i>
197
     * type designation is assigned must still be typified. Two
198
     * cases must be differentiated: <BR><ul>
199
     * <li> a) it is unknown whether a type exists and
200
     * <li> b) it is known that no type exists
201
     *  </ul>
202
     * If a) is true there should be no TypeDesignation instance at all
203
     * assigned to the "typified" taxon name.<BR>
204
     * If b) is true there should be a TypeDesignation instance with the
205
     * flag isNotDesignated set. The typeName attribute, in case of a
206
     * {@link NameTypeDesignation name type designation}, or the typeSpecimen attribute,
207
     * in case of a {@link SpecimenTypeDesignation specimen type designation}, should then be "null".
208
     */
209
    public boolean isNotDesignated() {
210
        return notDesignated;
211
    }
212
    /**
213
     * @see   #isNotDesignated()
214
     */
215
    public void setNotDesignated(boolean notDesignated) {
216
        this.notDesignated = notDesignated;
217
    }
218

    
219
    public String getCitationMicroReference(){
220
        return this.citationMicroReference;
221
    }
222
    public void setCitationMicroReference(String citationMicroReference){
223
        this.citationMicroReference = citationMicroReference;
224
    }
225

    
226
    public Reference getCitation(){
227
        return this.citation;
228
    }
229
    public void setCitation(Reference citation) {
230
        this.citation = citation;
231
    }
232

    
233
    /**
234
     * Returns the {@link Registration registrations} available for this
235
     * type designation.
236
     */
237
    public Set<Registration> getRegistrations() {
238
        return this.registrations;
239
    }
240

    
241
    /**
242
     * Remove the type (specimen or name) from this type designation
243
     */
244
    public abstract void removeType();
245

    
246
    /**
247
     * Returns the set of {@link TaxonName taxon names} typified in <i>this</i>
248
     * type designation. This is a subset of the taxon names belonging to the
249
     * corresponding {@link #getHomotypicalGroup() homotypical group}.
250
     */
251
    @Override
252
    public Set<TaxonName> getTypifiedNames() {
253
        return typifiedNames;
254
    }
255

    
256
    /**
257
     * @deprecated for bidirectional use only
258
     */
259
    @Deprecated
260
    protected void addTypifiedName(TaxonName taxonName){
261
        this.typifiedNames.add(taxonName);
262
    }
263

    
264
    /**
265
     * @deprecated for bidirectional use only
266
     */
267
    @Deprecated
268
    protected void removeTypifiedName(TaxonName taxonName){
269
        this.typifiedNames.remove(taxonName);
270
        if (taxonName.getTypeDesignations().contains(this)){
271
            taxonName.removeTypeDesignation(this);
272
        }
273
    }
274

    
275

    
276
    /**
277
     * {@inheritDoc}
278
     */
279
    @Override
280
    protected IdentifiableSource createNewSource(OriginalSourceType type, String idInSource, String idNamespace,
281
            Reference reference, String microReference, String originalInfo) {
282
        return IdentifiableSource.NewInstance(type, idInSource, idNamespace, reference, microReference, originalInfo);
283
    }
284

    
285

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

    
295
//*********************** CLONE ********************************************************/
296

    
297

    
298
    /**
299
     * Clones <i>this</i> type designation. This is a shortcut that enables to create
300
     * a new instance that differs only slightly from <i>this</i> type designation by
301
     * modifying only some of the attributes.<BR>
302
     * CAUTION: the typifiedNames set is also cloned by adding the new type designation
303
     * to the typifiedNames of the original type designation. If this is unwanted
304
     * th
305
     *
306
     * not cloned but empty after cloning as the typified
307
     * names is considered to be the not owning part of a bidirectional relationship.
308
     * This may be changed in future.
309
     *
310
     * @throws CloneNotSupportedException
311
     *
312
     * @see eu.etaxonomy.cdm.model.common.ReferencedEntityBase#clone()
313
     * @see java.lang.Object#clone()
314
     */
315
    @Override
316
    public Object clone() throws CloneNotSupportedException {
317
        TypeDesignationBase<?> result = (TypeDesignationBase<?>)super.clone();
318

    
319
		//registrations
320
		result.registrations = new HashSet<>();
321
		for (Registration registration : registrations){
322
		    registration.addTypeDesignation(result);
323
		}
324

    
325
        //typified names
326
        result.typifiedNames = new HashSet<>();
327
        for (TaxonName taxonName : getTypifiedNames()){
328
            taxonName.addTypeDesignation(result, false);
329
        }
330

    
331
        //no changes to: notDesignated, typeStatus, homotypicalGroup
332
        return result;
333
    }
334
}
(34-34/37)