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
|
|
13
|
|
14
|
import java.util.HashSet;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import javax.persistence.Entity;
|
18
|
import javax.persistence.FetchType;
|
19
|
import javax.persistence.ManyToMany;
|
20
|
import javax.persistence.ManyToOne;
|
21
|
import javax.persistence.Transient;
|
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.XmlElementWrapper;
|
26
|
import javax.xml.bind.annotation.XmlIDREF;
|
27
|
import javax.xml.bind.annotation.XmlRootElement;
|
28
|
import javax.xml.bind.annotation.XmlSchemaType;
|
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
|
import org.joda.time.Partial;
|
37
|
|
38
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
39
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
40
|
import eu.etaxonomy.cdm.model.common.EventBase;
|
41
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
42
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
44
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
45
|
|
46
|
/**
|
47
|
* @author m.doering
|
48
|
* @since 08-Nov-2007 13:06:21
|
49
|
*/
|
50
|
@XmlAccessorType(XmlAccessType.FIELD)
|
51
|
@XmlType(name = "DeterminationEvent", propOrder = {
|
52
|
"identifiedUnit",
|
53
|
"taxon",
|
54
|
"taxonName",
|
55
|
"modifier",
|
56
|
"preferredFlag",
|
57
|
"setOfReferences"
|
58
|
})
|
59
|
@XmlRootElement(name = "DeterminationEvent")
|
60
|
@Entity
|
61
|
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
|
62
|
//@Indexed
|
63
|
@Audited
|
64
|
public class DeterminationEvent extends EventBase {
|
65
|
private static final long serialVersionUID = 5065341354427569773L;
|
66
|
|
67
|
private static final Logger logger = Logger.getLogger(DeterminationEvent.class);
|
68
|
|
69
|
@XmlElement(name = "IdentifiedUnit")
|
70
|
@XmlIDREF
|
71
|
@XmlSchemaType(name = "IDREF")
|
72
|
@ManyToOne(fetch = FetchType.LAZY)
|
73
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
74
|
private SpecimenOrObservationBase<?> identifiedUnit;
|
75
|
|
76
|
@XmlElement(name = "Taxon")
|
77
|
@XmlIDREF
|
78
|
@XmlSchemaType(name = "IDREF")
|
79
|
@ManyToOne(fetch = FetchType.LAZY)
|
80
|
@IndexedEmbedded(includeEmbeddedObjectId=true)
|
81
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
82
|
private TaxonBase<?> taxon;
|
83
|
|
84
|
// #4518
|
85
|
@XmlElement(name = "TaxonName")
|
86
|
@XmlIDREF
|
87
|
@XmlSchemaType(name = "IDREF")
|
88
|
@ManyToOne(fetch = FetchType.LAZY)
|
89
|
@IndexedEmbedded(includeEmbeddedObjectId=true)
|
90
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
91
|
private TaxonName taxonName;
|
92
|
|
93
|
@XmlElement(name = "Modifier")
|
94
|
@XmlIDREF
|
95
|
@XmlSchemaType(name = "IDREF")
|
96
|
@ManyToOne(fetch = FetchType.LAZY)
|
97
|
private DefinedTerm modifier;
|
98
|
|
99
|
@XmlElement(name = "PreferredFlag")
|
100
|
private boolean preferredFlag;
|
101
|
|
102
|
@XmlElementWrapper(name = "SetOfReferences")
|
103
|
@XmlElement(name = "Reference")
|
104
|
@XmlIDREF
|
105
|
@XmlSchemaType(name = "IDREF")
|
106
|
@ManyToMany(fetch = FetchType.LAZY)
|
107
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
108
|
private Set<Reference> setOfReferences = new HashSet<>();
|
109
|
|
110
|
|
111
|
|
112
|
/**
|
113
|
* Factory method
|
114
|
* @return
|
115
|
*/
|
116
|
public static DeterminationEvent NewInstance(){
|
117
|
return new DeterminationEvent();
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Factory method
|
122
|
* @return
|
123
|
*/
|
124
|
public static DeterminationEvent NewInstance(Taxon taxon, SpecimenOrObservationBase identifiedUnit ){
|
125
|
DeterminationEvent result = new DeterminationEvent();
|
126
|
result.setTaxon(taxon);
|
127
|
result.setIdentifiedUnit(identifiedUnit);
|
128
|
identifiedUnit.addDetermination(result);
|
129
|
return result;
|
130
|
}
|
131
|
|
132
|
public static DeterminationEvent NewInstance(TaxonName name, SpecimenOrObservationBase identifiedUnit ){
|
133
|
DeterminationEvent result = new DeterminationEvent();
|
134
|
result.setTaxonName(name);
|
135
|
result.setIdentifiedUnit(identifiedUnit);
|
136
|
identifiedUnit.addDetermination(result);
|
137
|
return result;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Constructor
|
142
|
*/
|
143
|
protected DeterminationEvent() {
|
144
|
super();
|
145
|
}
|
146
|
|
147
|
public DefinedTerm getModifier() {
|
148
|
return modifier;
|
149
|
}
|
150
|
|
151
|
public void setModifier(DefinedTerm modifier) {
|
152
|
this.modifier = modifier;
|
153
|
}
|
154
|
|
155
|
public TaxonBase getTaxon(){
|
156
|
return this.taxon;
|
157
|
}
|
158
|
|
159
|
/*** @param taxon the */
|
160
|
public void setTaxonName(TaxonName taxonName){
|
161
|
this.taxonName = taxonName;
|
162
|
}
|
163
|
|
164
|
public TaxonName getTaxonName(){
|
165
|
return this.taxonName;
|
166
|
}
|
167
|
|
168
|
/*** @param taxon the */
|
169
|
public void setTaxon(TaxonBase taxon){
|
170
|
this.taxon = taxon;
|
171
|
}
|
172
|
|
173
|
@Transient
|
174
|
public Partial getIdentificationDate(){
|
175
|
return this.getTimeperiod().getStart();
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
*
|
180
|
* @param identificationDate identificationDate
|
181
|
*/
|
182
|
public void setIdentificationDate(Partial identificationDate){
|
183
|
this.getTimeperiod().setStart(identificationDate);
|
184
|
}
|
185
|
|
186
|
@Transient
|
187
|
public AgentBase getDeterminer() {
|
188
|
return this.getActor();
|
189
|
}
|
190
|
|
191
|
public void setDeterminer(AgentBase determiner) {
|
192
|
this.setActor(determiner);
|
193
|
}
|
194
|
|
195
|
public SpecimenOrObservationBase getIdentifiedUnit() {
|
196
|
return identifiedUnit;
|
197
|
}
|
198
|
|
199
|
public void setIdentifiedUnit(SpecimenOrObservationBase identifiedUnit) {
|
200
|
this.identifiedUnit = identifiedUnit;
|
201
|
}
|
202
|
|
203
|
public boolean getPreferredFlag() {
|
204
|
return preferredFlag;
|
205
|
}
|
206
|
|
207
|
public void setPreferredFlag(boolean preferredFlag) {
|
208
|
this.preferredFlag = preferredFlag;
|
209
|
}
|
210
|
|
211
|
public Set<Reference> getReferences() {
|
212
|
return setOfReferences;
|
213
|
}
|
214
|
|
215
|
public void setReferences(Set<Reference> references) {
|
216
|
this.setOfReferences = references;
|
217
|
}
|
218
|
|
219
|
public void addReference(Reference reference) {
|
220
|
this.setOfReferences.add(reference);
|
221
|
}
|
222
|
|
223
|
//*********** CLONE **********************************/
|
224
|
|
225
|
/**
|
226
|
* Clones <i>this</i> determination event. This is a shortcut that enables to
|
227
|
* create a new instance that differs only slightly from <i>this</i> determination event
|
228
|
* by modifying only some of the attributes.<BR>
|
229
|
* This method overrides the clone method from {@link EventBase EventBase}.
|
230
|
*
|
231
|
* @see EventBase#clone()
|
232
|
* @see java.lang.Object#clone()
|
233
|
*/
|
234
|
@Override
|
235
|
public DeterminationEvent clone(){
|
236
|
try{
|
237
|
DeterminationEvent result = (DeterminationEvent)super.clone();
|
238
|
//type
|
239
|
result.setIdentifiedUnit(this.getIdentifiedUnit());
|
240
|
//modifier
|
241
|
result.setModifier(this.getModifier());
|
242
|
//taxon
|
243
|
result.setTaxon(this.getTaxon()); //TODO
|
244
|
//no changes to: preferredFlag
|
245
|
return result;
|
246
|
} catch (CloneNotSupportedException e) {
|
247
|
logger.warn("Object does not implement cloneable");
|
248
|
e.printStackTrace();
|
249
|
return null;
|
250
|
}
|
251
|
}
|
252
|
|
253
|
}
|