Project

General

Profile

Download (6.07 KB) Statistics
| Branch: | Tag: | Revision:
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.commons.lang.StringUtils;
31
import org.apache.log4j.Logger;
32
import org.hibernate.annotations.Cascade;
33
import org.hibernate.annotations.CascadeType;
34
import org.hibernate.envers.Audited;
35
import org.hibernate.search.annotations.Field;
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 disabled to reduce clutter in indexes, since this type is not used by any search
66
//@Indexed(index = "eu.etaxonomy.cdm.model.agent.AgentBase")
67
@Audited
68
@Configurable
69
public class Institution extends AgentBase<IIdentifiableEntityCacheStrategy<Institution>> {
70
	private static final long serialVersionUID = -951321271656955808L;
71
	public static final Logger logger = Logger.getLogger(Institution.class);
72

    
73
    @XmlElement(name = "Code")
74
    @Field
75
    //TODO Val #3379
76
//    @NullOrNotEmpty
77
    @Column(length=255)
78
	private String code;
79

    
80
    @XmlElement(name = "Name")
81
    @Field
82
//TODO Val #3379
83
//    @NullOrNotEmpty
84
    @Column(length=255)
85
	private String name;
86

    
87
    @XmlElementWrapper(name = "Types", nillable = true)
88
    @XmlElement(name = "Type")
89
    @XmlIDREF
90
    @XmlSchemaType(name = "IDREF")
91
    @ManyToMany(fetch = FetchType.LAZY)
92
	private Set<DefinedTerm> types;  //InstitutionTypes
93

    
94
    @XmlElement(name = "IsPartOf")
95
    @XmlIDREF
96
    @XmlSchemaType(name = "IDREF")
97
    @ManyToOne(fetch = FetchType.LAZY)
98
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
99
	private Institution isPartOf;
100

    
101
	/**
102
	 * Creates a new empty institution instance.
103
	 */
104
	public static Institution NewInstance(){
105
		return new Institution();
106
	}
107

    
108

    
109
	/**
110
	 * Class constructor.
111
	 */
112
	protected Institution() {
113
		super();
114
		this.cacheStrategy = new InstitutionDefaultCacheStrategy();
115
	}
116

    
117
	/**
118
	 * Returns the set of institution types (categories)
119
	 * used to describe or circumscribe <i>this</i> institution's activities.
120
	 * Institution types are items of a controlled {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary}.
121
	 *
122
	 * @return	the set of institution types
123
	 */
124
	public Set<DefinedTerm> getTypes(){
125
		if(types == null) {
126
			this.types = new HashSet<DefinedTerm>();
127
		}
128
		return this.types;
129
	}
130

    
131
	/**
132
	 * Adds a new institutional type (from the corresponding {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary})
133
	 * to the set of institution types of <i>this</i> institution.
134
	 *
135
	 * @param  t  any type of institution
136
	 * @see 	  #getTypes()
137
	 */
138
	public void addType(DefinedTerm type){
139
		getTypes().add(type);
140
	}
141

    
142
	/**
143
	 * Removes one element from the set of institution types for <i>this</i> institution.
144
	 *
145
	 * @param  t  the institution type which should be deleted
146
	 * @see       #getTypes()
147
	 */
148
	public void removeType(DefinedTerm type){
149
		getTypes().remove(type);
150
	}
151

    
152
	/**
153
	 * Returns the parent institution of this institution.
154
	 * This is for instance the case when this institution is a herbarium
155
	 * belonging to a parent institution such as a museum.
156
	 */
157
	public Institution getIsPartOf(){
158
		return this.isPartOf;
159
	}
160

    
161
	/**
162
	 * Assigns a parent institution to which this institution belongs.
163
	 *
164
	 * @param  isPartOf  the parent institution
165
	 * @see	   #getIsPartOf()
166
	 */
167
	public void setIsPartOf(Institution parentInstitution){
168
		this.isPartOf = parentInstitution;
169
	}
170

    
171
	/**
172
	 * Returns the string representing the code (can also be an acronym or initials)
173
	 * by which this institution is known among experts.
174
	 */
175
	public String getCode(){
176
		return this.code;
177
	}
178
	/**
179
	 * @see	   #getCode()
180
	 */
181
	public void setCode(String code){
182
		this.code = StringUtils.isBlank(code) ? null : code;
183
	}
184

    
185

    
186
	/**
187
	 * Returns the full name, as distinct from a code, an acronym or initials,
188
	 * by which this institution is generally known.
189
	 */
190
	public String getName(){
191
		return this.name;
192
	}
193
	/**
194
	 * @see	   #getName()
195
	 */
196
	public void setName(String name){
197
		this.name = StringUtils.isBlank(name) ? null: name;
198
	}
199

    
200
//*********************** CLONE ********************************************************/
201

    
202
	/**
203
	 * Clones <i>this</i> Institution. This is a shortcut that enables to create
204
	 * a new instance that differs only slightly from <i>this</i> Institution.
205
	 *
206
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity
207
	 * @see java.lang.Object#clone()
208
	 */
209
	@Override
210
	public Object clone() {
211
		try{
212
			Institution result = (Institution) super.clone();
213
			//no changes to code, isPartOf, name, types
214
			return result;
215
		}catch (CloneNotSupportedException e){
216
			logger.warn("Object does not implement cloneable");
217
			e.printStackTrace();
218
			return null;
219
		}
220
	}
221
}
(5-5/11)