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

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