Project

General

Profile

Download (12.3 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.description;
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.JoinTable;
20
import javax.persistence.ManyToMany;
21
import javax.persistence.OneToMany;
22
import javax.xml.bind.annotation.XmlAccessType;
23
import javax.xml.bind.annotation.XmlAccessorType;
24
import javax.xml.bind.annotation.XmlElement;
25
import javax.xml.bind.annotation.XmlElementRef;
26
import javax.xml.bind.annotation.XmlElementWrapper;
27
import javax.xml.bind.annotation.XmlElements;
28
import javax.xml.bind.annotation.XmlIDREF;
29
import javax.xml.bind.annotation.XmlSchemaType;
30
import javax.xml.bind.annotation.XmlType;
31

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

    
37
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
38
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
39
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
40
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
41
import eu.etaxonomy.cdm.model.taxon.Taxon;
42
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
43

    
44
/**
45
 * The upmost (abstract) class for a description as a whole (with possibly
46
 * several {@link DescriptionElementBase elementary information data})
47
 * for a {@link SpecimenOrObservationBase specimen}, a {@link Taxon taxon}
48
 * or even a {@link TaxonNameBase taxon name}.
49
 * <P>
50
 * This class corresponds to: <ul>
51
 * <li> DescriptionsSectionType according to the the SDD schema
52
 * <li> MeasurementOrFact according to the ABCD schema
53
 * </ul>
54
 * 
55
 * @author m.doering
56
 * @version 1.0
57
 * @created 08-Nov-2007 13:06:24
58
 */
59

    
60
@XmlAccessorType(XmlAccessType.FIELD)
61
@XmlType(name = "DescriptionBase", propOrder = {
62
    "describedSpecimenOrObservations",
63
    "descriptionSources",
64
    "descriptiveSystem",
65
    "descriptionElements",
66
    "imageGallery"
67
})
68
@Entity
69
@Audited
70
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
71
public abstract class DescriptionBase<S extends IIdentifiableEntityCacheStrategy> extends IdentifiableEntity<S> {
72
	private static final long serialVersionUID = 5504218413819040193L;
73
	private static final Logger logger = Logger.getLogger(DescriptionBase.class);
74
	
75
	@XmlElementWrapper(name = "DescribedSpecimenOrObservations")
76
	@XmlElement(name = "DescribedSpecimenOrObservation")
77
	@XmlIDREF
78
	@XmlSchemaType(name="IDREF")
79
	@ManyToMany(fetch = FetchType.LAZY)
80
	@Cascade(CascadeType.SAVE_UPDATE)
81
	private Set<SpecimenOrObservationBase> describedSpecimenOrObservations = new HashSet<SpecimenOrObservationBase>();
82
	
83
	@XmlElementWrapper(name = "DescriptionSources")
84
	@XmlElement(name = "DescriptionSource")
85
	@XmlIDREF
86
	@XmlSchemaType(name="IDREF")
87
	@ManyToMany(fetch = FetchType.LAZY)  //FIXME what is the difference between this and IdentifiableEntity.sources
88
	private Set<ReferenceBase> descriptionSources = new HashSet<ReferenceBase>();
89
	
90
	@XmlElementWrapper(name = "DescriptiveSystem")
91
	@XmlElement(name = "Feature")
92
	@XmlIDREF
93
	@XmlSchemaType(name="IDREF")
94
	@ManyToMany(fetch = FetchType.LAZY)  //FIXME
95
    //@Cascade( { CascadeType.SAVE_UPDATE, CascadeType.MERGE })
96
    @JoinTable(name = "DescriptionBase_Feature")
97
	private Set<Feature> descriptiveSystem = new HashSet<Feature>();
98
	
99
	@XmlElementWrapper(name = "DescriptionElements")
100
    @XmlElements({
101
        @XmlElement(name = "CategorialData", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = CategoricalData.class),
102
        @XmlElement(name = "CommonTaxonName", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = CommonTaxonName.class),
103
        @XmlElement(name = "Distribution", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = Distribution.class),
104
        @XmlElement(name = "IndividualsAssociation", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = IndividualsAssociation.class),
105
        @XmlElement(name = "QuantitativeData", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = QuantitativeData.class),
106
        @XmlElement(name = "TaxonInteraction", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TaxonInteraction.class),
107
        @XmlElement(name = "TextData", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TextData.class)
108
    })
109
    @OneToMany(fetch=FetchType.LAZY, mappedBy = "inDescription")
110
	@Cascade( { CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN })
111
	private Set<DescriptionElementBase> descriptionElements = new HashSet<DescriptionElementBase>();
112

    
113
	@XmlElement(name = "ImageGallery")
114
	private boolean imageGallery;
115
	
116
	
117
	/**
118
	 * Returns the set of {@link SpecimenOrObservationBase specimens or observations} involved in
119
	 * <i>this</i> description as a whole. {@link TaxonDescription Taxon descriptions} are also often based
120
	 * on concrete specimens or observations. For {@link TaxonNameDescription taxon name descriptions}
121
	 * this set should be empty.
122
	 * 
123
	 * @see    #addDescribedSpecimenOrObservations(SpecimenOrObservationBase)
124
	 * @see    #removeDescribedSpecimenOrObservations(SpecimenOrObservationBase)
125
	 */
126
	public Set<SpecimenOrObservationBase> getDescribedSpecimenOrObservations() {
127
		return describedSpecimenOrObservations;
128
	}
129
	
130
	/**
131
	 * Adds an existing {@link SpecimenOrObservationBase specimen or observation} to the set of
132
	 * {@link #getDescribedSpecimenOrObservations() specimens or observations} described in <i>this</i>
133
	 * description or which <i>this</i> description is based on.<BR>
134
	 * Due to bidirectionality if <i>this</i> description is a {@link SpecimenDescription specimen description},
135
	 * <i>this</i> description will also be added to the set of specimen
136
	 * descriptions corresponding to the given additional specimen or observation.
137
	 * 
138
	 * @param describedSpecimenOrObservation	the specimen or observation to be added to <i>this</i> description
139
	 * @see    	   								#getDescribedSpecimenOrObservations()
140
	 * @see    	   								SpecimenOrObservationBase#addDescription(DescriptionBase)
141
	 */
142
	public void addDescribedSpecimenOrObservation(SpecimenOrObservationBase describedSpecimenOrObservation) {
143
		logger.debug("addDescribedSpecimenOrObservations");
144
		this.describedSpecimenOrObservations.add(describedSpecimenOrObservation);
145
		if (! describedSpecimenOrObservation.getDescriptions().contains(this)){
146
			describedSpecimenOrObservation.addDescription(this);
147
		}
148
	}
149
	
150
	/** 
151
	 * Removes one element from the set of {@link #getDescribedSpecimenOrObservations() specimens or observations} involved
152
	 * in <i>this</i> description.<BR>
153
	 * Due to bidirectionality if <i>this</i> description is a {@link SpecimenDescription specimen description},
154
	 * <i>this</i> description will also be removed from the set of specimen
155
	 * descriptions corresponding to the given specimen or observation.
156
	 *
157
	 * @param  describedSpecimenOrObservation   the specimen or observation which should be removed
158
	 * @see     		  						#getDescribedSpecimenOrObservations()
159
	 * @see     		  						#addDescribedSpecimenOrObservations(SpecimenOrObservationBase)
160
	 * @see     		  						SpecimenOrObservationBase#removeDescription(DescriptionBase)
161
	 */
162
	public void removeDescribedSpecimenOrObservation(SpecimenOrObservationBase describedSpecimenOrObservation) {
163
		this.describedSpecimenOrObservations.remove(describedSpecimenOrObservation);
164
		if (describedSpecimenOrObservation.getDescriptions().contains(this)){
165
			describedSpecimenOrObservation.removeDescription(this);
166
		}
167
	}
168

    
169
	/**
170
	 * Returns the set of {@link ReferenceBase references} used as sources for <i>this</i> description as a
171
	 * whole. More than one source can be used for a general description without
172
	 * assigning for each data element of the description one of those sources. 
173
	 * 
174
	 * @see    #addDescriptionSource(ReferenceBase)
175
	 * @see    #removeDescriptionSource(ReferenceBase)
176
	 */
177
	public Set<ReferenceBase> getDescriptionSources() {
178
		return this.descriptionSources;
179
	}
180
	
181
	/**
182
	 * Adds an existing {@link ReferenceBase reference} to the set of
183
	 * {@link #getDescriptionSources() references} used as sources for <i>this</i>
184
	 * description.
185
	 * 
186
	 * @param descriptionSource	the reference source to be added to <i>this</i> description
187
	 * @see    	   				#getDescriptionSources()
188
	 */
189
	public void addDescriptionSource(ReferenceBase descriptionSource) {
190
		this.descriptionSources.add(descriptionSource);
191
	}
192
	
193
	/** 
194
	 * Removes one element from the set of {@link #getDescriptionSources() references} used as
195
	 * sources for <i>this</i> description.
196
	 *
197
	 * @param  descriptionSource	the reference source which should be deleted
198
	 * @see     		  			#getDescriptionSources()
199
	 * @see     		  			#addDescriptionSource(ReferenceBase)
200
	 */
201
	public void removeDescriptionSource(ReferenceBase descriptionSource) {
202
		this.descriptionSources.remove(descriptionSource);
203
	}
204

    
205
	/**
206
	 * Returns the set of {@link Feature feature} used as 
207
	 * features/characters/descriptors for <i>this</i> description.
208
	 * 
209
	 * @see    #addFeature(Feature)
210
	 * @see    #removeFeature(Feature)
211
	 */
212
	public Set<Feature> getDescriptiveSystem() {
213
		return this.descriptiveSystem;
214
	}
215
	
216
	/** 
217
	 * @see    #getDescriptiveSystem()
218
	 * @see    #addDescriptiveSystem(Feature)
219
	 */
220
	public void setDescriptiveSystem(Set<Feature> descriptiveSystem) {
221
		this.descriptiveSystem = descriptiveSystem;
222
	}
223
	
224
	/**
225
	 * Adds an existing {@link Feature feature} to the set of
226
	 * {@link #getDescriptiveSystem() descriptiveSystem} used as features for
227
	 * <i>this</i> description.
228
	 * 
229
	 * @param feature	the feature to be added to the descriptive system
230
	 * @see     #getDescriptiveSystem()
231
	 */
232
	public void addFeature(Feature feature) {
233
		this.descriptiveSystem.add(feature);
234
	}
235
	
236
	/** 
237
	 * Removes one element from the set of {@link #getDescriptiveSystem() features} used as
238
	 * features for <i>this</i> description.
239
	 *
240
	 * @param  feature	the feature which should be deleted
241
	 * @see     #getDescriptiveSystem()
242
	 * @see     addFeature(Feature)
243
	 */
244
	public void removeFeature(Feature feature) {
245
		this.descriptiveSystem.remove(feature);
246
	}
247
	
248
	/**
249
	 * Returns the set of {@link DescriptionElementBase elementary description data} which constitute
250
	 * <i>this</i> description as a whole. 
251
	 * 
252
	 * @see    #addElement(DescriptionElementBase)
253
	 * @see    #removeElement(DescriptionElementBase)
254
	 */
255
	public Set<DescriptionElementBase> getElements() {
256
		return this.descriptionElements;
257
	}
258

    
259
	/**
260
	 * Adds an existing {@link DescriptionElementBase elementary description} to the set of
261
	 * {@link #getElements() elementary description data} which constitute <i>this</i>
262
	 * description as a whole.
263
	 * If the elementary descriptions already belongs to a description it is first removed from
264
	 * the old description.
265
	 * 
266
	 * @param element	the elementary description to be added to <i>this</i> description
267
	 * @see    	   		#getDescriptionSources()
268
	 */
269
	public void addElement(DescriptionElementBase element) {
270
		if (element.getInDescription() != null){
271
			element.getInDescription().removeElement(element);
272
		}
273
		element.setInDescription(this);
274
		this.descriptionElements.add(element);
275
	}
276

    
277
	/** 
278
	 * Removes one element from the set of {@link #getElements() elementary description data} which
279
	 * constitute <i>this</i> description as a whole.
280
	 *
281
	 * @param  element	the reference source which should be deleted
282
	 * @see     		#getElements()
283
	 * @see     		#addElement(DescriptionElementBase)
284
	 */
285
	public void removeElement(DescriptionElementBase element) {
286
		this.descriptionElements.remove(element);
287
		element.setInDescription(null);
288
	}
289
	
290
	/**
291
	 * Returns the number of {@link DescriptionElementBase elementary description data} which constitute
292
	 * <i>this</i> description as a whole. This is the cardinality of the set of
293
	 * elementary description data.
294
	 * 
295
	 * @see		#getElements()
296
	 * @return	the number of elements of the elementary description data set
297
	 */
298
	public int size(){
299
		return this.descriptionElements.size();
300
	}
301
	
302
    /**
303
	 * @return the imageGallery
304
	 */
305
	public boolean isImageGallery() {
306
		return imageGallery;
307
	}
308

    
309
	/**
310
	 * @param imageGallery the imageGallery to set
311
	 */
312
	public void setImageGallery(boolean imageGallery) {
313
		this.imageGallery = imageGallery;
314
	}
315
}
(4-4/36)