2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.occurrence
;
12 import java
.util
.Calendar
;
13 import java
.util
.HashSet
;
16 import javax
.persistence
.Entity
;
17 import javax
.persistence
.FetchType
;
18 import javax
.persistence
.ManyToMany
;
19 import javax
.persistence
.ManyToOne
;
20 import javax
.persistence
.Transient
;
21 import javax
.xml
.bind
.annotation
.XmlAccessType
;
22 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
23 import javax
.xml
.bind
.annotation
.XmlElement
;
24 import javax
.xml
.bind
.annotation
.XmlElementWrapper
;
25 import javax
.xml
.bind
.annotation
.XmlIDREF
;
26 import javax
.xml
.bind
.annotation
.XmlRootElement
;
27 import javax
.xml
.bind
.annotation
.XmlSchemaType
;
28 import javax
.xml
.bind
.annotation
.XmlType
;
30 import org
.apache
.log4j
.Logger
;
31 import org
.hibernate
.annotations
.Cascade
;
32 import org
.hibernate
.annotations
.CascadeType
;
33 import org
.joda
.time
.Partial
;
35 import eu
.etaxonomy
.cdm
.model
.agent
.Agent
;
36 import eu
.etaxonomy
.cdm
.model
.common
.EventBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
38 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
39 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
40 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
43 * The event when gathering a specimen or recording a field observation only
47 @XmlAccessorType(XmlAccessType
.FIELD
)
48 @XmlType(name
= "GatheringEvent", propOrder
= {
54 "absoluteElevationError",
56 "distanceToWaterSurface"
58 @XmlRootElement(name
= "GatheringEvent")
61 public class GatheringEvent
extends EventBase
implements Cloneable
{
63 static Logger logger
= Logger
.getLogger(GatheringEvent
.class);
65 //Locality name (as free text) where this occurrence happened
66 @XmlElement(name
= "Locality")
67 private LanguageString locality
;
69 @XmlElement(name
= "ExactLocation")
70 private Point exactLocation
;
72 @XmlElementWrapper(name
= "CollectingAreas")
73 @XmlElement(name
= "CollectingArea")
75 @XmlSchemaType(name
= "IDREF")
76 private Set
<NamedArea
> collectingAreas
= getNewNamedAreaSet();
78 @XmlElement(name
= "CollectingMethod")
79 private String collectingMethod
;
81 // meter above/below sea level of the surface
82 @XmlElement(name
= "AbsoluteElevation")
83 private Integer absoluteElevation
;
85 @XmlElement(name
= "AbsoluteElevationError")
86 private Integer absoluteElevationError
;
88 // distance in meter from the ground surface when collecting. E.g. 10m below the ground or 10m above the ground/bottom of a lake or 20m up in the canope
89 @XmlElement(name
= "DistanceToGround")
90 private Integer distanceToGround
;
92 // distance in meters to lake or sea surface. Similar to distanceToGround use negative integers for distance *below* the surface, ie under water
93 @XmlElement(name
= "DistanceToWaterSurface")
94 private Integer distanceToWaterSurface
;
101 public static GatheringEvent
NewInstance(){
102 return new GatheringEvent();
108 protected GatheringEvent() {
112 public Point
getExactLocation(){
113 return this.exactLocation
;
115 public void setExactLocation(Point exactLocation
){
116 this.exactLocation
= exactLocation
;
119 @ManyToMany(fetch
= FetchType
.LAZY
)
120 public Set
<NamedArea
> getCollectingAreas(){
121 return this.collectingAreas
;
123 public void setCollectingAreas(Set
<NamedArea
> area
){
125 getNewNamedAreaSet();
127 this.collectingAreas
= area
;
129 public void addCollectingArea(NamedArea area
){
130 if (this.collectingAreas
== null)
131 this.collectingAreas
= getNewNamedAreaSet();
132 this.collectingAreas
.add(area
);
134 public void removeCollectingArea(NamedArea area
){
135 //TODO to be implemented?
136 logger
.warn("not yet fully implemented?");
137 this.collectingAreas
.remove(area
);
140 @ManyToOne(fetch
= FetchType
.LAZY
)
141 @Cascade({CascadeType
.SAVE_UPDATE
})
142 public LanguageString
getLocality(){
143 return this.locality
;
145 public void setLocality(LanguageString locality
){
146 this.locality
= locality
;
150 * EventBase managed attributes
154 public Partial
getGatheringDate(){
155 return this.getTimeperiod().getStart();
157 public void setGatheringDate(Partial gatheringDate
){
158 this.setTimeperiod(TimePeriod
.NewInstance(gatheringDate
));
161 public void setGatheringDate(Calendar gatheringDate
){
162 this.setTimeperiod(TimePeriod
.NewInstance(gatheringDate
));
166 public Agent
getCollector(){
167 return this.getActor();
169 public void setCollector(Agent collector
){
170 this.setActor(collector
);
174 public String
getCollectingMethod() {
175 return collectingMethod
;
177 public void setCollectingMethod(String collectingMethod
) {
178 this.collectingMethod
= collectingMethod
;
182 public Integer
getAbsoluteElevation() {
183 return absoluteElevation
;
186 public void setAbsoluteElevation(Integer absoluteElevation
) {
187 this.absoluteElevation
= absoluteElevation
;
191 public Integer
getAbsoluteElevationError() {
192 return absoluteElevationError
;
194 public void setAbsoluteElevationError(Integer absoluteElevationError
) {
195 this.absoluteElevationError
= absoluteElevationError
;
197 public Integer
getDistanceToGround() {
198 return distanceToGround
;
200 public void setDistanceToGround(Integer distanceToGround
) {
201 this.distanceToGround
= distanceToGround
;
203 public Integer
getDistanceToWaterSurface() {
204 return distanceToWaterSurface
;
206 public void setDistanceToWaterSurface(Integer distanceToWaterSurface
) {
207 this.distanceToWaterSurface
= distanceToWaterSurface
;
211 //*********** CLONE **********************************/
214 * Clones <i>this</i> gathering event. This is a shortcut that enables to
215 * create a new instance that differs only slightly from <i>this</i> gathering event
216 * by modifying only some of the attributes.<BR>
217 * This method overrides the clone method from {@link DerivedUnitBase DerivedUnitBase}.
219 * @see DerivedUnitBase#clone()
220 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
221 * @see java.lang.Object#clone()
224 public GatheringEvent
clone(){
226 GatheringEvent result
= (GatheringEvent
)super.clone();
228 LanguageString langString
= LanguageString
.NewInstance(this.locality
.getText(), this.locality
.getLanguage());
229 result
.setLocality(langString
);
231 result
.setExactLocation(this.exactLocation
.clone());
233 Set
<NamedArea
> namedAreas
= getNewNamedAreaSet();
234 namedAreas
.addAll(this.collectingAreas
);
235 result
.setCollectingAreas(namedAreas
);
237 //no changes to: distanceToWaterSurface, distanceToGround, collectingMethod, absoluteElevationError, absoluteElevation
239 } catch (CloneNotSupportedException e
) {
240 logger
.warn("Object does not implement cloneable");
246 private static Set
<NamedArea
> getNewNamedAreaSet(){
247 return new HashSet
<NamedArea
>();