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