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.agent;
|
11
|
|
12
|
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Set;
|
15
|
|
16
|
import javax.persistence.Column;
|
17
|
import javax.persistence.Entity;
|
18
|
import javax.persistence.FetchType;
|
19
|
import javax.persistence.ManyToMany;
|
20
|
import javax.persistence.ManyToOne;
|
21
|
import javax.xml.bind.annotation.XmlAccessType;
|
22
|
import javax.xml.bind.annotation.XmlAccessorType;
|
23
|
import javax.xml.bind.annotation.XmlElement;
|
24
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
25
|
import javax.xml.bind.annotation.XmlIDREF;
|
26
|
import javax.xml.bind.annotation.XmlRootElement;
|
27
|
import javax.xml.bind.annotation.XmlSchemaType;
|
28
|
import javax.xml.bind.annotation.XmlType;
|
29
|
|
30
|
import org.apache.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.Field;
|
35
|
import org.springframework.beans.factory.annotation.Configurable;
|
36
|
|
37
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
38
|
import eu.etaxonomy.cdm.strategy.cache.agent.InstitutionDefaultCacheStrategy;
|
39
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
40
|
|
41
|
/**
|
42
|
* This class represents public or private institutions.
|
43
|
* It includes name, contact details and institution type.
|
44
|
* <P>
|
45
|
* This class corresponds to: <ul>
|
46
|
* <li> Institution according to the TDWG ontology
|
47
|
* <li> Institution according to the TCS
|
48
|
* <li> Organisation (Institution) according to the ABCD schema
|
49
|
* </ul>
|
50
|
*
|
51
|
* @author m.doering
|
52
|
* @since 08-Nov-2007 13:06:29
|
53
|
*/
|
54
|
@XmlAccessorType(XmlAccessType.FIELD)
|
55
|
@XmlType(name = "Institution", propOrder = {
|
56
|
"code",
|
57
|
"name",
|
58
|
"types",
|
59
|
"isPartOf"
|
60
|
})
|
61
|
@XmlRootElement(name = "Institution")
|
62
|
@Entity
|
63
|
// @Indexed disabled to reduce clutter in indexes, since this type is not used by any search
|
64
|
//@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
|
65
|
@Audited
|
66
|
@Configurable
|
67
|
public class Institution extends AgentBase<IIdentifiableEntityCacheStrategy<Institution>> {
|
68
|
private static final long serialVersionUID = -951321271656955808L;
|
69
|
public static final Logger logger = Logger.getLogger(Institution.class);
|
70
|
|
71
|
@XmlElement(name = "Code")
|
72
|
@Field
|
73
|
//TODO Val #3379
|
74
|
// @NullOrNotEmpty
|
75
|
@Column(length=255)
|
76
|
private String code;
|
77
|
|
78
|
@XmlElement(name = "Name")
|
79
|
@Field
|
80
|
//TODO Val #3379
|
81
|
// @NullOrNotEmpty
|
82
|
@Column(length=255)
|
83
|
private String name;
|
84
|
|
85
|
@XmlElementWrapper(name = "Types", nillable = true)
|
86
|
@XmlElement(name = "Type")
|
87
|
@XmlIDREF
|
88
|
@XmlSchemaType(name = "IDREF")
|
89
|
@ManyToMany(fetch = FetchType.LAZY)
|
90
|
private Set<DefinedTerm> types; //InstitutionTypes
|
91
|
|
92
|
@XmlElement(name = "IsPartOf")
|
93
|
@XmlIDREF
|
94
|
@XmlSchemaType(name = "IDREF")
|
95
|
@ManyToOne(fetch = FetchType.LAZY)
|
96
|
@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
|
97
|
private Institution isPartOf;
|
98
|
|
99
|
/**
|
100
|
* Creates a new empty institution instance.
|
101
|
*/
|
102
|
public static Institution NewInstance(){
|
103
|
return new Institution();
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Creates a new empty institution instance.
|
108
|
*/
|
109
|
public static Institution NewNamedInstance(String name){
|
110
|
Institution result = new Institution();
|
111
|
result.setName(name);
|
112
|
return result;
|
113
|
}
|
114
|
|
115
|
//******************* CONSTRUCTOR ***********************/
|
116
|
|
117
|
/**
|
118
|
* Class constructor.
|
119
|
*/
|
120
|
protected Institution() {
|
121
|
super();
|
122
|
}
|
123
|
|
124
|
@Override
|
125
|
protected void initDefaultCacheStrategy() {
|
126
|
this.cacheStrategy = InstitutionDefaultCacheStrategy.NewInstance();
|
127
|
}
|
128
|
|
129
|
//*************** Methods ******************************/
|
130
|
|
131
|
/**
|
132
|
* Returns the set of institution types (categories)
|
133
|
* used to describe or circumscribe <i>this</i> institution's activities.
|
134
|
* Institution types are items of a controlled {@link eu.etaxonomy.cdm.model.term.TermVocabulary vocabulary}.
|
135
|
*
|
136
|
* @return the set of institution types
|
137
|
*/
|
138
|
public Set<DefinedTerm> getTypes(){
|
139
|
if(types == null) {
|
140
|
this.types = new HashSet<>();
|
141
|
}
|
142
|
return this.types;
|
143
|
}
|
144
|
|
145
|
/**
|
146
|
* Adds a new institutional type (from the corresponding {@link eu.etaxonomy.cdm.model.term.TermVocabulary vocabulary})
|
147
|
* to the set of institution types of <i>this</i> institution.
|
148
|
*
|
149
|
* @param t any type of institution
|
150
|
* @see #getTypes()
|
151
|
*/
|
152
|
public void addType(DefinedTerm type){
|
153
|
getTypes().add(type);
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Removes one element from the set of institution types for <i>this</i> institution.
|
158
|
*
|
159
|
* @param t the institution type which should be deleted
|
160
|
* @see #getTypes()
|
161
|
*/
|
162
|
public void removeType(DefinedTerm type){
|
163
|
getTypes().remove(type);
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* Returns the parent institution of this institution.
|
168
|
* This is for instance the case when this institution is a herbarium
|
169
|
* belonging to a parent institution such as a museum.
|
170
|
*/
|
171
|
public Institution getIsPartOf(){
|
172
|
return this.isPartOf;
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* Assigns a parent institution to which this institution belongs.
|
177
|
*
|
178
|
* @param isPartOf the parent institution
|
179
|
* @see #getIsPartOf()
|
180
|
*/
|
181
|
public void setIsPartOf(Institution parentInstitution){
|
182
|
this.isPartOf = parentInstitution;
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* Returns the string representing the code (can also be an acronym or initials)
|
187
|
* by which this institution is known among experts.
|
188
|
*/
|
189
|
public String getCode(){
|
190
|
return this.code;
|
191
|
}
|
192
|
/**
|
193
|
* @see #getCode()
|
194
|
*/
|
195
|
public void setCode(String code){
|
196
|
this.code = isBlank(code) ? null : code;
|
197
|
}
|
198
|
|
199
|
|
200
|
/**
|
201
|
* Returns the full name, as distinct from a code, an acronym or initials,
|
202
|
* by which this institution is generally known.
|
203
|
*/
|
204
|
public String getName(){
|
205
|
return this.name;
|
206
|
}
|
207
|
/**
|
208
|
* @see #getName()
|
209
|
*/
|
210
|
public void setName(String name){
|
211
|
this.name = isBlank(name) ? null: name;
|
212
|
}
|
213
|
|
214
|
//*********************** CLONE ********************************************************/
|
215
|
|
216
|
/**
|
217
|
* Clones <i>this</i> Institution. This is a shortcut that enables to create
|
218
|
* a new instance that differs only slightly from <i>this</i> Institution.
|
219
|
*
|
220
|
* @see java.lang.Object#clone()
|
221
|
*/
|
222
|
@Override
|
223
|
public Institution clone() {
|
224
|
try{
|
225
|
Institution result = (Institution) super.clone();
|
226
|
//no changes to code, isPartOf, name, types
|
227
|
return result;
|
228
|
}catch (CloneNotSupportedException e){
|
229
|
logger.warn("Object does not implement cloneable");
|
230
|
e.printStackTrace();
|
231
|
return null;
|
232
|
}
|
233
|
}
|
234
|
}
|