Project

General

Profile

Download (7.38 KB) Statistics
| Branch: | Tag: | Revision:
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.Column;
14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.ManyToOne;
17
import javax.xml.bind.annotation.XmlAccessType;
18
import javax.xml.bind.annotation.XmlAccessorType;
19
import javax.xml.bind.annotation.XmlElement;
20
import javax.xml.bind.annotation.XmlIDREF;
21
import javax.xml.bind.annotation.XmlRootElement;
22
import javax.xml.bind.annotation.XmlSchemaType;
23
import javax.xml.bind.annotation.XmlType;
24

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

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

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

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

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

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

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

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

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

    
113
// ************** FACTORY METHODS *************************/
114

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

    
123
// ******************** CONSTRUCTOR *************************/
124

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

    
133
// ******************* GETTER / SETTER ************************/
134

    
135

    
136

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

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

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

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

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

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

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

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

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

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

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

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

    
240

    
241
//*********** CLONE **********************************/
242

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

    
269

    
270

    
271
// *********************** toString() **************************************
272

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