Project

General

Profile

Download (3.4 KB) Statistics
| Branch: | Tag: | Revision:
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
    public static <T extends IdentifiableEntity<?>> Identifier<T> NewInstance(IdentifiableEntity identifiableEntity,
70
            String identifier, DefinedTerm type){
71
        Identifier<T> result = new Identifier<T>(identifier, type);
72
        identifiableEntity.addIdentifier(result);
73
        return result;
74
    }
75

    
76
// ************************* CONSTRUCTOR ************************************
77

    
78
    @Deprecated  //for hibernate use only
79
    protected Identifier(){};
80

    
81
    public Identifier (String identifier, DefinedTerm type){
82
    	this.identifier = identifier;
83
    	this.type = type;
84
    }
85

    
86

    
87
// ****************** GETTER / SETTER **********************/
88

    
89
	public String getIdentifier() {
90
		return identifier;
91
	}
92
	public void setIdentifier(String identifier) {
93
		this.identifier = StringUtils.isBlank(identifier) ? null : identifier;
94
	}
95

    
96

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

    
109
	//****************** CLONE ************************************************/
110

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

    
118
}
(38-38/72)