Project

General

Profile

Download (6.81 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;import org.apache.logging.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

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

    
67
// ****************** FACTORY METHOD *****************/
68

    
69
	/**
70
	 * Factory method
71
	 * @return a new and empty DnaSample
72
	 */
73
	public static DnaSample NewInstance(){
74
		return new DnaSample(SpecimenOrObservationType.DnaSample);
75
	}
76

    
77
    public static DnaSample NewTissueSampleAsDnaSampleInstance(){
78
        return new DnaSample(SpecimenOrObservationType.TissueSample);
79
    }
80

    
81
// ************** ATTRIBUTES ****************************/
82

    
83
//	@XmlElement(name = "BankNumber")
84
//	private String bankNumber;
85

    
86
	@XmlElementWrapper(name = "Sequences")
87
	@XmlElement(name = "sequence")
88
    @XmlIDREF
89
    @XmlSchemaType(name = "IDREF")
90
    @OneToMany(mappedBy="dnaSample", fetch = FetchType.LAZY)
91
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
92
    private Set<Sequence> sequences = new HashSet<>();
93

    
94
	@XmlElementWrapper(name = "AmplificationResults")
95
	@XmlElement(name = "AmplificationResult")
96
	@OneToMany(mappedBy="dnaSample", fetch = FetchType.LAZY)
97
	@Cascade( { CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE})
98
    @NotNull
99
	private final Set<AmplificationResult> amplificationResults = new HashSet<>();
100

    
101
    @XmlElement(name = "DnaQuality", required = true)
102
    @XmlIDREF
103
    @XmlSchemaType(name = "IDREF")
104
    @ManyToOne(fetch = FetchType.LAZY)
105
    @IndexedEmbedded
106
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
107
    private DnaQuality dnaQuality;
108

    
109
// ******************* CONSTRUCTOR *************************/
110

    
111
    /**
112
     * @deprecated for hibernate use only
113
     */
114
    @Deprecated
115
	protected DnaSample() {  //protected for Javassist, otherwise private
116
		super();
117
	}
118

    
119
	private  DnaSample(SpecimenOrObservationType type) {  //protected for Javassist, otherwise private
120
        super(type);
121
    }
122

    
123
    @Override
124
    protected void initDefaultCacheStrategy() {
125
        if (this.getRecordBasis() == null || SpecimenOrObservationType.DnaSample.equals(this.getRecordBasis())){
126
            this.cacheStrategy = new DnaSampleDefaultCacheStrategy();
127
        }else{
128
            super.initDefaultCacheStrategy();
129
        }
130
    }
131

    
132
//************ GETTER / SETTER  **********************************/
133

    
134
    //sequencings
135
	public Set<Sequence> getSequences() {
136
		return sequences;
137
	}
138
	public void addSequence(Sequence sequence) {
139
		if (sequence.getDnaSample() != null){
140
			sequence.getDnaSample().removeSequence(sequence);
141
		}
142
		this.sequences.add(sequence);
143
		sequence.setDnaSample(this);
144
	}
145
	public void removeSequence(Sequence sequence) {
146
		sequence.setDnaSample(null);
147
		this.sequences.remove(sequence);
148
	}
149

    
150
	//amplifications
151
	public Set<AmplificationResult> getAmplificationResults() {
152
		return amplificationResults;
153
	}
154
	public void addAmplificationResult(AmplificationResult amplificationResult) {
155
		this.amplificationResults.add(amplificationResult);
156
		amplificationResult.setDnaSample(this);
157
	}
158
	public void removeAmplificationResult(AmplificationResult amplificationResult) {
159
		this.amplificationResults.remove(amplificationResult);
160
		amplificationResult.setDnaSample(null);
161
	}
162

    
163
	public DnaQuality getDnaQuality() {
164
		return dnaQuality;
165
	}
166
	public void setDnaQuality(DnaQuality dnaQuality) {
167
		this.dnaQuality = dnaQuality;
168
	}
169

    
170
// ************* Convenience Getter / Setter ************/
171

    
172
	@Transient
173
	public Collection getStoredAt(){
174
		return this.getCollection();
175
	}
176
	public void setStoredAt(Collection storedAt){
177
		this.setCollection(storedAt);
178
	}
179

    
180
	@Transient
181
	public Set<SpecimenOrObservationBase> getExtractedFrom(){
182
		return getOriginals();
183
	}
184

    
185
	@Transient
186
	public String getBankNumber(){
187
		return this.getCatalogNumber();
188
	}
189
	public void setBankNumber(String bankNumber){
190
		this.setCatalogNumber(bankNumber);
191
	}
192

    
193
//*********** CLONE **********************************/
194

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