Project

General

Profile

Download (3.47 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
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.commons.lang.StringUtils;
25
import org.apache.log4j.Logger;
26
import org.hibernate.envers.Audited;
27
import org.hibernate.search.annotations.Field;
28

    
29
import eu.etaxonomy.cdm.model.term.DefinedTerm;
30
import eu.etaxonomy.cdm.model.term.TermType;
31
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
32

    
33
/**
34
 * @author a.mueller
35
 * @since 2014-06-30
36
 */
37

    
38
@XmlAccessorType(XmlAccessType.FIELD)
39
@XmlType(name = "Identifier", propOrder = {
40
    "identifier",
41
    "type"
42
})
43
@Entity
44
@Audited
45
@Table(name="Identifier", indexes = { @Index(name = "identifierIndex", columnList = "identifier") })
46
public class Identifier<T extends IdentifiableEntity<?>>
47
            extends AnnotatableEntity
48
            implements Cloneable {
49

    
50
    private static final long serialVersionUID = 3337567049024506936L;
51
	@SuppressWarnings("unused")
52
	private static final Logger logger = Logger.getLogger(Identifier.class);
53

    
54

    
55
	@XmlElement(name ="Identifier" )
56
	@Column(length=800, name="identifier")
57
	@Field
58
    @NullOrNotEmpty
59
	private String identifier;
60

    
61
    @XmlElement(name = "Type")
62
    @XmlIDREF
63
    @XmlSchemaType(name = "IDREF")
64
    @ManyToOne(fetch = FetchType.LAZY)
65
	private DefinedTerm type;
66

    
67
// **************************** FACTORY ******************************/
68

    
69
    public static <T extends IdentifiableEntity<?>> Identifier<T> NewInstance(String identifier, DefinedTerm type){
70
    	return new Identifier<T>(identifier, type);
71
    }
72

    
73
    public static <T extends IdentifiableEntity<?>> Identifier<T> NewInstance(T identifiableEntity,
74
            String identifier, DefinedTerm type){
75
        Identifier<T> result = new Identifier<T>(identifier, type);
76
        identifiableEntity.addIdentifier(result);
77
        return result;
78
    }
79

    
80
// ************************* CONSTRUCTOR ************************************
81

    
82
    @Deprecated  //for hibernate use only
83
    protected Identifier(){};
84

    
85
    public Identifier (String identifier, DefinedTerm type){
86
    	this.identifier = identifier;
87
    	this.type = type;
88
    }
89

    
90

    
91
// ****************** GETTER / SETTER **********************/
92

    
93
	public String getIdentifier() {
94
		return identifier;
95
	}
96
	public void setIdentifier(String identifier) {
97
		this.identifier = StringUtils.isBlank(identifier) ? null : identifier;
98
	}
99

    
100

    
101
	/**
102
	 * The identifier type. E.g. DOI, LSID, Barcode, Sample Designation, ...
103
	 * @see TermType#IdentifierType
104
	 * @return
105
	 */
106
	public DefinedTerm getType() {
107
		return type;
108
	}
109
	public void setType(DefinedTerm identifierType) {
110
		this.type = identifierType;
111
	}
112

    
113
	//****************** CLONE ************************************************/
114

    
115
	@Override
116
	public Object clone() throws CloneNotSupportedException{
117
		Identifier<?> result = (Identifier<?>)super.clone();
118
		//no changes to: type, value
119
		return result;
120
	}
121

    
122
}
(31-31/60)