CHANGES TO THE CDMLIB-MODEL: Media and DefinedTermBase become IdentifiableEntity...
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / occurrence / Collection.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.occurrence;
11
12
13 import javax.persistence.Entity;
14 import javax.persistence.FetchType;
15 import javax.persistence.ManyToOne;
16 import javax.xml.bind.annotation.XmlAccessType;
17 import javax.xml.bind.annotation.XmlAccessorType;
18 import javax.xml.bind.annotation.XmlElement;
19 import javax.xml.bind.annotation.XmlIDREF;
20 import javax.xml.bind.annotation.XmlRootElement;
21 import javax.xml.bind.annotation.XmlSchemaType;
22 import javax.xml.bind.annotation.XmlType;
23
24 import org.apache.log4j.Logger;
25 import org.hibernate.annotations.Cascade;
26 import org.hibernate.annotations.CascadeType;
27 import org.hibernate.annotations.Index;
28 import org.hibernate.annotations.Table;
29 import org.hibernate.envers.Audited;
30 import org.hibernate.search.annotations.Field;
31 import org.hibernate.search.annotations.Indexed;
32 import org.hibernate.search.annotations.IndexedEmbedded;
33 import org.springframework.beans.factory.annotation.Configurable;
34
35 import eu.etaxonomy.cdm.model.agent.Institution;
36 import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
37 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
38 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
39
40 /**
41 * @author m.doering
42 * @version 1.0
43 * @created 08-Nov-2007 13:06:16
44 */
45 @XmlAccessorType(XmlAccessType.FIELD)
46 @XmlType(name = "Collection", propOrder = {
47 "name",
48 "code",
49 "codeStandard",
50 "townOrLocation",
51 "institute",
52 "superCollection"
53 })
54 @XmlRootElement(name = "Collection")
55 @Entity
56 @Indexed
57 @Audited
58 @Configurable
59 @Table(appliesTo="Collection", indexes = { @Index(name = "collectionTitleCacheIndex", columnNames = { "titleCache" }) })
60 public class Collection extends IdentifiableMediaEntity<IIdentifiableEntityCacheStrategy<Collection>> implements Cloneable{
61 /**
62 *
63 */
64 private static final long serialVersionUID = -7833674897174732255L;
65
66 private static final Logger logger = Logger.getLogger(Collection.class);
67
68 @XmlElement(name = "Code")
69 @Field(index=org.hibernate.search.annotations.Index.UN_TOKENIZED)
70 private String code;
71
72 @XmlElement(name = "CodeStandard")
73 @Field(index=org.hibernate.search.annotations.Index.UN_TOKENIZED)
74 private String codeStandard;
75
76 @XmlElement(name = "Name")
77 @Field(index=org.hibernate.search.annotations.Index.TOKENIZED)
78 private String name;
79
80 @XmlElement(name = "TownOrLocation")
81 @Field(index=org.hibernate.search.annotations.Index.TOKENIZED)
82 private String townOrLocation;
83
84 @XmlElement(name = "Institution")
85 @XmlIDREF
86 @XmlSchemaType(name = "IDREF")
87 @ManyToOne(fetch = FetchType.LAZY)
88 @Cascade(CascadeType.SAVE_UPDATE)
89 @IndexedEmbedded
90 private Institution institute;
91
92 @XmlElement(name = "SuperCollection")
93 @XmlIDREF
94 @XmlSchemaType(name = "IDREF")
95 @ManyToOne(fetch = FetchType.LAZY)
96 @Cascade(CascadeType.SAVE_UPDATE)
97 private Collection superCollection;
98
99
100 /**
101 * Factory method
102 * @return
103 */
104 public static Collection NewInstance(){
105 return new Collection();
106 }
107
108 /**
109 * Constructor
110 */
111 protected Collection() {
112 super();
113 this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<Collection>();
114 }
115
116 public Institution getInstitute(){
117 return this.institute;
118 }
119
120 /**
121 *
122 * @param institute institute
123 */
124 public void setInstitute(Institution institute){
125 this.institute = institute;
126 }
127
128 public String getCode(){
129 return this.code;
130 }
131
132 /**
133 *
134 * @param code code
135 */
136 public void setCode(String code){
137 this.code = code;
138 }
139
140 public String getCodeStandard(){
141 return this.codeStandard;
142 }
143
144 /**
145 *
146 * @param codeStandard codeStandard
147 */
148 public void setCodeStandard(String codeStandard){
149 this.codeStandard = codeStandard;
150 }
151
152 public String getName(){
153 return this.name;
154 }
155
156 /**
157 *
158 * @param name name
159 */
160 public void setName(String name){
161 this.name = name;
162 }
163
164 public String getTownOrLocation(){
165 return this.townOrLocation;
166 }
167
168 /**
169 *
170 * @param townOrLocation townOrLocation
171 */
172 public void setTownOrLocation(String townOrLocation){
173 this.townOrLocation = townOrLocation;
174 }
175
176 // @Override
177 // public String generateTitle(){
178 // return "";
179 // }
180
181 public Collection getSuperCollection() {
182 return superCollection;
183 }
184
185 public void setSuperCollection(Collection superCollection) {
186 this.superCollection = superCollection;
187 }
188
189
190 //*********** CLONE **********************************/
191
192 /**
193 * Clones <i>this</i> collection. This is a shortcut that enables to
194 * create a new instance that differs only slightly from <i>this</i> collection
195 * by modifying only some of the attributes.<BR>
196 * This method overrides the clone method from {@link IdentifiableMediaEntity IdentifiableMediaEntity}.
197 *
198 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
199 * @see java.lang.Object#clone()
200 */
201 @Override
202 public Collection clone(){
203 try{
204 Collection result = (Collection)super.clone();
205 //superCollection
206 result.setSuperCollection(this.superCollection);
207 //institute
208 result.setInstitute(this.institute);
209 //no changes to: code, codeStandard, name, townOrLocation
210 return result;
211 } catch (CloneNotSupportedException e) {
212 logger.warn("Object does not implement cloneable");
213 e.printStackTrace();
214 return null;
215 }
216 }
217 }