making constructor private again
[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.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.envers.Audited;
31 import org.hibernate.search.annotations.Indexed;
32
33 import eu.etaxonomy.cdm.model.occurrence.Collection;
34 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
35 import eu.etaxonomy.cdm.model.occurrence.Specimen;
36 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
37 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
38
39 /**
40 * @author m.doering
41 * @version 1.0
42 * @created 08-Nov-2007 13:06:22
43 */
44 @XmlAccessorType(XmlAccessType.FIELD)
45 @XmlType(name = "DnaSample", propOrder = {
46 "sequences"
47 })
48 @XmlRootElement(name = "DnaSample")
49 @Entity
50 @Indexed(index = "eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase")
51 @Audited
52 public class DnaSample extends Specimen implements Cloneable {
53 private static final long serialVersionUID = -2978411330023671805L;
54 private static final Logger logger = Logger.getLogger(DnaSample.class);
55
56 /**
57 * Factory method
58 * @return
59 */
60 public static DnaSample NewInstance(){
61 return new DnaSample();
62 }
63
64
65 // @XmlElement(name = "BankNumber")
66 // private String bankNumber;
67
68 @XmlElementWrapper(name = "Sequences")
69 @XmlElement(name = "sequence")
70 @XmlIDREF
71 @XmlSchemaType(name = "IDREF")
72 @OneToMany(fetch = FetchType.LAZY)
73 private Set<Sequence> sequences = new HashSet<Sequence>();
74
75
76
77 /**
78 * Constructor
79 */
80 private DnaSample() {
81 super();
82 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Specimen>();
83 }
84
85 public Set<Sequence> getSequences() {
86 return sequences;
87 }
88
89 // FIXME shouldn't this be the singular? i.e. addSequence( . . . )
90 public void addSequences(Sequence sequence) {
91 this.sequences.add(sequence);
92 }
93
94 // FIXME shouldn't this be the singular? i.e. removeSequence( . . . )
95 public void removeSequences(Sequence sequence) {
96 this.sequences.remove(sequence);
97 }
98
99 @Transient
100 public Collection getStoredAt(){
101 return this.getCollection();
102 }
103
104 public void setStoredAt(Collection storedAt){
105 this.setCollection(storedAt);
106 }
107
108 @Transient
109 public Set<SpecimenOrObservationBase> getExtractedFrom(){
110 return getOriginals();
111 }
112
113 @Transient
114 public String getBankNumber(){
115 return this.getCatalogNumber();
116 }
117
118 public void setBankNumber(String bankNumber){
119 this.setCatalogNumber(bankNumber);
120 }
121
122
123 //*********** CLONE **********************************/
124
125 /**
126 * Clones <i>this</i> dna sample. This is a shortcut that enables to
127 * create a new instance that differs only slightly from <i>this</i> dna sample
128 * by modifying only some of the attributes.<BR>
129 * This method overrides the clone method from {@link Specimen Specimen}.
130 *
131 * @see Specimen#clone()
132 * @see DerivedUnitBase#clone()
133 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
134 * @see java.lang.Object#clone()
135 */
136 @Override
137 public DnaSample clone(){
138 DnaSample result = (DnaSample)super.clone();
139 //sequenceSet
140 result.sequences = new HashSet<Sequence>();
141 for(Sequence sequence : this.sequences) {
142 result.addSequences(sequence);
143 }
144 //no changes to: bankNumber
145 return result;
146 }
147 }