Project

General

Profile

Download (7.39 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.model.occurrence;
12

    
13

    
14
import javax.persistence.Column;
15
import javax.persistence.Entity;
16
import javax.persistence.FetchType;
17
import javax.persistence.ManyToOne;
18
import javax.xml.bind.annotation.XmlAccessType;
19
import javax.xml.bind.annotation.XmlAccessorType;
20
import javax.xml.bind.annotation.XmlElement;
21
import javax.xml.bind.annotation.XmlIDREF;
22
import javax.xml.bind.annotation.XmlRootElement;
23
import javax.xml.bind.annotation.XmlSchemaType;
24
import javax.xml.bind.annotation.XmlType;
25

    
26
import org.apache.commons.lang.StringUtils;
27
import org.apache.log4j.Logger;
28
import org.hibernate.annotations.Cascade;
29
import org.hibernate.annotations.CascadeType;
30
import org.hibernate.annotations.Table;
31
import org.hibernate.envers.Audited;
32
import org.hibernate.search.annotations.Analyze;
33
import org.hibernate.search.annotations.Field;
34
import org.hibernate.search.annotations.IndexedEmbedded;
35
import org.springframework.beans.factory.annotation.Configurable;
36

    
37
import eu.etaxonomy.cdm.common.CdmUtils;
38
import eu.etaxonomy.cdm.model.agent.Institution;
39
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
40
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
41
import eu.etaxonomy.cdm.strategy.cache.occurrence.CollectionDefaultCacheStrategy;
42

    
43
/**
44
 * Instances of this class represent a collection for primary biodiversity data.
45
 * Collections may be part of other collections and may belong to an institution.
46
 * Collection inherits from
47
 *
48
 * @author m.doering
49
 * @created 08-Nov-2007 13:06:16
50
 */
51
@XmlAccessorType(XmlAccessType.FIELD)
52
@XmlType(name = "Collection", propOrder = {
53
	"name",
54
    "code",
55
    "codeStandard",
56
    "townOrLocation",
57
    "institute",
58
    "superCollection"
59
})
60
@XmlRootElement(name = "Collection")
61
@Entity
62
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
63
//@Indexed(index = "eu.etaxonomy.cdm.model.occurrence.Collection")
64
@Audited
65
@Configurable
66
@Table(appliesTo="Collection", indexes = { @org.hibernate.annotations.Index(name = "collectionTitleCacheIndex", columnNames = { "titleCache" }) })
67
public class Collection extends IdentifiableMediaEntity<IIdentifiableEntityCacheStrategy<Collection>> implements Cloneable{
68
	private static final long serialVersionUID = -7833674897174732255L;
69
	private static final Logger logger = Logger.getLogger(Collection.class);
70

    
71
	@XmlElement(name = "Code")
72
	@Field(analyze = Analyze.NO)
73
    //TODO Val #3379
74
//	@NullOrNotEmpty
75
	@Column(length=255)
76
	private String code;
77

    
78
	@XmlElement(name = "CodeStandard")
79
	@Field(analyze = Analyze.NO)
80
    //TODO Val #3379
81
//	@NullOrNotEmpty
82
	@Column(length=255)
83
	private String codeStandard;
84

    
85
	@XmlElement(name = "Name")
86
	@Field
87
    //TODO Val #3379
88
//	@NullOrNotEmpty
89
	@Column(length=255)
90
	private String name;
91

    
92
	@XmlElement(name = "TownOrLocation")
93
	@Field
94
    //TODO Val #3379
95
//	@NullOrNotEmpty
96
	@Column(length=255)
97
	private String townOrLocation;
98

    
99
	@XmlElement(name = "Institution")
100
	@XmlIDREF
101
	@XmlSchemaType(name = "IDREF")
102
	@ManyToOne(fetch = FetchType.LAZY)
103
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
104
	@IndexedEmbedded
105
	private Institution institute;
106

    
107
	@XmlElement(name = "SuperCollection")
108
	@XmlIDREF
109
	@XmlSchemaType(name = "IDREF")
110
	@ManyToOne(fetch = FetchType.LAZY)
111
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
112
	private Collection superCollection;
113

    
114
// ************** FACTORY METHODS *************************/
115

    
116
	/**
117
	 * Factory method
118
	 * @return
119
	 */
120
	public static Collection NewInstance(){
121
		return new Collection();
122
	}
123

    
124
// ******************** CONSTRUCTOR *************************/
125

    
126
	/**
127
	 * Constructor
128
	 */
129
	protected Collection() {
130
		super();
131
		this.cacheStrategy = new CollectionDefaultCacheStrategy();
132
	}
133

    
134
// ******************* GETTER / SETTER ************************/
135

    
136

    
137

    
138
	/**
139
	 * The {@link Institution institution} this collection belongs to.
140
	 * @see #getSuperCollection()
141
	 * @return the institute
142
	 */
143
	public Institution getInstitute(){
144
		return this.institute;
145
	}
146

    
147
	/**
148
	 * @see #getInstitute()
149
	 * @param institute    institute
150
	 */
151
	public void setInstitute(Institution institute){
152
		this.institute = institute;
153
	}
154

    
155
	/**
156
	 * The code for this collection. The standard this code belongs to
157
	 * is given by the {@link #getCodeStandard() code standard}.
158
	 * The code is NOT the {@link #getName()name} of the collection.
159
	 *
160
	 * @see #getCodeStandard()
161
	 * @see #getName()
162
	 * @return the code
163
	 */
164
	public String getCode(){
165
		return this.code;
166
	}
167

    
168
	/**
169
	 * @see #getCode()
170
	 * @param code the code
171
	 */
172
	public void setCode(String code){
173
		this.code = StringUtils.isBlank(code)? null : code;
174
	}
175

    
176
	/**
177
	 * The standard used for the given {@link #getCode() collection code}
178
	 * @return the code standard
179
	 */
180
	public String getCodeStandard(){
181
		return this.codeStandard;
182
	}
183

    
184
	/**
185
	 * @see #getCodeStandard()
186
	 * @see #getCode()
187
	 * @param codeStandard    codeStandard
188
	 */
189
	public void setCodeStandard(String codeStandard){
190
		this.codeStandard = StringUtils.isBlank(codeStandard)? null : codeStandard;
191
	}
192

    
193
	/**
194
	 * The name of this collection
195
	 * @return the name
196
	 */
197
	public String getName(){
198
		return this.name;
199
	}
200

    
201
	/**
202
	 * @see #getName()
203
	 * @param name    name
204
	 */
205
	public void setName(String name){
206
		this.name = StringUtils.isBlank(name)? null : name;
207
	}
208

    
209
	/**
210
	 * The town or location where this collection is to be found.
211
	 * @return the town or location
212
	 */
213
	public String getTownOrLocation(){
214
		return this.townOrLocation;
215
	}
216

    
217
	/**
218
	 * @see #getTownOrLocation
219
	 * @param townOrLocation    townOrLocation
220
	 */
221
	public void setTownOrLocation(String townOrLocation){
222
		this.townOrLocation = StringUtils.isBlank(townOrLocation)? null : townOrLocation;
223
	}
224

    
225
	/**
226
	 * The collection <code>this</code> collection is part of.
227
	 * @return
228
	 */
229
	public Collection getSuperCollection() {
230
		return superCollection;
231
	}
232

    
233
	/**
234
	 * @see #getSuperCollection()
235
	 * @param superCollection
236
	 */
237
	public void setSuperCollection(Collection superCollection) {
238
		this.superCollection = superCollection;
239
	}
240

    
241

    
242
//*********** CLONE **********************************/
243

    
244
	/**
245
	 * Clones <i>this</i> collection. This is a shortcut that enables to
246
	 * create a new instance that differs only slightly from <i>this</i> collection
247
	 * by modifying only some of the attributes.<BR>
248
	 * This method overrides the clone method from {@link IdentifiableMediaEntity IdentifiableMediaEntity}.
249
	 *
250
	 * @see eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity#clone()
251
	 * @see java.lang.Object#clone()
252
	 */
253
	@Override
254
	public Collection clone(){
255
		try{
256
			Collection result = (Collection)super.clone();
257
			//superCollection
258
			result.setSuperCollection(this.superCollection);
259
			//institute
260
			result.setInstitute(this.institute);
261
			//no changes to: code, codeStandard, name, townOrLocation
262
			return result;
263
		} catch (CloneNotSupportedException e) {
264
			logger.warn("Object does not implement cloneable");
265
			e.printStackTrace();
266
			return null;
267
		}
268
	}
269

    
270

    
271

    
272
// *********************** toString() **************************************
273

    
274
	@Override
275
	public String toString() {
276
		if (StringUtils.isNotBlank(code) || StringUtils.isNotBlank(name)){
277
			return "Collection [id= "+ getId() +", + code=" + CdmUtils.Nz(code) + ", name=" + CdmUtils.Nz(name) + "]";
278
		}else{
279
			return super.toString();
280
		}
281
	}
282
}
(1-1/14)