Intensive model change for referenceBase and subclass, smaller model changes for...
[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 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.xml.bind.annotation.XmlAccessType;
21 import javax.xml.bind.annotation.XmlAccessorType;
22 import javax.xml.bind.annotation.XmlElement;
23 import javax.xml.bind.annotation.XmlElementWrapper;
24 import javax.xml.bind.annotation.XmlIDREF;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlSchemaType;
27 import javax.xml.bind.annotation.XmlType;
28
29 import org.apache.log4j.Logger;
30 import org.hibernate.annotations.Cascade;
31 import org.hibernate.annotations.CascadeType;
32 import org.hibernate.envers.Audited;
33 import org.hibernate.search.annotations.Field;
34 import org.hibernate.search.annotations.Index;
35 import org.hibernate.search.annotations.Indexed;
36 import org.springframework.beans.factory.annotation.Configurable;
37
38 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
39 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
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 * @version 1.0
53 * @created 08-Nov-2007 13:06:29
54 */
55 @XmlAccessorType(XmlAccessType.FIELD)
56 @XmlType(name = "Institution", propOrder = {
57 "code",
58 "name",
59 "types",
60 "isPartOf"
61 })
62 @XmlRootElement(name = "Institution")
63 @Entity
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(index=Index.TOKENIZED)
73 private String code;
74
75 @XmlElement(name = "Name")
76 @Field(index=Index.TOKENIZED)
77 private String name;
78
79 @XmlElementWrapper(name = "Types")
80 @XmlElement(name = "Type")
81 @XmlIDREF
82 @XmlSchemaType(name = "IDREF")
83 @ManyToMany(fetch = FetchType.LAZY)
84 private Set<InstitutionType> types = new HashSet<InstitutionType>();
85
86 @XmlElement(name = "IsPartOf")
87 @XmlIDREF
88 @XmlSchemaType(name = "IDREF")
89 @ManyToOne(fetch = FetchType.LAZY)
90 @Cascade(CascadeType.SAVE_UPDATE)
91 private Institution isPartOf;
92
93 /**
94 * Creates a new empty institution instance.
95 */
96 public static Institution NewInstance(){
97 return new Institution();
98 }
99
100
101 /**
102 * Class constructor.
103 */
104 public Institution() {
105 super();
106 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Institution>();
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 public Set<InstitutionType> getTypes(){
118 return this.types;
119 }
120
121 /**
122 * Adds a new institutional type (from the corresponding {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary})
123 * to the set of institution types of <i>this</i> institution.
124 *
125 * @param t any type of institution
126 * @see #getTypes()
127 * @see InstitutionType
128 */
129 public void addType(InstitutionType t){
130 this.types.add(t);
131 }
132
133 /**
134 * Removes one element from the set of institution types for <i>this</i> institution.
135 *
136 * @param t the institution type which should be deleted
137 * @see #getTypes()
138 */
139 public void removeType(InstitutionType t){
140 this.types.remove(t);
141 }
142
143 /**
144 * Returns the parent institution of this institution.
145 * This is for instance the case when this institution is a herbarium
146 * belonging to a parent institution such as a museum.
147 */
148 public Institution getIsPartOf(){
149 return this.isPartOf;
150 }
151
152 /**
153 * Assigns a parent institution to which this institution belongs.
154 *
155 * @param isPartOf the parent institution
156 * @see #getIsPartOf()
157 */
158 public void setIsPartOf(Institution isPartOf){
159 this.isPartOf = isPartOf;
160 }
161
162 /**
163 * Returns the string representing the code (can also be an acronym or initials)
164 * by which this institution is known among experts.
165 */
166 public String getCode(){
167 return this.code;
168 }
169 /**
170 * @see #getCode()
171 */
172 public void setCode(String code){
173 this.code = code;
174 }
175
176
177 /**
178 * Returns the full name, as distinct from a code, an acronym or initials,
179 * by which this institution is generally known.
180 */
181 public String getName(){
182 return this.name;
183 }
184 /**
185 * @see #getName()
186 */
187 public void setName(String name){
188 this.name = name;
189 }
190 }