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.location;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import javax.persistence.Entity;
|
20
|
import javax.persistence.FetchType;
|
21
|
import javax.persistence.JoinTable;
|
22
|
import javax.persistence.ManyToMany;
|
23
|
import javax.persistence.ManyToOne;
|
24
|
import javax.persistence.Transient;
|
25
|
import javax.xml.bind.annotation.XmlAccessType;
|
26
|
import javax.xml.bind.annotation.XmlAccessorType;
|
27
|
import javax.xml.bind.annotation.XmlElement;
|
28
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
29
|
import javax.xml.bind.annotation.XmlIDREF;
|
30
|
import javax.xml.bind.annotation.XmlRootElement;
|
31
|
import javax.xml.bind.annotation.XmlSchemaType;
|
32
|
import javax.xml.bind.annotation.XmlSeeAlso;
|
33
|
import javax.xml.bind.annotation.XmlType;
|
34
|
|
35
|
import org.apache.log4j.Logger;
|
36
|
import org.hibernate.annotations.Cascade;
|
37
|
import org.hibernate.annotations.CascadeType;
|
38
|
import org.hibernate.envers.Audited;
|
39
|
|
40
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
41
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
42
|
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
|
43
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
44
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
45
|
import eu.etaxonomy.cdm.model.media.Media;
|
46
|
|
47
|
/**
|
48
|
* @author m.doering
|
49
|
* @version 1.0
|
50
|
* @created 08-Nov-2007 13:06:36
|
51
|
*/
|
52
|
@XmlAccessorType(XmlAccessType.PROPERTY)
|
53
|
@XmlType(name = "NamedArea", propOrder = {
|
54
|
"kindOf",
|
55
|
"generalizationOf",
|
56
|
"partOf",
|
57
|
"includes",
|
58
|
"validPeriod",
|
59
|
"shape",
|
60
|
"pointApproximation",
|
61
|
"waterbodiesOrCountries",
|
62
|
"type",
|
63
|
"level"
|
64
|
})
|
65
|
@XmlRootElement(name = "NamedArea")
|
66
|
@XmlSeeAlso({
|
67
|
TdwgArea.class,
|
68
|
Continent.class,
|
69
|
WaterbodyOrCountry.class
|
70
|
})
|
71
|
@Entity
|
72
|
@Audited
|
73
|
public class NamedArea extends OrderedTermBase<NamedArea> {
|
74
|
private static final long serialVersionUID = 6248434369557403036L;
|
75
|
private static final Logger logger = Logger.getLogger(NamedArea.class);
|
76
|
|
77
|
protected static Map<UUID, NamedArea> termMap = null;
|
78
|
|
79
|
//description of time valid context of this area. e.g. year range
|
80
|
private TimePeriod validPeriod = TimePeriod.NewInstance();
|
81
|
|
82
|
//Binary shape definition for user's defined area as polygon
|
83
|
@ManyToOne(fetch = FetchType.LAZY)
|
84
|
@Cascade(CascadeType.SAVE_UPDATE)
|
85
|
private Media shape;
|
86
|
|
87
|
private Point pointApproximation;
|
88
|
|
89
|
@ManyToMany(fetch = FetchType.LAZY)
|
90
|
@JoinTable(name="DefinedTermBase_WaterbodyOrCountry")
|
91
|
private Set<WaterbodyOrCountry> waterbodiesOrCountries = new HashSet<WaterbodyOrCountry>();
|
92
|
|
93
|
@ManyToOne(fetch = FetchType.LAZY)
|
94
|
private NamedAreaType type;
|
95
|
|
96
|
@ManyToOne(fetch = FetchType.LAZY)
|
97
|
private NamedAreaLevel level;
|
98
|
|
99
|
/**
|
100
|
* Factory method
|
101
|
* @return
|
102
|
*/
|
103
|
public static NamedArea NewInstance(){
|
104
|
logger.debug("NewInstance");
|
105
|
return new NamedArea();
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* Factory method
|
110
|
* @return
|
111
|
*/
|
112
|
public static NamedArea NewInstance(String term, String label, String labelAbbrev){
|
113
|
return new NamedArea(term, label, labelAbbrev);
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Constructor
|
118
|
*/
|
119
|
public NamedArea() {
|
120
|
}
|
121
|
|
122
|
public NamedArea(String term, String label, String labelAbbrev) {
|
123
|
super(term, label, labelAbbrev);
|
124
|
}
|
125
|
|
126
|
@XmlElement(name = "NamedAreaType")
|
127
|
@XmlIDREF
|
128
|
@XmlSchemaType(name = "IDREF")
|
129
|
public NamedAreaType getType(){
|
130
|
return this.type;
|
131
|
}
|
132
|
|
133
|
public void setType(NamedAreaType type){
|
134
|
this.type = type;
|
135
|
}
|
136
|
|
137
|
@XmlElement(name = "NamedAreaLevel")
|
138
|
@XmlIDREF
|
139
|
@XmlSchemaType(name = "IDREF")
|
140
|
public NamedAreaLevel getLevel(){
|
141
|
return this.level;
|
142
|
}
|
143
|
|
144
|
public void setLevel(NamedAreaLevel level){
|
145
|
this.level = level;
|
146
|
}
|
147
|
|
148
|
@XmlElement(name = "ValidPeriod")
|
149
|
public TimePeriod getValidPeriod(){
|
150
|
return this.validPeriod;
|
151
|
}
|
152
|
|
153
|
public void setValidPeriod(TimePeriod validPeriod){
|
154
|
this.validPeriod = validPeriod;
|
155
|
}
|
156
|
|
157
|
@XmlElement(name = "Shape")
|
158
|
@XmlIDREF
|
159
|
@XmlSchemaType(name = "IDREF")
|
160
|
public Media getShape(){
|
161
|
return this.shape;
|
162
|
}
|
163
|
public void setShape(Media shape){
|
164
|
this.shape = shape;
|
165
|
}
|
166
|
|
167
|
@XmlElementWrapper(name = "WaterbodiesOrCountries")
|
168
|
@XmlElement(name = "WaterbodiesOrCountry")
|
169
|
@XmlIDREF
|
170
|
@XmlSchemaType(name = "IDREF")
|
171
|
public Set<WaterbodyOrCountry> getWaterbodiesOrCountries() {
|
172
|
return waterbodiesOrCountries;
|
173
|
}
|
174
|
|
175
|
public void addWaterbodyOrCountry(WaterbodyOrCountry waterbodyOrCountry) {
|
176
|
this.waterbodiesOrCountries.add(waterbodyOrCountry);
|
177
|
}
|
178
|
|
179
|
public void removeWaterbodyOrCountry(WaterbodyOrCountry waterbodyOrCountry) {
|
180
|
this.waterbodiesOrCountries.remove(waterbodyOrCountry);
|
181
|
}
|
182
|
|
183
|
@XmlElement(name = "PointApproximation")
|
184
|
public Point getPointApproximation() {
|
185
|
return pointApproximation;
|
186
|
}
|
187
|
public void setPointApproximation(Point pointApproximation) {
|
188
|
this.pointApproximation = pointApproximation;
|
189
|
}
|
190
|
|
191
|
@XmlElement(name = "KindOf", namespace = "http://etaxonomy.eu/cdm/model/common/1.0")
|
192
|
@XmlIDREF
|
193
|
@XmlSchemaType(name = "IDREF")
|
194
|
public NamedArea getKindOf(){
|
195
|
return super.getKindOf();
|
196
|
}
|
197
|
|
198
|
public void setKindOf(NamedArea kindOf){
|
199
|
super.setKindOf(kindOf);
|
200
|
}
|
201
|
|
202
|
@XmlElement(name = "PartOf", namespace = "http://etaxonomy.eu/cdm/model/common/1.0")
|
203
|
@XmlIDREF
|
204
|
@XmlSchemaType(name = "IDREF")
|
205
|
public NamedArea getPartOf(){
|
206
|
return partOf;
|
207
|
}
|
208
|
|
209
|
/**
|
210
|
* FIXME this method is a workaround for a casting problem in the getPartOf implementation
|
211
|
*
|
212
|
* the partOf instance variable is typically a proxy object of type DefinedTermBase, thus
|
213
|
* does not coincide with the return value of NamedArea and a ClassCastException is thrown.
|
214
|
*
|
215
|
* It is not clear why this only occurs in the editor and not in the webservice where the same
|
216
|
* method gets called and should lead to the same results.
|
217
|
*
|
218
|
* Seems to be a bigger problem although its origin is buggy behaviour of the javassist implementation.
|
219
|
*/
|
220
|
@Deprecated
|
221
|
@Transient
|
222
|
public NamedArea getPartOfWorkaround(){
|
223
|
Object area = super.getPartOf();
|
224
|
|
225
|
if(!(area instanceof NamedArea)){
|
226
|
area = HibernateProxyHelper.deproxy(area, NamedArea.class);
|
227
|
}
|
228
|
|
229
|
return (NamedArea) area;
|
230
|
}
|
231
|
|
232
|
public void setPartOf(NamedArea partOf){
|
233
|
this.partOf = partOf;
|
234
|
}
|
235
|
|
236
|
@XmlElementWrapper(name = "Generalizations", namespace = "http://etaxonomy.eu/cdm/model/common/1.0")
|
237
|
@XmlElement(name = "GeneralizationOf", namespace = "http://etaxonomy.eu/cdm/model/common/1.0")
|
238
|
@XmlIDREF
|
239
|
@XmlSchemaType(name = "IDREF")
|
240
|
public Set<NamedArea> getGeneralizationOf(){
|
241
|
return super.getGeneralizationOf();
|
242
|
}
|
243
|
|
244
|
protected void setGeneralizationOf(Set<NamedArea> value){
|
245
|
super.setGeneralizationOf(value);
|
246
|
}
|
247
|
|
248
|
@XmlElementWrapper(name = "Includes", namespace = "http://etaxonomy.eu/cdm/model/common/1.0")
|
249
|
@XmlElement(name = "Include", namespace = "http://etaxonomy.eu/cdm/model/common/1.0")
|
250
|
@XmlIDREF
|
251
|
@XmlSchemaType(name = "IDREF")
|
252
|
public Set<NamedArea> getIncludes(){
|
253
|
return super.getIncludes();
|
254
|
}
|
255
|
|
256
|
protected void setIncludes(Set<NamedArea> includes) {
|
257
|
super.setIncludes(includes);
|
258
|
}
|
259
|
|
260
|
|
261
|
/* (non-Javadoc)
|
262
|
* @see eu.etaxonomy.cdm.model.common.DefinedTermBase#readCsvLine(java.util.List)
|
263
|
*/
|
264
|
@Override
|
265
|
public NamedArea readCsvLine(Class<NamedArea> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms) {
|
266
|
NamedArea newInstance = super.readCsvLine(termClass, csvLine, terms);
|
267
|
|
268
|
String levelString = (String)csvLine.get(6);
|
269
|
|
270
|
if(levelString != null && levelString.length() != 0) {
|
271
|
UUID levelUuid = UUID.fromString(levelString);
|
272
|
NamedAreaLevel level = (NamedAreaLevel)terms.get(levelUuid);
|
273
|
newInstance.setLevel(level);
|
274
|
}
|
275
|
|
276
|
String partOfString = (String)csvLine.get(7);
|
277
|
|
278
|
if(partOfString != null && partOfString.length() != 0) {
|
279
|
UUID partOfUuid = UUID.fromString(partOfString);
|
280
|
NamedArea partOf = (NamedArea)terms.get(partOfUuid);
|
281
|
partOf.addIncludes(newInstance);
|
282
|
}
|
283
|
return newInstance;
|
284
|
}
|
285
|
|
286
|
@Override
|
287
|
protected void setDefaultTerms(TermVocabulary<NamedArea> termVocabulary) {
|
288
|
termMap = new HashMap<UUID, NamedArea>();
|
289
|
for (NamedArea term : termVocabulary.getTerms()){
|
290
|
termMap.put(term.getUuid(), term);
|
291
|
}
|
292
|
}
|
293
|
}
|