Project

General

Profile

Download (6.58 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.logging.log4j.LogManager;
30
import org.apache.logging.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.IndexedEmbedded;
35

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

    
42
/**
43
 * A DNA Sample is the extracted DNA of a given tissue sample. It may be stored in
44
 * a DNA Bank and should then be handled as a collection unit.
45
 * DNA Sample are used to determine their {@link Sequence DNA sequences}
46
 * starting with a process called {@link Amplification amplification}.
47
 *
48
 * @author m.doering
49
 * @since 08-Nov-2007
50
 */
51
@XmlAccessorType(XmlAccessType.FIELD)
52
@XmlType(name = "DnaSample", propOrder = {
53
    "sequences",
54
    "amplificationResults",
55
    "dnaQuality"
56
})
57
@XmlRootElement(name = "DnaSample")
58
@Entity
59
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
60
//@Indexed(index = "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase")
61
@Audited
62
public class DnaSample extends DerivedUnit {
63

    
64
	private static final long serialVersionUID = -2978411330023671805L;
65
	@SuppressWarnings("unused")
66
	private static final Logger logger = LogManager.getLogger(DnaSample.class);
67

    
68
// ****************** FACTORY METHOD *****************/
69

    
70
	public static DnaSample NewInstance(){
71
		return new DnaSample(SpecimenOrObservationType.DnaSample);
72
	}
73

    
74
    public static DnaSample NewTissueSampleAsDnaSampleInstance(){
75
        return new DnaSample(SpecimenOrObservationType.TissueSample);
76
    }
77

    
78
// ************** ATTRIBUTES ****************************/
79

    
80
	@XmlElementWrapper(name = "Sequences")
81
	@XmlElement(name = "sequence")
82
    @XmlIDREF
83
    @XmlSchemaType(name = "IDREF")
84
    @OneToMany(mappedBy="dnaSample", fetch = FetchType.LAZY)
85
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
86
    private Set<Sequence> sequences = new HashSet<>();
87

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

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

    
103
// ******************* CONSTRUCTOR *************************/
104

    
105
    //for hibernate use only, *packet* private required by bytebuddy
106
    @Deprecated
107
	DnaSample() {}
108

    
109
	private  DnaSample(SpecimenOrObservationType type) {
110
        super(type);
111
    }
112

    
113
    @Override
114
    protected void initDefaultCacheStrategy() {
115
        if (this.getRecordBasis() == null || SpecimenOrObservationType.DnaSample.equals(this.getRecordBasis())){
116
            this.cacheStrategy = new DnaSampleDefaultCacheStrategy();
117
        }else{
118
            super.initDefaultCacheStrategy();
119
        }
120
    }
121

    
122
//************ GETTER / SETTER  **********************************/
123

    
124
    //sequencings
125
	public Set<Sequence> getSequences() {
126
		return sequences;
127
	}
128
	public void addSequence(Sequence sequence) {
129
		if (sequence.getDnaSample() != null){
130
			sequence.getDnaSample().removeSequence(sequence);
131
		}
132
		this.sequences.add(sequence);
133
		sequence.setDnaSample(this);
134
	}
135
	public void removeSequence(Sequence sequence) {
136
		sequence.setDnaSample(null);
137
		this.sequences.remove(sequence);
138
	}
139

    
140
	//amplifications
141
	public Set<AmplificationResult> getAmplificationResults() {
142
		return amplificationResults;
143
	}
144
	public void addAmplificationResult(AmplificationResult amplificationResult) {
145
		this.amplificationResults.add(amplificationResult);
146
		amplificationResult.setDnaSample(this);
147
	}
148
	public void removeAmplificationResult(AmplificationResult amplificationResult) {
149
		this.amplificationResults.remove(amplificationResult);
150
		amplificationResult.setDnaSample(null);
151
	}
152

    
153
	public DnaQuality getDnaQuality() {
154
		return dnaQuality;
155
	}
156
	public void setDnaQuality(DnaQuality dnaQuality) {
157
		this.dnaQuality = dnaQuality;
158
	}
159

    
160
// ************* Convenience Getter / Setter ************/
161

    
162
	@Transient
163
	public Collection getStoredAt(){
164
		return this.getCollection();
165
	}
166
	public void setStoredAt(Collection storedAt){
167
		this.setCollection(storedAt);
168
	}
169

    
170
	@Transient
171
	public Set<SpecimenOrObservationBase> getExtractedFrom(){
172
		return getOriginals();
173
	}
174

    
175
	@Transient
176
	public String getBankNumber(){
177
		return this.getCatalogNumber();
178
	}
179
	public void setBankNumber(String bankNumber){
180
		this.setCatalogNumber(bankNumber);
181
	}
182

    
183
//*********** CLONE **********************************/
184

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