Project

General

Profile

Download (7.63 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.persistence.Table;
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.lang3.StringUtils;
27
import org.apache.logging.log4j.LogManager;
28
import org.apache.logging.log4j.Logger;
29
import org.hibernate.annotations.Cascade;
30
import org.hibernate.annotations.CascadeType;
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
 * @since 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(name="Collection", indexes = { @javax.persistence.Index(name = "collectionTitleCacheIndex", columnList = "titleCache") })
67
public class Collection
68
        extends IdentifiableMediaEntity<IIdentifiableEntityCacheStrategy<Collection>> {
69

    
70
    private static final long serialVersionUID = -7833674897174732255L;
71
	private static final Logger logger = LogManager.getLogger();
72

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

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

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

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

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

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

    
116
// ************** FACTORY METHODS *************************/
117

    
118
	public static Collection NewInstance(){
119
		return new Collection();
120
	}
121

    
122
    public static Collection NewInstance(String code, String name){
123
        Collection result = new Collection();
124
        result.setCode(code);
125
        result.setName(name);
126
        return result;
127
    }
128

    
129
// ******************** CONSTRUCTOR *************************/
130

    
131
    //*packet* private required by bytebuddy
132
	Collection() {
133
		super();
134
	}
135

    
136
    @Override
137
    protected void initDefaultCacheStrategy() {
138
        this.cacheStrategy = new CollectionDefaultCacheStrategy();
139
    }
140

    
141
// ******************* GETTER / SETTER ************************/
142

    
143
	/**
144
	 * The {@link Institution institution} this collection belongs to.
145
	 * @see #getSuperCollection()
146
	 * @return the institute
147
	 */
148
	public Institution getInstitute(){
149
		return this.institute;
150
	}
151

    
152
	/**
153
	 * @see #getInstitute()
154
	 * @param institute    institute
155
	 */
156
	public void setInstitute(Institution institute){
157
		this.institute = institute;
158
	}
159

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

    
173
	/**
174
	 * @see #getCode()
175
	 * @param code the code
176
	 */
177
	public void setCode(String code){
178
		this.code = StringUtils.isBlank(code)? null : code;
179
	}
180

    
181
	/**
182
	 * The standard used for the given {@link #getCode() collection code}
183
	 * @return the code standard
184
	 */
185
	public String getCodeStandard(){
186
		return this.codeStandard;
187
	}
188

    
189
	/**
190
	 * @see #getCodeStandard()
191
	 * @see #getCode()
192
	 * @param codeStandard    codeStandard
193
	 */
194
	public void setCodeStandard(String codeStandard){
195
		this.codeStandard = StringUtils.isBlank(codeStandard)? null : codeStandard;
196
	}
197

    
198
	/**
199
	 * The name of this collection
200
	 * @return the name
201
	 */
202
	public String getName(){
203
		return this.name;
204
	}
205

    
206
	/**
207
	 * @see #getName()
208
	 * @param name    name
209
	 */
210
	public void setName(String name){
211
		this.name = StringUtils.isBlank(name)? null : name;
212
	}
213

    
214
	/**
215
	 * The town or location where this collection is to be found.
216
	 * @return the town or location
217
	 */
218
	public String getTownOrLocation(){
219
		return this.townOrLocation;
220
	}
221

    
222
	/**
223
	 * @see #getTownOrLocation
224
	 * @param townOrLocation    townOrLocation
225
	 */
226
	public void setTownOrLocation(String townOrLocation){
227
		this.townOrLocation = StringUtils.isBlank(townOrLocation)? null : townOrLocation;
228
	}
229

    
230
	/**
231
	 * The collection <code>this</code> collection is part of.
232
	 * @return
233
	 */
234
	public Collection getSuperCollection() {
235
		return superCollection;
236
	}
237

    
238
	/**
239
	 * @see #getSuperCollection()
240
	 * @param superCollection
241
	 */
242
	public void setSuperCollection(Collection superCollection) {
243
		this.superCollection = superCollection;
244
	}
245

    
246
//*********** CLONE **********************************/
247

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

    
274
// *********************** toString() **************************************
275

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