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
|
|
10
|
package eu.etaxonomy.cdm.model.common;
|
11
|
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.hibernate.annotations.Cascade;
|
15
|
import org.hibernate.annotations.CascadeType;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.media.Rights;
|
18
|
|
19
|
|
20
|
import java.util.HashSet;
|
21
|
import java.util.Set;
|
22
|
|
23
|
import javax.persistence.*;
|
24
|
|
25
|
/**
|
26
|
* Superclass for the primary CDM classes that can be referenced from outside via LSIDs and contain a simple generated title string as a label for human reading.
|
27
|
* All subclasses inherit the ability to store additional properties that are stored as {@link Extension Extensions}, basically a string value with a type term.
|
28
|
* Any number of right statements can be attached as well as multiple {@link OriginalSource} objects.
|
29
|
* Original sources carry a reference to the source, an ID within that source and the original title/label of this object as it was used in that source (originalNameString).
|
30
|
* A Taxon for example that was taken from 2 sources like FaunaEuropaea and IPNI would have two originalSource objects.
|
31
|
* The originalSource representing that taxon as it was found in IPNI would contain IPNI as the reference, the IPNI id of the taxon and the name of the taxon exactly as it was used in IPNI.
|
32
|
*
|
33
|
* @author m.doering
|
34
|
* @version 1.0
|
35
|
* @created 08-Nov-2007 13:06:27
|
36
|
*/
|
37
|
@MappedSuperclass
|
38
|
public abstract class IdentifiableEntity<T extends IdentifiableEntity> extends AnnotatableEntity<T> implements IOriginalSource {
|
39
|
static Logger logger = Logger.getLogger(IdentifiableEntity.class);
|
40
|
|
41
|
public final boolean PROTECTED = true;
|
42
|
public final boolean NOT_PROTECTED = false;
|
43
|
|
44
|
private String lsid;
|
45
|
private String titleCache;
|
46
|
//if true titleCache will not be automatically generated/updated
|
47
|
private boolean protectedTitleCache;
|
48
|
private Set<Rights> rights = new HashSet<Rights>();
|
49
|
private Set<Extension> extensions = new HashSet<Extension>();
|
50
|
private Set<OriginalSource> sources = new HashSet<OriginalSource>();
|
51
|
|
52
|
|
53
|
public String getLsid(){
|
54
|
return this.lsid;
|
55
|
}
|
56
|
public void setLsid(String lsid){
|
57
|
this.lsid = lsid;
|
58
|
}
|
59
|
|
60
|
public abstract String generateTitle();
|
61
|
|
62
|
public String getTitleCache(){
|
63
|
if (protectedTitleCache){
|
64
|
return this.titleCache;
|
65
|
}
|
66
|
// is title dirty, i.e. equal NULL?
|
67
|
if (titleCache == null){
|
68
|
this.titleCache = generateTitle();
|
69
|
}
|
70
|
return titleCache;
|
71
|
}
|
72
|
public void setTitleCache(String titleCache){
|
73
|
//TODO truncation of title cach
|
74
|
if (titleCache != null && titleCache.length() > 254){
|
75
|
logger.warn("Truncation of title cache: " + this.toString());
|
76
|
titleCache = titleCache.substring(0, 252) + "...";
|
77
|
}
|
78
|
this.titleCache = titleCache;
|
79
|
this.setProtectedTitleCache(PROTECTED);
|
80
|
}
|
81
|
public void setTitleCache(String titleCache, boolean protectCache){
|
82
|
this.titleCache = titleCache;
|
83
|
this.setProtectedTitleCache(protectCache);
|
84
|
}
|
85
|
|
86
|
@ManyToMany
|
87
|
@Cascade({CascadeType.SAVE_UPDATE})
|
88
|
public Set<Rights> getRights(){
|
89
|
return this.rights;
|
90
|
}
|
91
|
|
92
|
protected void setRights(Set<Rights> rights) {
|
93
|
this.rights = rights;
|
94
|
}
|
95
|
public void addRights(Rights right){
|
96
|
this.rights.add(right);
|
97
|
}
|
98
|
public void removeRights(Rights right){
|
99
|
this.rights.remove(right);
|
100
|
}
|
101
|
|
102
|
@OneToMany//(mappedBy="extendedObj")
|
103
|
@Cascade({CascadeType.SAVE_UPDATE})
|
104
|
public Set<Extension> getExtensions(){
|
105
|
return this.extensions;
|
106
|
}
|
107
|
protected void setExtensions(Set<Extension> extensions) {
|
108
|
this.extensions = extensions;
|
109
|
}
|
110
|
public void addExtension(Extension extension){
|
111
|
this.extensions.add(extension);
|
112
|
}
|
113
|
public void removeExtension(Extension extension){
|
114
|
this.extensions.remove(extension);
|
115
|
}
|
116
|
|
117
|
|
118
|
public boolean isProtectedTitleCache() {
|
119
|
return protectedTitleCache;
|
120
|
}
|
121
|
|
122
|
public void setProtectedTitleCache(boolean protectedTitleCache) {
|
123
|
this.protectedTitleCache = protectedTitleCache;
|
124
|
}
|
125
|
|
126
|
@OneToMany //(mappedBy="sourcedObj")
|
127
|
@Cascade({CascadeType.SAVE_UPDATE})
|
128
|
public Set<OriginalSource> getSources() {
|
129
|
return this.sources;
|
130
|
}
|
131
|
protected void setSources(Set<OriginalSource> sources) {
|
132
|
this.sources = sources;
|
133
|
}
|
134
|
public void addSource(OriginalSource source) {
|
135
|
this.sources.add(source);
|
136
|
}
|
137
|
public void removeSource(OriginalSource source) {
|
138
|
this.sources.remove(source);
|
139
|
}
|
140
|
|
141
|
/**
|
142
|
* Overrides {@link eu.etaxonomy.cdm.model.common.CdmBase#toString()}.
|
143
|
* This returns an String that identifies the object well without beeing necessarily unique.
|
144
|
* Specification: This method should never call other object' methods so it can be well used for debugging
|
145
|
* without problems like lazy loading, unreal states etc.
|
146
|
* Note: If overriding this method's javadoc always copy or link the above requirement.
|
147
|
* If not overwritten by a subclass method returns the class, id and uuid as a string for any CDM object.
|
148
|
* For example: Taxon#13<b5938a98-c1de-4dda-b040-d5cc5bfb3bc0>
|
149
|
* @see java.lang.Object#toString()
|
150
|
*/
|
151
|
@Override
|
152
|
public String toString() {
|
153
|
String result;
|
154
|
if (titleCache == null){
|
155
|
result = super.toString();
|
156
|
}else{
|
157
|
result = this.titleCache;
|
158
|
}
|
159
|
return result;
|
160
|
}
|
161
|
|
162
|
}
|