Project

General

Profile

Download (8.04 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.molecular;
11

    
12

    
13
import java.util.HashSet;
14
import java.util.Set;
15

    
16
import javax.persistence.Basic;
17
import javax.persistence.Entity;
18
import javax.persistence.FetchType;
19
import javax.persistence.ManyToOne;
20
import javax.persistence.OneToMany;
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.XmlAttribute;
25
import javax.xml.bind.annotation.XmlElement;
26
import javax.xml.bind.annotation.XmlElementWrapper;
27
import javax.xml.bind.annotation.XmlIDREF;
28
import javax.xml.bind.annotation.XmlRootElement;
29
import javax.xml.bind.annotation.XmlSchemaType;
30
import javax.xml.bind.annotation.XmlType;
31
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
32

    
33
import org.apache.log4j.Logger;
34
import org.hibernate.annotations.Cascade;
35
import org.hibernate.annotations.CascadeType;
36
import org.hibernate.annotations.Index;
37
import org.hibernate.annotations.Table;
38
import org.hibernate.annotations.Type;
39
import org.hibernate.envers.Audited;
40
import org.joda.time.DateTime;
41
import org.springframework.beans.factory.annotation.Configurable;
42

    
43
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
44
import eu.etaxonomy.cdm.model.common.IReferencedEntity;
45
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
46
import eu.etaxonomy.cdm.model.media.IMediaDocumented;
47
import eu.etaxonomy.cdm.model.media.Media;
48
import eu.etaxonomy.cdm.model.reference.Reference;
49
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
50
import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
51

    
52
/**
53
 * @author m.doering
54
 * @version 1.0
55
 * @created 08-Nov-2007 13:06:51
56
 */
57
@XmlAccessorType(XmlAccessType.FIELD)
58
@XmlType(name = "Sequence", propOrder = {
59
    "sequence",
60
    "length",
61
    "dateSequenced",
62
    "barcode",
63
    "citationMicroReference",
64
    "publishedIn",
65
    "locus",
66
    "citations",
67
    "genBankAccession",
68
    "chromatograms"
69
})
70
@XmlRootElement(name = "Sequence")
71
@Entity
72
@Audited
73
@Configurable
74
@Table(appliesTo="Sequence", indexes = { @Index(name = "sequenceTitleCacheIndex", columnNames = { "titleCache" }) })
75
public class Sequence extends IdentifiableEntity<IIdentifiableEntityCacheStrategy<Sequence>> implements IReferencedEntity, IMediaDocumented{
76
	private static final long serialVersionUID = 8298983152731241775L;
77
	private static final Logger logger = Logger.getLogger(Sequence.class);
78
	
79
	//the sequence as a string of base pairs. 5'->3'
80
	@XmlElement(name = "Sequence")
81
	private String sequence;
82
	
83
	//should be calculated in case sequence is set
84
	@XmlElement(name = "Length")
85
	private Integer length;
86
	
87
	//should be calculated in case sequence is set
88
	@XmlElement (name = "DateSequenced", type= String.class)
89
	@XmlJavaTypeAdapter(DateTimeAdapter.class)
90
	@Type(type="dateTimeUserType")
91
	@Basic(fetch = FetchType.LAZY)
92
	private DateTime dateSequenced;
93
	
94
	//should be calculated in case sequence is set
95
	@XmlAttribute(name = "isBarcode")
96
	private boolean barcode;
97
	
98
	//the sequence as a string of base pairs. 5'->3'
99
	@XmlElement(name = "CitationMicroReference")
100
	private String citationMicroReference;
101
	
102
	@XmlElement(name = "PublishedIn")
103
    @XmlIDREF
104
    @XmlSchemaType(name = "IDREF")
105
    @ManyToOne(fetch = FetchType.LAZY)
106
    @Cascade(CascadeType.SAVE_UPDATE)
107
	private Reference publishedIn;
108
	
109
	@XmlElementWrapper(name = "Citations")
110
	@XmlElement(name = "Citation")
111
    @XmlIDREF
112
    @XmlSchemaType(name = "IDREF")
113
    @OneToMany(fetch = FetchType.LAZY)
114
	private Set<Reference> citations = new HashSet<Reference>();
115
	
116
	@XmlElementWrapper(name = "GenBankAccessions")
117
	@XmlElement(name = "GenBankAccession")
118
    @OneToMany(fetch = FetchType.LAZY)
119
	private Set<GenBankAccession> genBankAccession = new HashSet<GenBankAccession>();
120
	
121
	@XmlElement(name = "Locus")
122
    @XmlIDREF
123
    @XmlSchemaType(name = "IDREF")
124
    @ManyToOne(fetch = FetchType.LAZY)
125
    @Cascade(CascadeType.SAVE_UPDATE)
126
	private Locus locus;
127
	
128
	@XmlElementWrapper(name = "Chromatograms")
129
	@XmlElement(name = "Chromatogram")
130
    @XmlIDREF
131
    @XmlSchemaType(name = "IDREF")
132
    @OneToMany(fetch = FetchType.LAZY)
133
	private Set<Media> chromatograms = new HashSet<Media>();
134
	
135
	protected Sequence() {
136
		super(); // FIXME I think this is explicit - do we really need to call this?
137
		this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Sequence>();
138
	}
139
	
140
	public Locus getLocus(){
141
		logger.debug("getLocus");
142
		return this.locus;
143
	}
144

    
145
	public void setLocus(Locus locus){
146
		this.locus = locus;
147
	}
148

    
149
	public Reference getPublishedIn(){
150
		return this.publishedIn;
151
	}
152
	
153
	public void setPublishedIn(Reference publishedIn){
154
		this.publishedIn = publishedIn;
155
	}
156

    
157
	public Set<Reference> getCitations() {
158
		return citations;
159
	}
160
	protected void setCitations(Set<Reference> citations) {
161
		this.citations = citations;
162
	}
163
	public void addCitation(Reference citation) {
164
		this.citations.add(citation);
165
	}
166
	public void removeCitation(Reference citation) {
167
		this.citations.remove(citation);
168
	}
169

    
170
	public Set<GenBankAccession> getGenBankAccession() {
171
		return genBankAccession;
172
	}
173

    
174
	public void addGenBankAccession(GenBankAccession genBankAccession) {
175
		this.genBankAccession.add(genBankAccession);
176
	}
177
	
178
	public void removeGenBankAccession(GenBankAccession genBankAccession) {
179
		this.genBankAccession.remove(genBankAccession);
180
	}
181
	
182
	public Set<Media> getChromatograms() {
183
		return chromatograms;
184
	}
185

    
186
	public void addChromatogram(Media chromatogram) {
187
		this.chromatograms.add(chromatogram);
188
	}
189
	
190
	public void removeChromatogram(Media chromatogram) {
191
		this.chromatograms.remove(chromatogram);
192
	}
193
	
194
	@Transient
195
	public Set<Media> getMedia() {
196
		return getChromatograms();
197
	}
198

    
199
	public String getSequence(){
200
		return this.sequence;
201
	}
202

    
203
	/**
204
	 * 
205
	 * @param sequence    sequence
206
	 */
207
	public void setSequence(String sequence){
208
		this.sequence = sequence;
209
	}
210

    
211
	public Integer getLength(){
212
		return this.length;
213
	}
214

    
215
	/**
216
	 * 
217
	 * @param length    length
218
	 */
219
	public void setLength(Integer length){
220
		this.length = length;
221
	}
222

    
223
	public DateTime getDateSequenced(){
224
		return this.dateSequenced;
225
	}
226

    
227
	/**
228
	 * 
229
	 * @param dateSequenced    dateSequenced
230
	 */
231
	public void setDateSequenced(DateTime dateSequenced){
232
		this.dateSequenced = dateSequenced;
233
	}
234

    
235
	public boolean isBarcode(){
236
		return this.barcode;
237
	}
238

    
239
	/**
240
	 * 
241
	 * @param isBarcode    isBarcode
242
	 */
243
	public void setBarcode(boolean barcode){
244
		this.barcode = barcode;
245
	}
246

    
247
	public String getCitationMicroReference(){
248
		return this.citationMicroReference;
249
	}
250

    
251
	/**
252
	 * 
253
	 * @param citationMicroReference    citationMicroReference
254
	 */
255
	public void setCitationMicroReference(String citationMicroReference){
256
		this.citationMicroReference = citationMicroReference;
257
	}
258

    
259
	public Reference getCitation(){
260
		return publishedIn;
261
	}
262
	
263
	//*********************** CLONE ********************************************************/
264
	/** 
265
	 * Clones <i>this</i> sequence. This is a shortcut that enables to create
266
	 * a new instance that differs only slightly from <i>this</i> sequence by
267
	 * modifying only some of the attributes.<BR><BR>
268
	 * 
269
	 *  
270
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
271
	 * @see java.lang.Object#clone()
272
	 */
273
	@Override
274
	public Object clone()  {
275
		try{
276
		Sequence result = (Sequence)super.clone();
277
		
278
		result.citations = new HashSet<Reference>();
279
		for (Reference ref: this.citations){
280
			result.citations.add((Reference) ref.clone());
281
		
282
		}
283
		
284
		result.genBankAccession = new HashSet<GenBankAccession>();
285
		for (GenBankAccession genBankAcc: this.genBankAccession){
286
			result.genBankAccession.add((GenBankAccession)genBankAcc.clone());
287
		}
288
		
289
		result.chromatograms = new HashSet<Media>();
290
		
291
		for (Media chromatogram: this.chromatograms){
292
			result.chromatograms.add((Media)chromatogram.clone());
293
		}
294
		
295
		return result;
296
		}catch (CloneNotSupportedException e) {
297
			logger.warn("Object does not implement cloneable");
298
			e.printStackTrace();
299
			return null;
300
		}
301
	}
302
}
(5-5/7)