Project

General

Profile

Download (6.16 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
package eu.etaxonomy.cdm.model.molecular;
10

    
11
import java.util.HashSet;
12
import java.util.Set;
13

    
14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.ManyToOne;
17
import javax.persistence.OneToMany;
18
import javax.persistence.Transient;
19
import javax.validation.constraints.NotNull;
20
import javax.xml.bind.annotation.XmlAccessType;
21
import javax.xml.bind.annotation.XmlAccessorType;
22
import javax.xml.bind.annotation.XmlElement;
23
import javax.xml.bind.annotation.XmlElementWrapper;
24
import javax.xml.bind.annotation.XmlIDREF;
25
import javax.xml.bind.annotation.XmlRootElement;
26
import javax.xml.bind.annotation.XmlSchemaType;
27
import javax.xml.bind.annotation.XmlType;
28

    
29
import org.apache.log4j.Logger;
30
import org.hibernate.annotations.Cascade;
31
import org.hibernate.annotations.CascadeType;
32
import org.hibernate.envers.Audited;
33
import org.hibernate.search.annotations.IndexedEmbedded;
34

    
35
import eu.etaxonomy.cdm.model.occurrence.Collection;
36
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
37
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
38
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
39
import eu.etaxonomy.cdm.strategy.cache.occurrence.DnaSampleDefaultCacheStrategy;
40

    
41
/**
42
 * A DNA Sample is the extracted DNA of a given tissue sample. It may be stored in
43
 * a DNA Bank and should then be handled as a collection unit.
44
 * DNA Sample are used to determine their {@link Sequence DNA sequences}
45
 * starting with a process called {@link Amplification amplification}.
46
 *
47
 * @author m.doering
48
 * @since 08-Nov-2007
49
 */
50
@XmlAccessorType(XmlAccessType.FIELD)
51
@XmlType(name = "DnaSample", propOrder = {
52
    "sequences",
53
    "amplificationResults",
54
    "dnaQuality"
55
})
56
@XmlRootElement(name = "DnaSample")
57
@Entity
58
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
59
//@Indexed(index = "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase")
60
@Audited
61
public class DnaSample extends DerivedUnit {
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 a new and empty DnaSample
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(mappedBy="dnaSample", fetch = FetchType.LAZY)
86
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
87
    private Set<Sequence> sequences = new HashSet<>();
88

    
89
	@XmlElementWrapper(name = "AmplificationResults")
90
	@XmlElement(name = "AmplificationResult")
91
	@OneToMany(mappedBy="dnaSample", fetch = FetchType.LAZY)
92
	@Cascade( { CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE})
93
    @NotNull
94
	private final Set<AmplificationResult> amplificationResults = new HashSet<>();
95

    
96
    @XmlElement(name = "DnaQuality", required = true)
97
    @XmlIDREF
98
    @XmlSchemaType(name = "IDREF")
99
    @ManyToOne(fetch = FetchType.LAZY)
100
    @IndexedEmbedded
101
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
102
    private DnaQuality dnaQuality;
103

    
104
// ******************* CONSTRUCTOR *************************/
105

    
106
	protected DnaSample() {  //protected for Javassist, otherwise private
107
		super(SpecimenOrObservationType.DnaSample);
108
		this.cacheStrategy = new DnaSampleDefaultCacheStrategy();
109
	}
110

    
111
//************ GETTER / SETTER  **********************************/
112

    
113
	//sequencings
114
	public Set<Sequence> getSequences() {
115
		return sequences;
116
	}
117
	public void addSequence(Sequence sequence) {
118
		if (sequence.getDnaSample() != null){
119
			sequence.getDnaSample().removeSequence(sequence);
120
		}
121
		this.sequences.add(sequence);
122
		sequence.setDnaSample(this);
123
	}
124
	public void removeSequence(Sequence sequence) {
125
		sequence.setDnaSample(null);
126
		this.sequences.remove(sequence);
127
	}
128

    
129
	//amplifications
130
	public Set<AmplificationResult> getAmplificationResults() {
131
		return amplificationResults;
132
	}
133
	public void addAmplificationResult(AmplificationResult amplificationResult) {
134
		this.amplificationResults.add(amplificationResult);
135
		amplificationResult.setDnaSample(this);
136
	}
137
	public void removeAmplificationResult(AmplificationResult amplificationResult) {
138
		this.amplificationResults.remove(amplificationResult);
139
		amplificationResult.setDnaSample(null);
140
	}
141

    
142
	public DnaQuality getDnaQuality() {
143
		return dnaQuality;
144
	}
145
	public void setDnaQuality(DnaQuality dnaQuality) {
146
		this.dnaQuality = dnaQuality;
147
	}
148

    
149
// ************* Convenience Getter / Setter ************/
150

    
151
	@Transient
152
	public Collection getStoredAt(){
153
		return this.getCollection();
154
	}
155
	public void setStoredAt(Collection storedAt){
156
		this.setCollection(storedAt);
157
	}
158

    
159
	@Transient
160
	public Set<SpecimenOrObservationBase> getExtractedFrom(){
161
		return getOriginals();
162
	}
163

    
164
	@Transient
165
	public String getBankNumber(){
166
		return this.getCatalogNumber();
167
	}
168
	public void setBankNumber(String bankNumber){
169
		this.setCatalogNumber(bankNumber);
170
	}
171

    
172
//*********** CLONE **********************************/
173

    
174
	/**
175
	 * Clones <i>this</i> dna sample. This is a shortcut that enables to
176
	 * create a new instance that differs only slightly from <i>this</i> dna sample
177
	 * by modifying only some of the attributes.<BR>
178
	 * This method overrides the clone method from {@link Specimen Specimen}.
179
	 * @throws CloneNotSupportedException
180
	 *
181
	 * @see Specimen#clone()
182
	 * @see DerivedUnit#clone()
183
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
184
	 * @see java.lang.Object#clone()
185
	 */
186
	@Override
187
	public DnaSample clone() {
188
		DnaSample result = (DnaSample)super.clone();
189
		//sequenceSet
190
		result.sequences = new HashSet<>();
191
		for(Sequence sequence : this.sequences) {
192
			result.addSequence(sequence.clone());
193
		}
194
		//no changes to: bankNumber
195
		return result;
196
	}
197
}
(5-5/14)