cleanup
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / occurrence / PreservationMethod.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 package eu.etaxonomy.cdm.model.occurrence;
10
11 import javax.persistence.Entity;
12 import javax.persistence.FetchType;
13 import javax.persistence.ManyToOne;
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlIDREF;
18 import javax.xml.bind.annotation.XmlRootElement;
19 import javax.xml.bind.annotation.XmlSchemaType;
20 import javax.xml.bind.annotation.XmlType;
21
22 import org.apache.logging.log4j.LogManager;
23 import org.apache.logging.log4j.Logger;
24 import org.hibernate.envers.Audited;
25 import org.hibernate.search.annotations.Analyze;
26 import org.hibernate.search.annotations.Field;
27 import org.hibernate.search.annotations.IndexedEmbedded;
28 import org.hibernate.search.annotations.NumericField;
29
30 import eu.etaxonomy.cdm.model.common.EventBase;
31 import eu.etaxonomy.cdm.model.molecular.Cloning;
32 import eu.etaxonomy.cdm.model.term.DefinedTerm;
33 import eu.etaxonomy.cdm.model.term.TermType;
34
35 /**
36 * This class is a specialization of {@link MaterialOrMethodEvent} which allows to
37 * specifically store temperature and XXX which are common parameters for preparation.
38 *
39 * {@link #getDefinedMaterialOrMethod() Defined methods} taken to describe a Preservation Method
40 * should be taken from a vocabulary of type {@link TermType#PreservationMethod}
41 *
42 * http://rs.tdwg.org/ontology/voc/Collection.rdf#SpecimenPreservationMethodTypeTerm
43 *
44 * @author a.mueller
45 * @since 2013-09-11
46 */
47 @XmlAccessorType(XmlAccessType.FIELD)
48 @XmlType(name = "PreservationMethod", propOrder = {
49 "medium",
50 "temperature"
51 })
52 @XmlRootElement(name = "PreservationMethod")
53 @Entity
54 //TODO @Indexed(index = "eu.etaxonomy.cdm.model.term.DefinedTermBase")
55 @Audited
56 public class PreservationMethod extends MaterialOrMethodEvent {
57
58 private static final long serialVersionUID = 2366116167028862401L;
59 @SuppressWarnings("unused")
60 private static final Logger logger = LogManager.getLogger();
61
62 @XmlElement(name = "Medium")
63 @XmlIDREF
64 @XmlSchemaType(name = "IDREF")
65 @ManyToOne(fetch = FetchType.LAZY)
66 @IndexedEmbedded // no depth for terms
67 private DefinedTerm medium;
68
69 @XmlElement(name = "Temperature")
70 @Field(analyze = Analyze.NO)
71 @NumericField
72 private Double temperature;
73
74 // ******************** FACTORY METHOD ******************/
75
76 public static PreservationMethod NewInstance(){
77 return new PreservationMethod();
78 }
79
80 public static PreservationMethod NewInstance(DefinedTerm definedMaterialOrMethod, String methodText){
81 return new PreservationMethod(definedMaterialOrMethod, methodText, null, null);
82 }
83
84 public static PreservationMethod NewInstance(DefinedTerm definedMaterialOrMethod, String methodText, DefinedTerm preservationMedium, Double temperature){
85 return new PreservationMethod(definedMaterialOrMethod, methodText, preservationMedium, temperature);
86 }
87
88 // ********************* CONSTRUCTOR ********************/
89
90 //for hibernate use only, *packet* private required by bytebuddy
91 PreservationMethod(){}
92
93 private PreservationMethod(DefinedTerm definedMaterialOrMethod, String methodText, DefinedTerm medium, Double temperature){
94 super(definedMaterialOrMethod, methodText);
95 this.medium = medium;
96 this.temperature = temperature;
97 }
98
99 // ********************* GETTER / SETTER ********************/
100
101 public DefinedTerm getMedium() {
102 return medium;
103 }
104 public void setMedium(DefinedTerm medium) {
105 this.medium = medium;
106 }
107
108 public Double getTemperature() {
109 return temperature;
110 }
111 public void setTemperature(Double temperature) {
112 this.temperature = temperature;
113 }
114
115 // ************************** CLONE ********************/
116
117 /**
118 * Clones <i>this</i> {@link Cloning}. This is a shortcut that enables to create
119 * a new instance that differs only slightly from <i>this</i> cloning by
120 * modifying only some of the attributes.<BR><BR>
121 *
122 * @see EventBase#clone()
123 * @see java.lang.Object#clone()
124 */
125 @Override
126 public PreservationMethod clone() {
127 PreservationMethod result = (PreservationMethod)super.clone();
128
129 //don't change medium, temperature
130 return result;
131 }
132 }