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.Inheritance;
|
14
|
import javax.persistence.InheritanceType;
|
15
|
import javax.persistence.ManyToOne;
|
16
|
import javax.persistence.Transient;
|
17
|
import javax.xml.bind.annotation.XmlAccessType;
|
18
|
import javax.xml.bind.annotation.XmlAccessorType;
|
19
|
import javax.xml.bind.annotation.XmlElement;
|
20
|
import javax.xml.bind.annotation.XmlIDREF;
|
21
|
import javax.xml.bind.annotation.XmlRootElement;
|
22
|
import javax.xml.bind.annotation.XmlSchemaType;
|
23
|
import javax.xml.bind.annotation.XmlType;
|
24
|
|
25
|
import org.apache.logging.log4j.LogManager;
|
26
|
import org.apache.logging.log4j.Logger;
|
27
|
import org.hibernate.envers.Audited;
|
28
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
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
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
35
|
|
36
|
/**
|
37
|
* A material or method event handles data on materials or methods used for handling specimen or derived units
|
38
|
* in general. It stores information on what material or method was used, who used it and when it was used.
|
39
|
* For reusable data on materials or methods it is best practice to define these first as {@link DefinedTerm
|
40
|
* defined terms} of type {@link TermType#MaterialOrMethod} TODO and then use this term as {@link #getDefinedMaterialOrMethod()
|
41
|
* material or method term}. If this is not possible or if additional data needs to be added one may also
|
42
|
* use {@link #getDescription() freetext} field inherited from {@link EventBase}. Actor and Date information
|
43
|
* are also handled via {@link EventBase} fields.
|
44
|
* This class may be extended by more specific classes which require structured handling of additional parameters.
|
45
|
*
|
46
|
* In general material or method data is not considered to be CDM core data. Therefore the decision was made to handle
|
47
|
* all the data with a common base class which is {@link MaterialOrMethodEvent} to reduce the number of tables required
|
48
|
* in the underlying databases.
|
49
|
*
|
50
|
* @author a.mueller
|
51
|
* @since 2013-07-08
|
52
|
*
|
53
|
*/
|
54
|
@XmlAccessorType(XmlAccessType.FIELD)
|
55
|
@XmlType(name = "MaterialOrMethod", propOrder = {
|
56
|
"definedMaterialOrMethod"
|
57
|
})
|
58
|
@XmlRootElement(name = "MaterialOrMethod")
|
59
|
@Entity
|
60
|
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
61
|
@Audited
|
62
|
public class MaterialOrMethodEvent extends EventBase {
|
63
|
|
64
|
private static final long serialVersionUID = -4799205199942053585L;
|
65
|
private static final Logger logger = LogManager.getLogger(MaterialOrMethodEvent.class);
|
66
|
|
67
|
@XmlElement(name = "DefinedMaterialOrMethod")
|
68
|
@XmlIDREF
|
69
|
@XmlSchemaType(name = "IDREF")
|
70
|
@ManyToOne(fetch=FetchType.LAZY)
|
71
|
@IndexedEmbedded // no depth for terms
|
72
|
private DefinedTerm definedMaterialOrMethod;
|
73
|
|
74
|
//TODO citation / link
|
75
|
|
76
|
// ******************** FACTORY METHOD ******************/
|
77
|
|
78
|
public static MaterialOrMethodEvent NewInstance(){
|
79
|
return new MaterialOrMethodEvent();
|
80
|
}
|
81
|
|
82
|
public static MaterialOrMethodEvent NewInstance(DefinedTerm definedMaterialOrMethod, String methodText){
|
83
|
return new MaterialOrMethodEvent(definedMaterialOrMethod, methodText);
|
84
|
}
|
85
|
|
86
|
// ********************* CONSTRUCTOR ********************/
|
87
|
|
88
|
//for hibernate use only, protected required by subclasses
|
89
|
protected MaterialOrMethodEvent(){}
|
90
|
|
91
|
protected MaterialOrMethodEvent(DefinedTerm definedMaterialOrMethod, String methodText){
|
92
|
this.definedMaterialOrMethod = definedMaterialOrMethod;
|
93
|
this.setDescription(methodText);
|
94
|
}
|
95
|
|
96
|
// ********************* GETTER / SETTER ********************/
|
97
|
|
98
|
/**
|
99
|
* The {@link #getDescription()} method is inherited from {@link EventBase}.
|
100
|
* In this class it is used as freetext describing the material or method used
|
101
|
* or if a {@link #getDefinedMaterialOrMethod() defined method} is given as
|
102
|
* an additional information about how this defined method was used.
|
103
|
*
|
104
|
* @see #getMaterialMethodText()
|
105
|
*/
|
106
|
@Override
|
107
|
public String getDescription() {
|
108
|
return super.getDescription();
|
109
|
}
|
110
|
|
111
|
|
112
|
/**
|
113
|
* @see #getDescription()
|
114
|
* @see #setMaterialMethodText(String)
|
115
|
*/
|
116
|
@Override
|
117
|
public void setDescription(String materialMethodText) {
|
118
|
super.setDescription(materialMethodText);
|
119
|
}
|
120
|
|
121
|
|
122
|
|
123
|
/**
|
124
|
* A freetext describing the material or method or if
|
125
|
* a {@link #getDefinedMaterialOrMethod() defined method} is given
|
126
|
* an additional information about how this method was used.
|
127
|
* In future this method could be removed to decrease the number
|
128
|
* of transient getters in the CDM.
|
129
|
*/
|
130
|
@Transient
|
131
|
public String getMaterialMethodText() {
|
132
|
return this.getDescription();
|
133
|
}
|
134
|
|
135
|
|
136
|
/**
|
137
|
* @see #getMaterialMethodText()
|
138
|
*/
|
139
|
public void setMaterialMethodText(String materialMethodText) {
|
140
|
this.setDescription(materialMethodText);
|
141
|
}
|
142
|
|
143
|
|
144
|
/**
|
145
|
* A defined material or method given as a defined term in a materialOrMethod
|
146
|
* {@link TermVocabulary term vocabulary}. If such a defined material or method is used
|
147
|
* the {@link #getDescription() description} should primarily focus on describing
|
148
|
* deviation from this method rather then repeating it.
|
149
|
*
|
150
|
* @see #getDescription()
|
151
|
* @see #getMaterialMethodText()
|
152
|
* @return the material or method term
|
153
|
*/
|
154
|
public DefinedTerm getDefinedMaterialOrMethod() {
|
155
|
return definedMaterialOrMethod;
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* @see #getDefinedMaterialOrMethod()
|
160
|
* @param materialMethodTerm
|
161
|
*/
|
162
|
public void setDefinedMaterialOrMethod(DefinedTerm definedMaterialOrMethod) {
|
163
|
this.definedMaterialOrMethod = definedMaterialOrMethod;
|
164
|
}
|
165
|
|
166
|
// ********************* CLONE ********************/
|
167
|
/**
|
168
|
* Clones <i>this</i> {@link Cloning}. This is a shortcut that enables to create
|
169
|
* a new instance that differs only slightly from <i>this</i> cloning by
|
170
|
* modifying only some of the attributes.<BR><BR>
|
171
|
*
|
172
|
* @see EventBase#clone()
|
173
|
* @see java.lang.Object#clone()
|
174
|
*/
|
175
|
@Override
|
176
|
public MaterialOrMethodEvent clone() {
|
177
|
try{
|
178
|
MaterialOrMethodEvent result = (MaterialOrMethodEvent)super.clone();
|
179
|
|
180
|
//don't change materialMethodTerm
|
181
|
return result;
|
182
|
}catch (CloneNotSupportedException e) {
|
183
|
logger.warn("Object does not implement cloneable");
|
184
|
e.printStackTrace();
|
185
|
return null;
|
186
|
}
|
187
|
}
|
188
|
}
|