Project

General

Profile

Download (6.15 KB) Statistics
| Branch: | Tag: | Revision:
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.name.TaxonNameBase;
43
import eu.etaxonomy.cdm.model.reference.Reference;
44
import eu.etaxonomy.cdm.model.taxon.Taxon;
45
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
46

    
47
/**
48
 * @author m.doering
49
 * @version 1.0
50
 * @created 08-Nov-2007 13:06:21
51
 */
52
@XmlAccessorType(XmlAccessType.FIELD)
53
@XmlType(name = "DeterminationEvent", propOrder = {
54
    "identifiedUnit",
55
    "taxon",
56
    "taxonName",
57
    "modifier",
58
    "preferredFlag",
59
    "setOfReferences"
60
})
61
@XmlRootElement(name = "DeterminationEvent")
62
@Entity
63
@Indexed
64
@Audited
65
public class DeterminationEvent extends EventBase {
66
	private static final long serialVersionUID = 5065341354427569773L;
67

    
68
	private static final Logger logger = Logger.getLogger(DeterminationEvent.class);
69

    
70
	@XmlElement(name = "IdentifiedUnit")
71
	@XmlIDREF
72
	@XmlSchemaType(name = "IDREF")
73
	@ManyToOne(fetch = FetchType.LAZY)
74
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
75
	private SpecimenOrObservationBase<?> identifiedUnit;
76

    
77
	@XmlElement(name = "Taxon")
78
	@XmlIDREF
79
	@XmlSchemaType(name = "IDREF")
80
	@ManyToOne(fetch = FetchType.LAZY)
81
	@IndexedEmbedded
82
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
83
    private TaxonBase<?> taxon;
84
	
85
//	#4518
86
	@XmlElement(name = "TaxonName")
87
	@XmlIDREF
88
	@XmlSchemaType(name = "IDREF")
89
	@ManyToOne(fetch = FetchType.LAZY)
90
	@IndexedEmbedded
91
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
92
    private TaxonNameBase<?,?> taxonName;
93

    
94
	@XmlElement(name = "Modifier")
95
	@XmlIDREF
96
	@XmlSchemaType(name = "IDREF")
97
	@ManyToOne(fetch = FetchType.LAZY)
98
	private DefinedTerm modifier;
99

    
100
	@XmlElement(name = "PreferredFlag")
101
	private boolean preferredFlag;
102

    
103
	@XmlElementWrapper(name = "SetOfReferences")
104
	@XmlElement(name = "Reference")
105
	@XmlIDREF
106
	@XmlSchemaType(name = "IDREF")
107
	@ManyToMany(fetch = FetchType.LAZY)
108
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
109
	private Set<Reference> setOfReferences = new HashSet<Reference>();
110

    
111

    
112

    
113
	/**
114
	 * Factory method
115
	 * @return
116
	 */
117
	public static DeterminationEvent NewInstance(){
118
		return new DeterminationEvent();
119
	}
120

    
121
	/**
122
	 * Factory method
123
	 * @return
124
	 */
125
	public static DeterminationEvent NewInstance(Taxon taxon, SpecimenOrObservationBase identifiedUnit ){
126
		DeterminationEvent result = new DeterminationEvent();
127
		result.setTaxon(taxon);
128
		result.setIdentifiedUnit(identifiedUnit);
129
		identifiedUnit.addDetermination(result);
130
		return result;
131
	}
132

    
133
	/**
134
	 * Constructor
135
	 */
136
	protected DeterminationEvent() {
137
		super();
138
	}
139

    
140
	public DefinedTerm getModifier() {
141
		return modifier;
142
	}
143

    
144
	public void setModifier(DefinedTerm modifier) {
145
		this.modifier = modifier;
146
	}
147

    
148
	public TaxonBase getTaxon(){
149
		return this.taxon;
150
	}
151

    
152
	/*** @param taxon    the */
153
	public void setTaxonName(TaxonNameBase taxonName){
154
		this.taxonName = taxonName;
155
	}
156
	
157
	public TaxonNameBase getTaxonName(){
158
		return this.taxonName;
159
	}
160

    
161
	/*** @param taxon    the */
162
	public void setTaxon(TaxonBase taxon){
163
		this.taxon = taxon;
164
	}
165

    
166
	@Transient
167
	public Partial getIdentificationDate(){
168
		return this.getTimeperiod().getStart();
169
	}
170

    
171
	/**
172
	 *
173
	 * @param identificationDate    identificationDate
174
	 */
175
	public void setIdentificationDate(Partial identificationDate){
176
		this.getTimeperiod().setStart(identificationDate);
177
	}
178

    
179
	@Transient
180
	public AgentBase getDeterminer() {
181
		return this.getActor();
182
	}
183

    
184
	public void setDeterminer(AgentBase determiner) {
185
		this.setActor(determiner);
186
	}
187

    
188
	public SpecimenOrObservationBase getIdentifiedUnit() {
189
		return identifiedUnit;
190
	}
191

    
192
	public void setIdentifiedUnit(SpecimenOrObservationBase identifiedUnit) {
193
		this.identifiedUnit = identifiedUnit;
194
	}
195

    
196
	public boolean getPreferredFlag() {
197
		return preferredFlag;
198
	}
199

    
200
	public void setPreferredFlag(boolean preferredFlag) {
201
		this.preferredFlag = preferredFlag;
202
	}
203

    
204
	public Set<Reference> getReferences() {
205
		return setOfReferences;
206
	}
207

    
208
	public void setReferences(Set<Reference> references) {
209
		this.setOfReferences = references;
210
	}
211

    
212
	public void addReference(Reference reference) {
213
		this.setOfReferences.add(reference);
214
	}
215

    
216
//*********** CLONE **********************************/
217

    
218
	/**
219
	 * Clones <i>this</i> determination event. This is a shortcut that enables to
220
	 * create a new instance that differs only slightly from <i>this</i> determination event
221
	 * by modifying only some of the attributes.<BR>
222
	 * This method overrides the clone method from {@link EventBase EventBase}.
223
	 *
224
	 * @see EventBase#clone()
225
	 * @see java.lang.Object#clone()
226
	 */
227
	@Override
228
	public DeterminationEvent clone(){
229
		try{
230
			DeterminationEvent result = (DeterminationEvent)super.clone();
231
			//type
232
			result.setIdentifiedUnit(this.getIdentifiedUnit());
233
			//modifier
234
			result.setModifier(this.getModifier());
235
			//taxon
236
			result.setTaxon(this.getTaxon()); //TODO
237
			//no changes to: preferredFlag
238
			return result;
239
		} catch (CloneNotSupportedException e) {
240
			logger.warn("Object does not implement cloneable");
241
			e.printStackTrace();
242
			return null;
243
		}
244
	}
245

    
246

    
247

    
248
}
(5-5/14)