Lots of changes, but primarily:
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / molecular / Sequence.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.molecular;
11
12
13 import eu.etaxonomy.cdm.model.media.IMediaDocumented;
14 import eu.etaxonomy.cdm.model.media.Media;
15 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
16 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
17 import eu.etaxonomy.cdm.model.common.IReferencedEntity;
18 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
19 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
20
21 import org.apache.log4j.Logger;
22 import org.hibernate.annotations.Cascade;
23 import org.hibernate.annotations.CascadeType;
24 import org.hibernate.annotations.Index;
25 import org.hibernate.annotations.Table;
26 import org.hibernate.envers.Audited;
27 import org.springframework.beans.factory.annotation.Configurable;
28
29 import java.util.*;
30
31 import javax.persistence.*;
32 import javax.xml.bind.annotation.XmlAccessType;
33 import javax.xml.bind.annotation.XmlAccessorType;
34 import javax.xml.bind.annotation.XmlAttribute;
35 import javax.xml.bind.annotation.XmlElement;
36 import javax.xml.bind.annotation.XmlElementWrapper;
37 import javax.xml.bind.annotation.XmlIDREF;
38 import javax.xml.bind.annotation.XmlRootElement;
39 import javax.xml.bind.annotation.XmlSchemaType;
40 import javax.xml.bind.annotation.XmlType;
41
42 /**
43 * @author m.doering
44 * @version 1.0
45 * @created 08-Nov-2007 13:06:51
46 */
47 @XmlAccessorType(XmlAccessType.FIELD)
48 @XmlType(name = "Sequence", propOrder = {
49 "sequence",
50 "length",
51 "dateSequenced",
52 "barcode",
53 "citationMicroReference",
54 "publishedIn",
55 "locus",
56 "citations",
57 "genBankAccession",
58 "chromatograms"
59 })
60 @XmlRootElement(name = "Sequence")
61 @Entity
62 @Audited
63 @Configurable
64 @Table(appliesTo="Sequence", indexes = { @Index(name = "sequenceTitleCacheIndex", columnNames = { "titleCache" }) })
65 public class Sequence extends IdentifiableEntity<IIdentifiableEntityCacheStrategy<Sequence>> implements IReferencedEntity, IMediaDocumented{
66 private static final long serialVersionUID = 8298983152731241775L;
67 private static final Logger logger = Logger.getLogger(Sequence.class);
68
69 //the sequence as a string of base pairs. 5'->3'
70 @XmlElement(name = "Sequence")
71 private String sequence;
72
73 //should be calculated in case sequence is set
74 @XmlElement(name = "Length")
75 private Integer length;
76
77 //should be calculated in case sequence is set
78 @XmlElement(name = "DateSequenced")
79 @Temporal(TemporalType.DATE)
80 private Calendar dateSequenced;
81
82 //should be calculated in case sequence is set
83 @XmlAttribute(name = "isBarcode")
84 private boolean barcode;
85
86 //the sequence as a string of base pairs. 5'->3'
87 @XmlElement(name = "CitationMicroReference")
88 private String citationMicroReference;
89
90 @XmlElement(name = "PublishedIn")
91 @XmlIDREF
92 @XmlSchemaType(name = "IDREF")
93 @ManyToOne(fetch = FetchType.LAZY)
94 @Cascade(CascadeType.SAVE_UPDATE)
95 private ReferenceBase publishedIn;
96
97 @XmlElementWrapper(name = "Citations")
98 @XmlElement(name = "Citation")
99 @XmlIDREF
100 @XmlSchemaType(name = "IDREF")
101 @OneToMany(fetch = FetchType.LAZY)
102 private Set<ReferenceBase> citations = new HashSet<ReferenceBase>();
103
104 @XmlElementWrapper(name = "GenBankAccessions")
105 @XmlElement(name = "GenBankAccession")
106 @OneToMany(fetch = FetchType.LAZY)
107 private Set<GenBankAccession> genBankAccession = new HashSet<GenBankAccession>();
108
109 @XmlElement(name = "Locus")
110 @XmlIDREF
111 @XmlSchemaType(name = "IDREF")
112 @ManyToOne(fetch = FetchType.LAZY)
113 @Cascade(CascadeType.SAVE_UPDATE)
114 private Locus locus;
115
116 @XmlElementWrapper(name = "Chromatograms")
117 @XmlElement(name = "Chromatogram")
118 @XmlIDREF
119 @XmlSchemaType(name = "IDREF")
120 @OneToMany(fetch = FetchType.LAZY)
121 private Set<Media> chromatograms = new HashSet<Media>();
122
123 protected Sequence() {
124 super(); // FIXME I think this is explicit - do we really need to call this?
125 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Sequence>();
126 }
127
128 public Locus getLocus(){
129 logger.debug("getLocus");
130 return this.locus;
131 }
132
133 public void setLocus(Locus locus){
134 this.locus = locus;
135 }
136
137 public ReferenceBase getPublishedIn(){
138 return this.publishedIn;
139 }
140
141 public void setPublishedIn(ReferenceBase publishedIn){
142 this.publishedIn = publishedIn;
143 }
144
145 public Set<ReferenceBase> getCitations() {
146 return citations;
147 }
148 protected void setCitations(Set<ReferenceBase> citations) {
149 this.citations = citations;
150 }
151 public void addCitation(ReferenceBase citation) {
152 this.citations.add(citation);
153 }
154 public void removeCitation(ReferenceBase citation) {
155 this.citations.remove(citation);
156 }
157
158 public Set<GenBankAccession> getGenBankAccession() {
159 return genBankAccession;
160 }
161
162 public void addGenBankAccession(GenBankAccession genBankAccession) {
163 this.genBankAccession.add(genBankAccession);
164 }
165
166 public void removeGenBankAccession(GenBankAccession genBankAccession) {
167 this.genBankAccession.remove(genBankAccession);
168 }
169
170 public Set<Media> getChromatograms() {
171 return chromatograms;
172 }
173
174 public void addChromatogram(Media chromatogram) {
175 this.chromatograms.add(chromatogram);
176 }
177
178 public void removeChromatogram(Media chromatogram) {
179 this.chromatograms.remove(chromatogram);
180 }
181
182 @Transient
183 public Set<Media> getMedia() {
184 return getChromatograms();
185 }
186
187 public String getSequence(){
188 return this.sequence;
189 }
190
191 /**
192 *
193 * @param sequence sequence
194 */
195 public void setSequence(String sequence){
196 this.sequence = sequence;
197 }
198
199 public Integer getLength(){
200 return this.length;
201 }
202
203 /**
204 *
205 * @param length length
206 */
207 public void setLength(Integer length){
208 this.length = length;
209 }
210
211 public Calendar getDateSequenced(){
212 return this.dateSequenced;
213 }
214
215 /**
216 *
217 * @param dateSequenced dateSequenced
218 */
219 public void setDateSequenced(Calendar dateSequenced){
220 this.dateSequenced = dateSequenced;
221 }
222
223 public boolean isBarcode(){
224 return this.barcode;
225 }
226
227 /**
228 *
229 * @param isBarcode isBarcode
230 */
231 public void setBarcode(boolean barcode){
232 this.barcode = barcode;
233 }
234
235 public String getCitationMicroReference(){
236 return this.citationMicroReference;
237 }
238
239 /**
240 *
241 * @param citationMicroReference citationMicroReference
242 */
243 public void setCitationMicroReference(String citationMicroReference){
244 this.citationMicroReference = citationMicroReference;
245 }
246
247 public ReferenceBase getCitation(){
248 return publishedIn;
249 }
250 }