Project

General

Profile

Download (4.35 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.JoinColumn;
16
import javax.persistence.ManyToOne;
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.annotations.Any;
27
import org.hibernate.annotations.Index;
28
import org.hibernate.annotations.Table;
29
import org.hibernate.envers.Audited;
30
import org.hibernate.envers.NotAudited;
31
import org.hibernate.search.annotations.Field;
32

    
33
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
34

    
35
/**
36
 * @author a.mueller
37
 * @date 2014-06-30
38
 */
39

    
40
@XmlAccessorType(XmlAccessType.FIELD)
41
@XmlType(name = "Identifier", propOrder = {
42
    "identifier",
43
    "type",
44
    "identifiedObj"
45
})
46
@Entity
47
@Audited
48
@Table(appliesTo="Identifier", indexes = { @Index(name = "identifierIndex", columnNames = { "identifier" }) })
49
public class Identifier<T extends IdentifiableEntity<?>> extends AnnotatableEntity implements Cloneable {
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
    @XmlElement(name = "IdentifiedObject")
68
    @XmlIDREF
69
    @XmlSchemaType(name = "IDREF")
70
    @Any(metaDef = "CdmBase",
71
	    	 metaColumn=@Column(name = "identifiedObj_type"),
72
	    	 fetch = FetchType.LAZY,
73
	    	 optional = false)
74
	@JoinColumn(name = "identifiedObj_id")
75
	@NotAudited
76
	private T identifiedObj;
77

    
78
// **************************** FACTORY ******************************/
79

    
80
    public static <T extends IdentifiableEntity<?>> Identifier<T> NewInstance(T entity, String identifier, DefinedTerm type){
81
    	return new Identifier<T>(entity, identifier, type);
82
    }
83

    
84
// ************************* CONSTRUCTOR ************************************
85

    
86
    @Deprecated  //for hibernate use only
87
    protected Identifier(){};
88

    
89
    public Identifier (T entity, String identifier, DefinedTerm type){
90
    	this.identifier = identifier;
91
    	this.type = type;
92
//    	logger.warn("Identified object not yet implemented");
93
    	this.identifiedObj = entity;
94
    	identifiedObj.addIdentifier(this);
95
    }
96

    
97

    
98
// ****************** GETTER / SETTER **********************/
99

    
100
	public String getIdentifier() {
101
		return identifier;
102
	}
103

    
104

    
105
	public void setIdentifier(String identifier) {
106
		this.identifier = StringUtils.isBlank(identifier) ? null : identifier;
107
	}
108

    
109

    
110
	/**
111
	 * The identifier type. E.g. DOI, LSID, Barcode, Sample Designation, ...
112
	 * @see TermType#IdentifierType
113
	 * @return
114
	 */
115
	public DefinedTerm getType() {
116
		return type;
117
	}
118

    
119

    
120
	public void setType(DefinedTerm identifierType) {
121
		this.type = identifierType;
122
	}
123

    
124
	public T getIdentifiedObj() {
125
		return identifiedObj;
126
	}
127
	protected void setIdentifiedObj(T identifiedObj) {
128
		this.identifiedObj = identifiedObj;
129
	}
130

    
131
	//****************** CLONE ************************************************/
132

    
133
		@Override
134
		public Object clone() throws CloneNotSupportedException{
135
			Identifier<?> result = (Identifier<?>)super.clone();
136
			//no changes to: type, value
137
			return result;
138
		}
139

    
140
	/**
141
	 * Clones this extension and sets the clone's extended object to 'extendedObject'
142
	 * @see java.lang.Object#clone()
143
	 */
144
	public <T extends IdentifiableEntity<?>> Identifier<T> clone(T identifiedObject) throws CloneNotSupportedException{
145
		Identifier<T> result = (Identifier<T>)clone();
146
		result.setIdentifiedObj(identifiedObject);
147
		return result;
148
	}
149

    
150
}
(38-38/72)