root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/occurrence/GatheringEvent.java

Revision 10919, 8.4 kB (checked in by a.mueller, 18 months ago)

merge 3.0.2 to trunk

  • Property svn:keywords set to Id
Line 
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
10package eu.etaxonomy.cdm.model.occurrence;
11
12import java.util.Calendar;
13import java.util.HashSet;
14import java.util.Set;
15
16import javax.persistence.Entity;
17import javax.persistence.FetchType;
18import javax.persistence.ManyToMany;
19import javax.persistence.ManyToOne;
20import javax.persistence.OneToOne;
21import javax.persistence.Transient;
22import javax.validation.constraints.NotNull;
23import javax.xml.bind.annotation.XmlAccessType;
24import javax.xml.bind.annotation.XmlAccessorType;
25import javax.xml.bind.annotation.XmlElement;
26import javax.xml.bind.annotation.XmlElementWrapper;
27import javax.xml.bind.annotation.XmlIDREF;
28import javax.xml.bind.annotation.XmlRootElement;
29import javax.xml.bind.annotation.XmlSchemaType;
30import javax.xml.bind.annotation.XmlType;
31
32import org.apache.log4j.Logger;
33import org.hibernate.annotations.Cascade;
34import org.hibernate.annotations.CascadeType;
35import org.hibernate.envers.Audited;
36import org.hibernate.search.annotations.Field;
37import org.hibernate.search.annotations.Index;
38import org.hibernate.search.annotations.Indexed;
39import org.hibernate.search.annotations.IndexedEmbedded;
40import org.hibernate.validator.constraints.Length;
41import org.joda.time.Partial;
42
43import eu.etaxonomy.cdm.model.agent.AgentBase;
44import eu.etaxonomy.cdm.model.common.EventBase;
45import eu.etaxonomy.cdm.model.common.LanguageString;
46import eu.etaxonomy.cdm.model.common.TimePeriod;
47import eu.etaxonomy.cdm.model.location.NamedArea;
48import eu.etaxonomy.cdm.model.location.Point;
49import eu.etaxonomy.cdm.model.reference.Reference;
50import eu.etaxonomy.cdm.strategy.cache.name.CacheUpdate;
51import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
52
53/**
54 * The event when gathering a specimen or recording a field observation only
55 * @author m.doering
56 *
57 */
58@XmlAccessorType(XmlAccessType.FIELD)
59@XmlType(name = "GatheringEvent", propOrder = {
60    "locality",
61    "exactLocation",
62    "country",
63    "collectingAreas",
64    "collectingMethod",
65    "absoluteElevation",
66    "absoluteElevationError",
67    "distanceToGround",
68    "distanceToWaterSurface"
69})
70@XmlRootElement(name = "GatheringEvent")
71@Entity
72@Audited
73@Indexed
74public class GatheringEvent extends EventBase implements Cloneable{
75        private static final long serialVersionUID = 7980806082366532180L;
76        private static final Logger logger = Logger.getLogger(GatheringEvent.class);
77
78        @XmlElement(name = "Locality")
79        @OneToOne(fetch = FetchType.LAZY)
80        @Cascade({CascadeType.ALL,CascadeType.DELETE_ORPHAN})
81        @IndexedEmbedded
82        private LanguageString locality;
83       
84        @XmlElement(name = "ExactLocation")
85        private Point exactLocation;
86       
87       
88        @XmlElement(name = "Country")
89        @XmlIDREF
90        @XmlSchemaType(name = "IDREF")
91        @ManyToOne(fetch = FetchType.LAZY)
92        @Cascade({CascadeType.SAVE_UPDATE})
93        private NamedArea country;
94       
95    @XmlElementWrapper(name = "CollectingAreas")
96        @XmlElement(name = "CollectingArea")
97        @XmlIDREF
98        @XmlSchemaType(name = "IDREF")
99        @ManyToMany(fetch = FetchType.LAZY)
100        @NotNull
101        // further collecting areas. Should not include country
102        private Set<NamedArea> collectingAreas = new HashSet<NamedArea>();
103       
104        @XmlElement(name = "CollectingMethod")
105        @Field(index=Index.TOKENIZED)
106        @NullOrNotEmpty
107        @Length(max = 255)
108        private String collectingMethod;
109       
110        // meter above/below sea level of the surface
111        @XmlElement(name = "AbsoluteElevation")
112        @Field(index=Index.UN_TOKENIZED)
113        private Integer absoluteElevation;
114       
115        @XmlElement(name = "AbsoluteElevationError")
116        @Field(index=Index.UN_TOKENIZED)
117        private Integer absoluteElevationError;
118       
119        // 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
120        @XmlElement(name = "DistanceToGround")
121        @Field(index=Index.UN_TOKENIZED)
122        private Integer distanceToGround;
123       
124        // distance in meters to lake or sea surface. Similar to distanceToGround use negative integers for distance *below* the surface, ie under water
125        @XmlElement(name = "DistanceToWaterSurface")
126        @Field(index=Index.UN_TOKENIZED)
127        private Integer distanceToWaterSurface;
128
129        /**
130         * Factory method
131         * @return
132         */
133        public static GatheringEvent NewInstance(){
134                return new GatheringEvent();
135        }
136       
137        /**
138         * Constructor
139         */
140        protected GatheringEvent() {
141                super();
142        }
143
144        public Point getExactLocation(){
145                return this.exactLocation;
146        }
147        public void setExactLocation(Point exactLocation){
148                this.exactLocation = exactLocation;
149        }
150
151       
152
153        public NamedArea getCountry() {
154                return country;
155        }
156
157        public void setCountry(NamedArea country) {
158                this.country = country;
159        }
160
161        /**
162         * Further collecting areas. Should not include #getCountry()
163         * @return
164         */
165        public Set<NamedArea> getCollectingAreas(){
166                if(collectingAreas == null) {
167                        this.collectingAreas = new HashSet<NamedArea>();
168                }
169                return this.collectingAreas;
170        }
171
172       
173         /**
174          * Further collecting areas. Should not include #getCountry()
175          * @param area
176         */
177        public void addCollectingArea(NamedArea area){
178                if (this.collectingAreas == null)
179                        this.collectingAreas = getNewNamedAreaSet();
180                this.collectingAreas.add(area);
181        }
182       
183        public void removeCollectingArea(NamedArea area){
184                //TODO to be implemented?
185                logger.warn("not yet fully implemented?");
186                this.collectingAreas.remove(area);
187        }
188
189        public LanguageString getLocality(){
190                return this.locality;
191        }
192       
193        public void setLocality(LanguageString locality){
194                this.locality = locality;
195        }
196
197        /**
198         * EventBase managed attributes
199         * @return
200         */
201
202        @Transient
203        public Partial getGatheringDate(){
204                return this.getTimeperiod().getStart();
205        }
206       
207        public void setGatheringDate(Partial gatheringDate){
208                this.setTimeperiod(TimePeriod.NewInstance(gatheringDate));
209        }       
210
211        public void setGatheringDate(Calendar gatheringDate){
212                this.setTimeperiod(TimePeriod.NewInstance(gatheringDate));
213        }
214       
215        @Transient
216        public AgentBase getCollector(){
217                return this.getActor();
218        }
219       
220        public void setCollector(AgentBase collector){
221                this.setActor(collector);
222        }
223
224        public String getCollectingMethod() {
225                return collectingMethod;
226        }
227       
228        public void setCollectingMethod(String collectingMethod) {
229                this.collectingMethod = collectingMethod;
230        }
231
232        public Integer getAbsoluteElevation() {
233                return absoluteElevation;
234        }
235
236        public void setAbsoluteElevation(Integer absoluteElevation) {
237                this.absoluteElevation = absoluteElevation;
238        }
239
240        public Integer getAbsoluteElevationError() {
241                return absoluteElevationError;
242        }
243       
244        public void setAbsoluteElevationError(Integer absoluteElevationError) {
245                this.absoluteElevationError = absoluteElevationError;
246        }
247       
248        public Integer getDistanceToGround() {
249                return distanceToGround;
250        }
251       
252        public void setDistanceToGround(Integer distanceToGround) {
253                this.distanceToGround = distanceToGround;
254        }
255       
256        public Integer getDistanceToWaterSurface() {
257                return distanceToWaterSurface;
258        }
259       
260        public void setDistanceToWaterSurface(Integer distanceToWaterSurface) {
261                this.distanceToWaterSurface = distanceToWaterSurface;
262        }
263       
264//*********** CLONE **********************************/
265       
266        /**
267         * Clones <i>this</i> gathering event. This is a shortcut that enables to
268         * create a new instance that differs only slightly from <i>this</i> gathering event
269         * by modifying only some of the attributes.<BR>
270         * This method overrides the clone method from {@link DerivedUnitBase DerivedUnitBase}.
271         *
272         * @see DerivedUnitBase#clone()
273         * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
274         * @see java.lang.Object#clone()
275         */
276        @Override
277        public GatheringEvent clone(){
278                try{
279                        GatheringEvent result = (GatheringEvent)super.clone();
280                        //locality
281                        LanguageString langString = LanguageString.NewInstance(this.locality.getText(), this.locality.getLanguage());
282                        result.setLocality(langString);
283                        //exact location
284                        result.setExactLocation(this.exactLocation.clone());
285                        //namedAreas
286                        result.collectingAreas = new HashSet<NamedArea>();
287                        for(NamedArea collectingArea : this.collectingAreas) {
288                                result.addCollectingArea(collectingArea);
289                        }
290                       
291                        //no changes to: distanceToWaterSurface, distanceToGround, collectingMethod, absoluteElevationError, absoluteElevation
292                        return result;
293                } catch (CloneNotSupportedException e) {
294                        logger.warn("Object does not implement cloneable");
295                        e.printStackTrace();
296                        return null;
297                }
298        }
299
300        private static Set<NamedArea> getNewNamedAreaSet(){
301                return new HashSet<NamedArea>();
302        }
303}
Note: See TracBrowser for help on using the browser.