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
|
package eu.etaxonomy.cdm.model.common;
|
11
|
|
12
|
import javax.persistence.Column;
|
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.XmlSchemaType;
|
21
|
import javax.xml.bind.annotation.XmlType;
|
22
|
|
23
|
import org.apache.commons.lang.StringUtils;
|
24
|
import org.apache.log4j.Logger;
|
25
|
import org.hibernate.annotations.Index;
|
26
|
import org.hibernate.annotations.Table;
|
27
|
import org.hibernate.envers.Audited;
|
28
|
import org.hibernate.search.annotations.Field;
|
29
|
|
30
|
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
* @date 2014-06-30
|
35
|
*/
|
36
|
|
37
|
@XmlAccessorType(XmlAccessType.FIELD)
|
38
|
@XmlType(name = "Identifier", propOrder = {
|
39
|
"identifier",
|
40
|
"type"
|
41
|
})
|
42
|
@Entity
|
43
|
@Audited
|
44
|
@Table(appliesTo="Identifier", indexes = { @Index(name = "identifierIndex", columnNames = { "identifier" }) })
|
45
|
public class Identifier<T extends IdentifiableEntity<?>> extends AnnotatableEntity implements Cloneable {
|
46
|
private static final long serialVersionUID = 3337567049024506936L;
|
47
|
@SuppressWarnings("unused")
|
48
|
private static final Logger logger = Logger.getLogger(Identifier.class);
|
49
|
|
50
|
|
51
|
@XmlElement(name ="Identifier" )
|
52
|
@Column(length=800, name="identifier")
|
53
|
@Field
|
54
|
@NullOrNotEmpty
|
55
|
private String identifier;
|
56
|
|
57
|
@XmlElement(name = "Type")
|
58
|
@XmlIDREF
|
59
|
@XmlSchemaType(name = "IDREF")
|
60
|
@ManyToOne(fetch = FetchType.LAZY)
|
61
|
private DefinedTerm type;
|
62
|
|
63
|
// **************************** FACTORY ******************************/
|
64
|
|
65
|
public static <T extends IdentifiableEntity<?>> Identifier<T> NewInstance(String identifier, DefinedTerm type){
|
66
|
return new Identifier<T>(identifier, type);
|
67
|
}
|
68
|
|
69
|
// ************************* CONSTRUCTOR ************************************
|
70
|
|
71
|
@Deprecated //for hibernate use only
|
72
|
protected Identifier(){};
|
73
|
|
74
|
public Identifier (String identifier, DefinedTerm type){
|
75
|
this.identifier = identifier;
|
76
|
this.type = type;
|
77
|
}
|
78
|
|
79
|
|
80
|
// ****************** GETTER / SETTER **********************/
|
81
|
|
82
|
public String getIdentifier() {
|
83
|
return identifier;
|
84
|
}
|
85
|
public void setIdentifier(String identifier) {
|
86
|
this.identifier = StringUtils.isBlank(identifier) ? null : identifier;
|
87
|
}
|
88
|
|
89
|
|
90
|
/**
|
91
|
* The identifier type. E.g. DOI, LSID, Barcode, Sample Designation, ...
|
92
|
* @see TermType#IdentifierType
|
93
|
* @return
|
94
|
*/
|
95
|
public DefinedTerm getType() {
|
96
|
return type;
|
97
|
}
|
98
|
public void setType(DefinedTerm identifierType) {
|
99
|
this.type = identifierType;
|
100
|
}
|
101
|
|
102
|
//****************** CLONE ************************************************/
|
103
|
|
104
|
@Override
|
105
|
public Object clone() throws CloneNotSupportedException{
|
106
|
Identifier<?> result = (Identifier<?>)super.clone();
|
107
|
//no changes to: type, value
|
108
|
return result;
|
109
|
}
|
110
|
|
111
|
}
|