Added Cascade.MERGE for some, not all relationships where Cascade.SAVE_UPDATE exists...
[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.persistence.Transient;
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.XmlTransient;
29 import javax.xml.bind.annotation.XmlType;
30
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.hibernate.search.annotations.Index;
37 import org.hibernate.search.annotations.Indexed;
38 import org.springframework.beans.factory.annotation.Configurable;
39
40 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
41 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
42
43 /**
44 * This class represents public or private institutions.
45 * It includes name, contact details and institution type.
46 * <P>
47 * This class corresponds to: <ul>
48 * <li> Institution according to the TDWG ontology
49 * <li> Institution according to the TCS
50 * <li> Organisation (Institution) according to the ABCD schema
51 * </ul>
52 *
53 * @author m.doering
54 * @version 1.0
55 * @created 08-Nov-2007 13:06:29
56 */
57 @XmlAccessorType(XmlAccessType.FIELD)
58 @XmlType(name = "Institution", propOrder = {
59 "code",
60 "name",
61 "types",
62 "isPartOf"
63 })
64 @XmlRootElement(name = "Institution")
65 @Entity
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(index=Index.TOKENIZED)
75 private String code;
76
77 @XmlElement(name = "Name")
78 @Field(index=Index.TOKENIZED)
79 private String name;
80
81 @XmlElementWrapper(name = "Types")
82 @XmlElement(name = "Type")
83 @XmlIDREF
84 @XmlSchemaType(name = "IDREF")
85 @ManyToMany(fetch = FetchType.LAZY)
86 private Set<InstitutionType> types = new HashSet<InstitutionType>();
87
88 @XmlElement(name = "IsPartOf")
89 @XmlIDREF
90 @XmlSchemaType(name = "IDREF")
91 @ManyToOne(fetch = FetchType.LAZY)
92 @Cascade(CascadeType.SAVE_UPDATE)
93 private Institution isPartOf;
94
95 /**
96 * Creates a new empty institution instance.
97 */
98 public static Institution NewInstance(){
99 return new Institution();
100 }
101
102
103 /**
104 * Class constructor.
105 */
106 public Institution() {
107 super();
108 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Institution>();
109 }
110
111 /**
112 * Returns the set of institution {@link InstitutionType types} (categories)
113 * used to describe or circumscribe <i>this</i> institution's activities.
114 * Institution types are items of a controlled {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary}.
115 *
116 * @return the set of institution types
117 * @see InstitutionType
118 */
119 public Set<InstitutionType> getTypes(){
120 return this.types;
121 }
122
123 /**
124 * Adds a new institutional type (from the corresponding {@link eu.etaxonomy.cdm.model.common.TermVocabulary vocabulary})
125 * to the set of institution types of <i>this</i> institution.
126 *
127 * @param t any type of institution
128 * @see #getTypes()
129 * @see InstitutionType
130 */
131 public void addType(InstitutionType t){
132 this.types.add(t);
133 }
134
135 /**
136 * Removes one element from the set of institution types for <i>this</i> institution.
137 *
138 * @param t the institution type which should be deleted
139 * @see #getTypes()
140 */
141 public void removeType(InstitutionType t){
142 this.types.remove(t);
143 }
144
145 /**
146 * Returns the parent institution of this institution.
147 * This is for instance the case when this institution is a herbarium
148 * belonging to a parent institution such as a museum.
149 */
150 public Institution getIsPartOf(){
151 return this.isPartOf;
152 }
153
154 /**
155 * Assigns a parent institution to which this institution belongs.
156 *
157 * @param isPartOf the parent institution
158 * @see #getIsPartOf()
159 */
160 public void setIsPartOf(Institution isPartOf){
161 this.isPartOf = isPartOf;
162 }
163
164 /**
165 * Returns the string representing the code (can also be an acronym or initials)
166 * by which this institution is known among experts.
167 */
168 public String getCode(){
169 return this.code;
170 }
171 /**
172 * @see #getCode()
173 */
174 public void setCode(String code){
175 this.code = code;
176 }
177
178
179 /**
180 * Returns the full name, as distinct from a code, an acronym or initials,
181 * by which this institution is generally known.
182 */
183 public String getName(){
184 return this.name;
185 }
186 /**
187 * @see #getName()
188 */
189 public void setName(String name){
190 this.name = name;
191 }
192 }