minor
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / molecular / DnaSample.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 java.util.HashSet;
14 import java.util.Set;
15
16 import javax.persistence.Entity;
17 import javax.persistence.FetchType;
18 import javax.persistence.OneToMany;
19 import javax.persistence.Transient;
20 import javax.validation.constraints.NotNull;
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlElement;
24 import javax.xml.bind.annotation.XmlElementWrapper;
25 import javax.xml.bind.annotation.XmlIDREF;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import javax.xml.bind.annotation.XmlSchemaType;
28 import javax.xml.bind.annotation.XmlType;
29
30 import org.apache.log4j.Logger;
31 import org.hibernate.annotations.Cascade;
32 import org.hibernate.annotations.CascadeType;
33 import org.hibernate.envers.Audited;
34 import org.hibernate.search.annotations.ContainedIn;
35 import org.hibernate.search.annotations.Indexed;
36
37 import eu.etaxonomy.cdm.model.occurrence.Collection;
38 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
39 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
40 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
41 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
42
43 /**
44 * A DNA Sample is the extracted DNA of a given tissue sample. It may be stored in
45 * a DNA Bank and should then be handled as a collection unit.
46 * DNA Sample are used to determine their {@link Sequence DNA sequences}
47 * starting with a process called {@link Amplification amplification}.
48 *
49 * @author m.doering
50 * @created 08-Nov-2007
51 */
52 @XmlAccessorType(XmlAccessType.FIELD)
53 @XmlType(name = "DnaSample", propOrder = {
54 "sequences",
55 "amplifications"
56 })
57 @XmlRootElement(name = "DnaSample")
58 @Entity
59 @Indexed(index = "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase")
60 @Audited
61 public class DnaSample extends DerivedUnit implements Cloneable {
62 private static final long serialVersionUID = -2978411330023671805L;
63 @SuppressWarnings("unused")
64 private static final Logger logger = Logger.getLogger(DnaSample.class);
65
66 // ****************** FACTORY METHOD *****************/
67
68 /**
69 * Factory method
70 * @return
71 */
72 public static DnaSample NewInstance(){
73 return new DnaSample();
74 }
75
76 // ************** ATTRIBUTES ****************************/
77
78 // @XmlElement(name = "BankNumber")
79 // private String bankNumber;
80
81 @XmlElementWrapper(name = "Sequences")
82 @XmlElement(name = "sequence")
83 @XmlIDREF
84 @XmlSchemaType(name = "IDREF")
85 @OneToMany(fetch = FetchType.LAZY)
86 @Cascade(CascadeType.SAVE_UPDATE)
87 private Set<Sequence> sequences = new HashSet<Sequence>();
88
89
90 @XmlElementWrapper(name = "Amplifications")
91 @XmlElement(name = "Amplification")
92 @OneToMany(mappedBy="dnaSample", fetch = FetchType.LAZY)
93 @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE})
94 @ContainedIn
95 @NotNull
96 private Set<Amplification> amplifications = new HashSet<Amplification>();
97
98
99 // ******************* CONSTRUCTOR *************************/
100
101 /**
102 * Constructor
103 */
104 private DnaSample() {
105 super(SpecimenOrObservationType.PreservedSpecimen);
106 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<DerivedUnit>();
107 }
108
109 //************ GETTER / SETTER **********************************/
110
111 //sequencings
112 public Set<Sequence> getSequences() {
113 return sequences;
114 }
115
116 public void addSequence(Sequence sequence) {
117 this.sequences.add(sequence);
118 }
119
120 public void removeSequence(Sequence sequence) {
121 this.sequences.remove(sequence);
122 }
123
124 //amplifications
125 public Set<Amplification> getAmplifications() {
126 return amplifications;
127 }
128
129 public void addAmplification(Amplification amplification) {
130 this.amplifications.add(amplification);
131 amplification.setDnaSample(this);
132 }
133
134 public void removeAmplification(Amplification amplification) {
135 this.amplifications.remove(amplification);
136 }
137
138 // ************* Convenience Getter / Setter ************/
139
140 @Transient
141 public Collection getStoredAt(){
142 return this.getCollection();
143 }
144
145 public void setStoredAt(Collection storedAt){
146 this.setCollection(storedAt);
147 }
148
149 @Transient
150 public Set<SpecimenOrObservationBase> getExtractedFrom(){
151 return getOriginals();
152 }
153
154 @Transient
155 public String getBankNumber(){
156 return this.getCatalogNumber();
157 }
158
159 public void setBankNumber(String bankNumber){
160 this.setCatalogNumber(bankNumber);
161 }
162
163
164 //*********** CLONE **********************************/
165
166 /**
167 * Clones <i>this</i> dna sample. This is a shortcut that enables to
168 * create a new instance that differs only slightly from <i>this</i> dna sample
169 * by modifying only some of the attributes.<BR>
170 * This method overrides the clone method from {@link Specimen Specimen}.
171 * @throws CloneNotSupportedException
172 *
173 * @see Specimen#clone()
174 * @see DerivedUnit#clone()
175 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
176 * @see java.lang.Object#clone()
177 */
178 @Override
179 public DnaSample clone() {
180 DnaSample result = (DnaSample)super.clone();
181 //sequenceSet
182 result.sequences = new HashSet<Sequence>();
183 for(Sequence sequence : this.sequences) {
184 result.addSequence(sequence);
185 }
186 //no changes to: bankNumber
187 return result;
188 }
189 }