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