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