Project

General

Profile

Download (4.43 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
//    @IndexedEmbedded(depth=1)
66
	private DefinedTerm type;
67

    
68
    @XmlElement(name = "IdentifiedObject")
69
    @XmlIDREF
70
    @XmlSchemaType(name = "IDREF")
71
    @Any(metaDef = "CdmBase",
72
	    	 metaColumn=@Column(name = "identifiedObj_type"),
73
	    	 fetch = FetchType.LAZY,
74
	    	 optional = false)
75
	@JoinColumn(name = "identifiedObj_id")
76
	@NotAudited
77
	private T identifiedObj;
78
    
79
// **************************** FACTORY ******************************/    
80
    
81
    public static <T extends IdentifiableEntity<?>> Identifier<T> NewInstance(T entity, String identifier, DefinedTerm type){
82
    	return new Identifier<T>(entity, identifier, type);
83
    }
84

    
85
// ************************* CONSTRUCTOR ************************************    
86
    
87
    @Deprecated  //for hibernate use only
88
    protected Identifier(){};
89
    
90
    public Identifier (T entity, String identifier, DefinedTerm type){
91
    	this.identifier = identifier;
92
    	this.type = type;
93
//    	logger.warn("Identified object not yet implemented");
94
    	this.identifiedObj = entity;
95
    	identifiedObj.addIdentifier(this);
96
    }
97

    
98
    
99
// ****************** GETTER / SETTER **********************/    
100
    
101
	public String getIdentifier() {
102
		return identifier;
103
	}
104

    
105

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

    
110

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

    
120

    
121
	public void setType(DefinedTerm identifierType) {
122
		this.type = identifierType;
123
	}
124
	
125
	public T getIdentifiedObj() {
126
		return identifiedObj;
127
	}
128
	protected void setIdentifiedObj(T identifiedObj) {
129
		this.identifiedObj = identifiedObj;
130
	}
131
	
132
	//****************** CLONE ************************************************/
133
	 
134
		@Override
135
		public Object clone() throws CloneNotSupportedException{
136
			Identifier<?> result = (Identifier<?>)super.clone();	
137
			//no changes to: type, value
138
			return result;
139
		}
140
	
141
	/**
142
	 * Clones this extension and sets the clone's extended object to 'extendedObject'
143
	 * @see java.lang.Object#clone()
144
	 */
145
	public <T extends IdentifiableEntity<?>> Identifier<T> clone(T identifiedObject) throws CloneNotSupportedException{
146
		Identifier<T> result = (Identifier<T>)clone();
147
		result.setIdentifiedObj(identifiedObject);
148
		return result;
149
	}
150
	
151
}
(38-38/72)