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
|
package eu.etaxonomy.cdm.model.occurrence;
|
10
|
|
11
|
import java.beans.PropertyChangeEvent;
|
12
|
import java.beans.PropertyChangeListener;
|
13
|
|
14
|
import javax.persistence.Column;
|
15
|
import javax.persistence.Entity;
|
16
|
import javax.persistence.FetchType;
|
17
|
import javax.persistence.ManyToOne;
|
18
|
import javax.validation.Valid;
|
19
|
import javax.xml.bind.annotation.XmlAccessType;
|
20
|
import javax.xml.bind.annotation.XmlAccessorType;
|
21
|
import javax.xml.bind.annotation.XmlElement;
|
22
|
import javax.xml.bind.annotation.XmlIDREF;
|
23
|
import javax.xml.bind.annotation.XmlRootElement;
|
24
|
import javax.xml.bind.annotation.XmlSchemaType;
|
25
|
import javax.xml.bind.annotation.XmlType;
|
26
|
|
27
|
import org.apache.logging.log4j.LogManager;
|
28
|
import org.apache.logging.log4j.Logger;
|
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.Indexed;
|
34
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
35
|
import org.springframework.beans.factory.annotation.Configurable;
|
36
|
|
37
|
import eu.etaxonomy.cdm.model.agent.Person;
|
38
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
39
|
import eu.etaxonomy.cdm.strategy.cache.occurrence.FieldUnitDefaultCacheStrategy;
|
40
|
|
41
|
/**
|
42
|
*
|
43
|
* In situ observation of a taxon in the field. If a specimen exists,
|
44
|
* in most cases a parallel field unit object should be instantiated and the specimen then
|
45
|
* is "derived" from the field unit via derivation type "accessioning" or any other.
|
46
|
*
|
47
|
* @author m.doering
|
48
|
* @since 08-Nov-2007 13:06:40
|
49
|
*/
|
50
|
@XmlAccessorType(XmlAccessType.FIELD)
|
51
|
@XmlType(name = "FieldUnit", propOrder = {
|
52
|
"fieldNumber",
|
53
|
"primaryCollector",
|
54
|
"fieldNotes",
|
55
|
"gatheringEvent"
|
56
|
})
|
57
|
@XmlRootElement(name = "FieldUnit")
|
58
|
@Entity
|
59
|
@Indexed(index = "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase")
|
60
|
@Audited
|
61
|
@Configurable
|
62
|
public class FieldUnit extends SpecimenOrObservationBase<IIdentifiableEntityCacheStrategy<FieldUnit>> implements Cloneable{
|
63
|
|
64
|
private static final long serialVersionUID = -7586670941559035171L;
|
65
|
private static final Logger logger = LogManager.getLogger(FieldUnit.class);
|
66
|
|
67
|
@XmlElement(name = "FieldNumber")
|
68
|
@Field
|
69
|
//TODO Val #3379
|
70
|
// @NullOrNotEmpty
|
71
|
@Column(length=255)
|
72
|
private String fieldNumber;
|
73
|
|
74
|
@XmlElement(name = "PrimaryCollector")
|
75
|
@XmlIDREF
|
76
|
@XmlSchemaType(name = "IDREF")
|
77
|
@ManyToOne(fetch = FetchType.LAZY)
|
78
|
@Cascade( { CascadeType.SAVE_UPDATE,CascadeType.MERGE })
|
79
|
@IndexedEmbedded(depth = 2)
|
80
|
@Valid
|
81
|
private Person primaryCollector;
|
82
|
|
83
|
@XmlElement(name = "FieldNotes")
|
84
|
@Field
|
85
|
//TODO Val #3379
|
86
|
// @NullOrNotEmpty
|
87
|
@Column(length=255)
|
88
|
private String fieldNotes;
|
89
|
|
90
|
@XmlElement(name = "GatheringEvent")
|
91
|
@XmlIDREF
|
92
|
@XmlSchemaType(name = "IDREF")
|
93
|
@ManyToOne(fetch = FetchType.LAZY)
|
94
|
@Cascade( { CascadeType.SAVE_UPDATE,CascadeType.MERGE })
|
95
|
@IndexedEmbedded(depth = 2)
|
96
|
@Valid
|
97
|
private GatheringEvent gatheringEvent;
|
98
|
|
99
|
// *************** FACTORY METHOD *************************/
|
100
|
|
101
|
/**
|
102
|
* Factory method.
|
103
|
*/
|
104
|
public static FieldUnit NewInstance(){
|
105
|
return new FieldUnit();
|
106
|
}
|
107
|
|
108
|
//****************************** CONSTRUCTOR **************************************/
|
109
|
|
110
|
//*packet* private required by bytebuddy
|
111
|
FieldUnit(){
|
112
|
super(SpecimenOrObservationType.FieldUnit);
|
113
|
initDefaultCacheStrategy();
|
114
|
}
|
115
|
|
116
|
//****************************** CACHE STRATEGY **************************************/
|
117
|
|
118
|
/**
|
119
|
* Sets the default cache strategy
|
120
|
*/
|
121
|
@Override
|
122
|
protected void initDefaultCacheStrategy() {
|
123
|
this.cacheStrategy = FieldUnitDefaultCacheStrategy.NewInstance();
|
124
|
}
|
125
|
|
126
|
// ************************ GETTER / SETTER *******************************************
|
127
|
|
128
|
@Override
|
129
|
public String getTitleCache() {
|
130
|
//most changes in fieldUnits take place in gathering events, therefore we compute titleCache each time from scratch
|
131
|
if (!this.protectedTitleCache){
|
132
|
this.titleCache = null;
|
133
|
}
|
134
|
return super.getTitleCache();
|
135
|
}
|
136
|
|
137
|
public GatheringEvent getGatheringEvent() {
|
138
|
return gatheringEvent;
|
139
|
}
|
140
|
|
141
|
public void setGatheringEvent(GatheringEvent gatheringEvent) {
|
142
|
this.gatheringEvent = gatheringEvent;
|
143
|
addGatheringEventPropertyChangeListener();
|
144
|
}
|
145
|
|
146
|
|
147
|
private void addGatheringEventPropertyChangeListener() {
|
148
|
if (gatheringEvent != null){
|
149
|
gatheringEvent.addPropertyChangeListener(getNewGatheringEventPropChangeListener());
|
150
|
}
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* The collectors field number. If the collector is a team the field number
|
155
|
* is taken from the field book of the primary collector.
|
156
|
* @see #primaryCollector
|
157
|
* @return
|
158
|
*/
|
159
|
public String getFieldNumber() {
|
160
|
return fieldNumber;
|
161
|
}
|
162
|
|
163
|
public void setFieldNumber(String fieldNumber) {
|
164
|
this.fieldNumber = isBlank(fieldNumber)? null : fieldNumber;
|
165
|
}
|
166
|
|
167
|
|
168
|
/**
|
169
|
* The primary collector is the person who the field books belongs to.
|
170
|
* So the field number is also taken from him (his field book).
|
171
|
* @see #fieldNumber
|
172
|
* @param primaryCollector
|
173
|
*/
|
174
|
public void setPrimaryCollector(Person primaryCollector) {
|
175
|
this.primaryCollector = primaryCollector;
|
176
|
}
|
177
|
|
178
|
public Person getPrimaryCollector() {
|
179
|
return primaryCollector;
|
180
|
}
|
181
|
|
182
|
public String getFieldNotes() {
|
183
|
return fieldNotes;
|
184
|
}
|
185
|
|
186
|
public void setFieldNotes(String fieldNotes) {
|
187
|
this.fieldNotes = isBlank(fieldNotes)? null : fieldNotes;
|
188
|
}
|
189
|
|
190
|
// *********** Listener *****************************/
|
191
|
|
192
|
private PropertyChangeListener getNewGatheringEventPropChangeListener() {
|
193
|
PropertyChangeListener listener = new PropertyChangeListener(){
|
194
|
|
195
|
@Override
|
196
|
public void propertyChange(PropertyChangeEvent event) {
|
197
|
firePropertyChange(event);
|
198
|
}
|
199
|
|
200
|
};
|
201
|
return listener;
|
202
|
}
|
203
|
|
204
|
//*********** CLONE **********************************/
|
205
|
|
206
|
/**
|
207
|
* Clones <i>this</i> field unit. This is a shortcut that enables to
|
208
|
* create a new instance that differs only slightly from <i>this</i> field unit
|
209
|
* by modifying only some of the attributes.<BR>
|
210
|
* This method overrides the clone method from {@link SpecimenOrObservationBase SpecimenOrObservationBase}.
|
211
|
*
|
212
|
* @see SpecimenOrObservationBase#clone()
|
213
|
* @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
|
214
|
* @see java.lang.Object#clone()
|
215
|
*/
|
216
|
@Override
|
217
|
public FieldUnit clone(){
|
218
|
try{
|
219
|
FieldUnit result = (FieldUnit)super.clone();
|
220
|
//no changes to: fieldNotes, fieldNumber
|
221
|
return result;
|
222
|
} catch (CloneNotSupportedException e) {
|
223
|
logger.warn("Object does not implement cloneable");
|
224
|
e.printStackTrace();
|
225
|
return null;
|
226
|
}
|
227
|
|
228
|
}
|
229
|
|
230
|
}
|