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