Major changes to the cdmlib default term loading and initialization, plus indexing...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / agent / Institution.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
10 package eu.etaxonomy.cdm.model.agent;
11
12
13 import org.apache.log4j.Logger;
14 import org.hibernate.annotations.Cascade;
15 import org.hibernate.annotations.CascadeType;
16
17 import java.util.*;
18 import javax.persistence.*;
19 import javax.xml.bind.annotation.XmlAccessType;
20 import javax.xml.bind.annotation.XmlAccessorType;
21 import javax.xml.bind.annotation.XmlElement;
22 import javax.xml.bind.annotation.XmlElementWrapper;
23 import javax.xml.bind.annotation.XmlIDREF;
24 import javax.xml.bind.annotation.XmlRootElement;
25 import javax.xml.bind.annotation.XmlSchemaType;
26 import javax.xml.bind.annotation.XmlType;
27
28 /**
29 * This class represents public or private institutions.
30 * It includes name, contact details and institution type.
31 * <P>
32 * This class corresponds to: <ul>
33 * <li> Institution according to the TDWG ontology
34 * <li> Institution according to the TCS
35 * <li> Organisation (Institution) according to the ABCD schema
36 * </ul>
37 *
38 * @author m.doering
39 * @version 1.0
40 * @created 08-Nov-2007 13:06:29
41 */
42 @XmlAccessorType(XmlAccessType.FIELD)
43 @XmlType(name = "Institution", propOrder = {
44 "code",
45 "name",
46 "types",
47 "isPartOf",
48 "contact"
49 })
50 @XmlRootElement(name = "Institution")
51 @Entity
52 //@Audited
53 public class Institution extends Agent {
54 private static final long serialVersionUID = -951321271656955808L;
55 public static final Logger logger = Logger.getLogger(Institution.class);
56
57 @XmlElement(name = "Code")
58 private String code;
59
60 @XmlElement(name = "Name")
61 private String name;
62
63 @XmlElementWrapper(name = "Types")
64 @XmlElement(name = "Type")
65 //@XmlIDREF
66 //@XmlSchemaType(name = "IDREF")
67 private Set<InstitutionType> types = new HashSet<InstitutionType>();
68
69 @XmlElement(name = "IsPartOf")
70 @XmlIDREF
71 @XmlSchemaType(name = "IDREF")
72 private Institution isPartOf;
73
74 @XmlElement(name = "Contact")
75 private Contact contact;
76
77 /**
78 * Creates a new empty institution instance.
79 */
80 public static Institution NewInstance(){
81 return new Institution();
82 }
83
84
85 /**
86 * Class constructor.
87 */
88 public Institution() {
89 super();
90 }
91
92 /**
93 * Returns the {@link Contact contact} corresponding to <i>this</i> institution.
94 * It includes telecommunication data
95 * and electronic as well as multiple postal addresses.
96 */
97 @ManyToOne
98 @Cascade({CascadeType.SAVE_UPDATE})
99 public Contact getContact(){
100 return this.contact;
101 }
102 /**
103 * @see #getContact()
104 */
105 public void setContact(Contact contact){
106 this.contact = contact;
107 }
108
109 /**
110 * Returns the set of institution {@link InstitutionType types} (categories)
111 * used to describe or circumscribe <i>this</i> institution's activities.
112 * Institution types are items of a controlled {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary}.
113 *
114 * @return the set of institution types
115 * @see InstitutionType
116 */
117 @ManyToMany(fetch = FetchType.LAZY)
118 public Set<InstitutionType> getTypes(){
119 return this.types;
120 }
121
122 /**
123 * Adds a new institutional type (from the corresponding {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary})
124 * to the set of institution types of <i>this</i> institution.
125 *
126 * @param t any type of institution
127 * @see #getTypes()
128 * @see InstitutionType
129 */
130 public void addType(InstitutionType t){
131 this.types.add(t);
132 }
133
134 /**
135 * Removes one element from the set of institution types for <i>this</i> institution.
136 *
137 * @param t the institution type which should be deleted
138 * @see #getTypes()
139 */
140 public void removeType(InstitutionType t){
141 this.types.remove(t);
142 }
143 /**
144 * @see #getTypes()
145 */
146 protected void setTypes(Set<InstitutionType> types){
147 this.types = types;
148 }
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 @ManyToOne
157 @Cascade({CascadeType.SAVE_UPDATE})
158 public Institution getIsPartOf(){
159 return this.isPartOf;
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 isPartOf){
168 this.isPartOf = isPartOf;
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 = 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 = name;
198 }
199
200 /**
201 * Generates the identification string for this institution.
202 * The string is based on its name and code as well as on the name and code of
203 * its parent institution, if existing.
204 * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
205 * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
206 * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
207 *
208 * @return the identification string
209 */
210 @Override
211 public String generateTitle(){
212 return "";
213 }
214
215 }