add serial version number
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / occurrence / DeterminationEvent.java
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.occurrence;
11
12
13
14 import java.util.HashSet;
15 import java.util.Set;
16
17 import javax.persistence.Entity;
18 import javax.persistence.FetchType;
19 import javax.persistence.ManyToMany;
20 import javax.persistence.ManyToOne;
21 import javax.persistence.Transient;
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlElementWrapper;
26 import javax.xml.bind.annotation.XmlIDREF;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import javax.xml.bind.annotation.XmlSchemaType;
29 import javax.xml.bind.annotation.XmlType;
30
31 import org.apache.log4j.Logger;
32 import org.hibernate.annotations.Cascade;
33 import org.hibernate.annotations.CascadeType;
34 import org.hibernate.envers.Audited;
35 import org.hibernate.search.annotations.Indexed;
36 import org.hibernate.search.annotations.IndexedEmbedded;
37 import org.joda.time.Partial;
38
39 import eu.etaxonomy.cdm.model.agent.AgentBase;
40 import eu.etaxonomy.cdm.model.common.DefinedTerm;
41 import eu.etaxonomy.cdm.model.common.EventBase;
42 import eu.etaxonomy.cdm.model.reference.Reference;
43 import eu.etaxonomy.cdm.model.taxon.Taxon;
44 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
45
46 /**
47 * @author m.doering
48 * @version 1.0
49 * @created 08-Nov-2007 13:06:21
50 */
51 @XmlAccessorType(XmlAccessType.FIELD)
52 @XmlType(name = "DeterminationEvent", propOrder = {
53 "identifiedUnit",
54 "taxon",
55 "modifier",
56 "preferredFlag",
57 "setOfReferences"
58 })
59 @XmlRootElement(name = "DeterminationEvent")
60 @Entity
61 @Indexed
62 @Audited
63 public class DeterminationEvent extends EventBase {
64 private static final long serialVersionUID = 5065341354427569773L;
65
66 private static final Logger logger = Logger.getLogger(DeterminationEvent.class);
67
68 @XmlElement(name = "IdentifiedUnit")
69 @XmlIDREF
70 @XmlSchemaType(name = "IDREF")
71 @ManyToOne(fetch = FetchType.LAZY)
72 @Cascade(CascadeType.SAVE_UPDATE)
73 private SpecimenOrObservationBase identifiedUnit;
74
75 @XmlElement(name = "Taxon")
76 @XmlIDREF
77 @XmlSchemaType(name = "IDREF")
78 @ManyToOne(fetch = FetchType.LAZY)
79 @IndexedEmbedded
80 @Cascade(CascadeType.SAVE_UPDATE)
81 private TaxonBase taxon;
82
83 @XmlElement(name = "Modifier")
84 @XmlIDREF
85 @XmlSchemaType(name = "IDREF")
86 @ManyToOne(fetch = FetchType.LAZY)
87 private DefinedTerm modifier;
88
89 @XmlElement(name = "PreferredFlag")
90 private boolean preferredFlag;
91
92 @XmlElementWrapper(name = "SetOfReferences")
93 @XmlElement(name = "Reference")
94 @XmlIDREF
95 @XmlSchemaType(name = "IDREF")
96 @ManyToMany(fetch = FetchType.LAZY)
97 @Cascade(CascadeType.SAVE_UPDATE)
98 private Set<Reference> setOfReferences = new HashSet<Reference>();
99
100
101
102 /**
103 * Factory method
104 * @return
105 */
106 public static DeterminationEvent NewInstance(){
107 return new DeterminationEvent();
108 }
109
110 /**
111 * Factory method
112 * @return
113 */
114 public static DeterminationEvent NewInstance(Taxon taxon, SpecimenOrObservationBase identifiedUnit ){
115 DeterminationEvent result = new DeterminationEvent();
116 result.setTaxon(taxon);
117 result.setIdentifiedUnit(identifiedUnit);
118 identifiedUnit.addDetermination(result);
119 return result;
120 }
121
122 /**
123 * Constructor
124 */
125 protected DeterminationEvent() {
126 super();
127 }
128
129 public DefinedTerm getModifier() {
130 return modifier;
131 }
132
133 public void setModifier(DefinedTerm modifier) {
134 this.modifier = modifier;
135 }
136
137 public TaxonBase getTaxon(){
138 return this.taxon;
139 }
140
141 /**
142 *
143 * @param taxon taxon
144 */
145 public void setTaxon(TaxonBase taxon){
146 this.taxon = taxon;
147 }
148
149 @Transient
150 public Partial getIdentificationDate(){
151 return this.getTimeperiod().getStart();
152 }
153
154 /**
155 *
156 * @param identificationDate identificationDate
157 */
158 public void setIdentificationDate(Partial identificationDate){
159 this.getTimeperiod().setStart(identificationDate);
160 }
161
162 @Transient
163 public AgentBase getDeterminer() {
164 return this.getActor();
165 }
166
167 public void setDeterminer(AgentBase determiner) {
168 this.setActor(determiner);
169 }
170
171 public SpecimenOrObservationBase getIdentifiedUnit() {
172 return identifiedUnit;
173 }
174
175 public void setIdentifiedUnit(SpecimenOrObservationBase identifiedUnit) {
176 this.identifiedUnit = identifiedUnit;
177 }
178
179 public boolean getPreferredFlag() {
180 return preferredFlag;
181 }
182
183 public void setPreferredFlag(boolean preferredFlag) {
184 this.preferredFlag = preferredFlag;
185 }
186
187 public Set<Reference> getReferences() {
188 return setOfReferences;
189 }
190
191 public void setReferences(Set<Reference> references) {
192 this.setOfReferences = references;
193 }
194
195 public void addReference(Reference reference) {
196 this.setOfReferences.add(reference);
197 }
198
199 //*********** CLONE **********************************/
200
201 /**
202 * Clones <i>this</i> determination event. This is a shortcut that enables to
203 * create a new instance that differs only slightly from <i>this</i> determination event
204 * by modifying only some of the attributes.<BR>
205 * This method overrides the clone method from {@link EventBase EventBase}.
206 *
207 * @see EventBase#clone()
208 * @see java.lang.Object#clone()
209 */
210 @Override
211 public DeterminationEvent clone(){
212 try{
213 DeterminationEvent result = (DeterminationEvent)super.clone();
214 //type
215 result.setIdentifiedUnit(this.getIdentifiedUnit());
216 //modifier
217 result.setModifier(this.getModifier());
218 //taxon
219 result.setTaxon(this.getTaxon()); //TODO
220 //no changes to: preferredFlag
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
231 }