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.occurrence;
|
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.ManyToOne;
|
18
|
import javax.persistence.OneToMany;
|
19
|
import javax.persistence.Transient;
|
20
|
import javax.xml.bind.annotation.XmlAccessType;
|
21
|
import javax.xml.bind.annotation.XmlAccessorType;
|
22
|
import javax.xml.bind.annotation.XmlElement;
|
23
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
24
|
import javax.xml.bind.annotation.XmlIDREF;
|
25
|
import javax.xml.bind.annotation.XmlRootElement;
|
26
|
import javax.xml.bind.annotation.XmlSchemaType;
|
27
|
import javax.xml.bind.annotation.XmlType;
|
28
|
|
29
|
import org.hibernate.annotations.Cascade;
|
30
|
import org.hibernate.annotations.CascadeType;
|
31
|
import org.hibernate.envers.Audited;
|
32
|
import org.hibernate.search.annotations.Field;
|
33
|
import org.hibernate.search.annotations.Index;
|
34
|
import org.hibernate.search.annotations.Indexed;
|
35
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
36
|
import org.hibernate.validator.constraints.Length;
|
37
|
|
38
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
39
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
40
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
41
|
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
|
42
|
|
43
|
/**
|
44
|
* http://www.bgbm.org/biodivinf/docs/CollectionModel/ReprintTNR.pdf
|
45
|
* http://www.bgbm.org/biodivinf/docs/CollectionModel/
|
46
|
* <BR>
|
47
|
* Type figures are derived units with at least a figure object in media
|
48
|
*
|
49
|
* @author markus
|
50
|
*
|
51
|
*/
|
52
|
@XmlAccessorType(XmlAccessType.FIELD)
|
53
|
@XmlType(name = "DerivedUnitBase", propOrder = {
|
54
|
"collection",
|
55
|
"catalogNumber",
|
56
|
"storedUnder",
|
57
|
"derivedFrom",
|
58
|
"accessionNumber",
|
59
|
"collectorsNumber",
|
60
|
"barcode"
|
61
|
})
|
62
|
@XmlRootElement(name = "DerivedUnitBase")
|
63
|
@Entity
|
64
|
@Indexed(index = "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase")
|
65
|
@Audited
|
66
|
public abstract class DerivedUnitBase<S extends IIdentifiableEntityCacheStrategy> extends SpecimenOrObservationBase<S> implements Cloneable{
|
67
|
|
68
|
@XmlElement(name = "Collection")
|
69
|
@XmlIDREF
|
70
|
@XmlSchemaType(name = "IDREF")
|
71
|
@ManyToOne(fetch = FetchType.LAZY)
|
72
|
@Cascade(CascadeType.SAVE_UPDATE)
|
73
|
@IndexedEmbedded
|
74
|
private Collection collection;
|
75
|
|
76
|
@XmlElement(name = "CatalogNumber")
|
77
|
@Field(index=Index.UN_TOKENIZED)
|
78
|
@NullOrNotEmpty
|
79
|
@Length(max = 255)
|
80
|
private String catalogNumber;
|
81
|
|
82
|
@XmlElement(name = "AccessionNumber")
|
83
|
@Field(index=Index.UN_TOKENIZED)
|
84
|
@NullOrNotEmpty
|
85
|
@Length(max = 255)
|
86
|
private String accessionNumber;
|
87
|
|
88
|
@XmlElement(name = "CollectorsNumber")
|
89
|
@Field(index=Index.UN_TOKENIZED)
|
90
|
@NullOrNotEmpty
|
91
|
@Length(max = 255)
|
92
|
private String collectorsNumber;
|
93
|
|
94
|
@XmlElement(name = "Barcode")
|
95
|
@Field(index=Index.UN_TOKENIZED)
|
96
|
@NullOrNotEmpty
|
97
|
@Length(max = 255)
|
98
|
private String barcode;
|
99
|
|
100
|
@XmlElement(name = "StoredUnder")
|
101
|
@XmlIDREF
|
102
|
@XmlSchemaType(name = "IDREF")
|
103
|
@ManyToOne(fetch = FetchType.LAZY)
|
104
|
@Cascade(CascadeType.SAVE_UPDATE)
|
105
|
@IndexedEmbedded
|
106
|
private TaxonNameBase storedUnder;
|
107
|
|
108
|
@XmlElement(name = "DerivedFrom")
|
109
|
@XmlIDREF
|
110
|
@XmlSchemaType(name = "IDREF")
|
111
|
@ManyToOne(fetch = FetchType.LAZY)
|
112
|
@Cascade(CascadeType.SAVE_UPDATE)
|
113
|
@IndexedEmbedded(depth = 4)
|
114
|
private DerivationEvent derivedFrom;
|
115
|
/*
|
116
|
@XmlElementWrapper(name = "SpecimenTypeDesignations")
|
117
|
@XmlElement(name = "SpecimenTypeDesignation")
|
118
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "typeSpecimen")
|
119
|
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE })
|
120
|
private Set<SpecimenTypeDesignation> specimenTypeDesignations = new HashSet<SpecimenTypeDesignation>();
|
121
|
*/
|
122
|
/**
|
123
|
* Constructor
|
124
|
*/
|
125
|
protected DerivedUnitBase() {
|
126
|
super();
|
127
|
}
|
128
|
/**
|
129
|
* create new unit derived from an existing field observation
|
130
|
* @param fieldObservation existing field observation from where this unit is derived
|
131
|
*/
|
132
|
protected DerivedUnitBase(FieldObservation fieldObservation) {
|
133
|
super();
|
134
|
DerivationEvent derivedFrom = new DerivationEvent();
|
135
|
// TODO: should be done in a more controlled way. Probably by making derivation event implement a general relationship interface (for bidirectional add/remove etc)
|
136
|
fieldObservation.addDerivationEvent(derivedFrom);
|
137
|
derivedFrom.getOriginals().add(fieldObservation);
|
138
|
derivedFrom.getDerivatives().add(this);
|
139
|
this.setDerivedFrom(derivedFrom);
|
140
|
}
|
141
|
/**
|
142
|
* create new unit derived from an existing gathering event,
|
143
|
* thereby creating a new empty field observation
|
144
|
* @param gatheringEvent the gathering event this unit was collected at
|
145
|
*/
|
146
|
protected DerivedUnitBase(GatheringEvent gatheringEvent) {
|
147
|
this(new FieldObservation());
|
148
|
FieldObservation field = (FieldObservation)this.getOriginalUnit();
|
149
|
field.setGatheringEvent(gatheringEvent);
|
150
|
}
|
151
|
|
152
|
|
153
|
public DerivationEvent getDerivedFrom() {
|
154
|
return derivedFrom;
|
155
|
}
|
156
|
|
157
|
public void setDerivedFrom(DerivationEvent derivedFrom){
|
158
|
if (getDerivedFrom() != null){
|
159
|
getDerivedFrom().getDerivatives().remove(derivedFrom);
|
160
|
}
|
161
|
this.derivedFrom = derivedFrom;
|
162
|
if (derivedFrom != null){
|
163
|
derivedFrom.addDerivative(this);
|
164
|
}
|
165
|
}
|
166
|
|
167
|
@Transient
|
168
|
public Set<SpecimenOrObservationBase> getOriginals(){
|
169
|
if(getDerivedFrom() != null){
|
170
|
return getDerivedFrom().getOriginals();
|
171
|
}
|
172
|
return null;
|
173
|
}
|
174
|
|
175
|
public Collection getCollection(){
|
176
|
return this.collection;
|
177
|
}
|
178
|
|
179
|
public void setCollection(Collection collection){
|
180
|
this.collection = collection;
|
181
|
}
|
182
|
|
183
|
|
184
|
public String getCatalogNumber() {
|
185
|
return catalogNumber;
|
186
|
}
|
187
|
|
188
|
public void setCatalogNumber(String catalogNumber) {
|
189
|
this.catalogNumber = catalogNumber;
|
190
|
}
|
191
|
|
192
|
public void setBarcode(String barcode) {
|
193
|
this.barcode = barcode;
|
194
|
}
|
195
|
public String getBarcode() {
|
196
|
return barcode;
|
197
|
}
|
198
|
|
199
|
public void setStoredUnder(TaxonNameBase storedUnder) {
|
200
|
this.storedUnder = storedUnder;
|
201
|
}
|
202
|
|
203
|
public String getAccessionNumber() {
|
204
|
return accessionNumber;
|
205
|
}
|
206
|
|
207
|
|
208
|
public void setAccessionNumber(String accessionNumber) {
|
209
|
this.accessionNumber = accessionNumber;
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* Will be removed in future versions as semantics is not clear.
|
214
|
* For accessing the collecting number use
|
215
|
* {@link FieldObservation#getFieldNumber()} instead.
|
216
|
* @return
|
217
|
*/
|
218
|
@Deprecated
|
219
|
public String getCollectorsNumber() {
|
220
|
return collectorsNumber;
|
221
|
}
|
222
|
|
223
|
/**
|
224
|
* Will be removed in future versions as semantics is not clear.
|
225
|
* For editing the collecting number use
|
226
|
* {@link FieldObservation#getFieldNumber()} instead.
|
227
|
* @return
|
228
|
*/
|
229
|
@Deprecated
|
230
|
public void setCollectorsNumber(String collectorsNumber) {
|
231
|
this.collectorsNumber = collectorsNumber;
|
232
|
}
|
233
|
|
234
|
public TaxonNameBase getStoredUnder() {
|
235
|
return storedUnder;
|
236
|
}
|
237
|
/*
|
238
|
public void addSpecimenTypeDesignation(SpecimenTypeDesignation specimenTypeDesignation){
|
239
|
specimenTypeDesignations.add(specimenTypeDesignation);
|
240
|
}
|
241
|
|
242
|
public Set<SpecimenTypeDesignation> getSpecimenTypeDesignations(){
|
243
|
return specimenTypeDesignations;
|
244
|
}
|
245
|
*/
|
246
|
//*********** CLONE **********************************/
|
247
|
|
248
|
/**
|
249
|
* Clones <i>this</i> derivedUnitBase. This is a shortcut that enables to
|
250
|
* create a new instance that differs only slightly from <i>this</i> specimen
|
251
|
* by modifying only some of the attributes.<BR>
|
252
|
* This method overrides the clone method from {@link SpecimenOrObservationBase SpecimenOrObservationBase}.
|
253
|
*
|
254
|
* @see SpecimenOrObservationBase#clone()
|
255
|
* @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
|
256
|
* @see java.lang.Object#clone()
|
257
|
*/
|
258
|
@Override
|
259
|
public Object clone() throws CloneNotSupportedException{
|
260
|
DerivedUnitBase result = (DerivedUnitBase)super.clone();
|
261
|
//collection
|
262
|
result.setCollection(this.collection);
|
263
|
//derivedFrom
|
264
|
result.setDerivedFrom(this.derivedFrom);
|
265
|
//storedUnder
|
266
|
result.setStoredUnder(this.storedUnder);
|
267
|
//no changes to: accessionNumber, catalogNumber, collectorsNumber
|
268
|
return result;
|
269
|
}
|
270
|
|
271
|
}
|