(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / IdentifiableEntity.java
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
18 import java.util.HashSet;
19 import java.util.Set;
20
21 import javax.persistence.*;
22
23 /**
24 * 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.
25 * All subclasses inherit the ability to store additional properties that are stored as {@link Extension Extensions}, basically a string value with a type term.
26 * Any number of right statements can be attached as well as multiple {@link OriginalSource} objects.
27 * 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).
28 * A Taxon for example that was taken from 2 sources like FaunaEuropaea and IPNI would have two originalSource objects.
29 * 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.
30 *
31 * @author m.doering
32 * @version 1.0
33 * @created 08-Nov-2007 13:06:27
34 */
35 @MappedSuperclass
36 public abstract class IdentifiableEntity<T extends IdentifiableEntity> extends AnnotatableEntity<T> implements IOriginalSource {
37 static Logger logger = Logger.getLogger(IdentifiableEntity.class);
38
39 private String lsid;
40 private String titleCache;
41 //if true titleCache will not be automatically generated/updated
42 private boolean protectedTitleCache;
43 private Set<Rights> rights = new HashSet();
44 private Set<Extension> extensions = new HashSet();
45 private Set<OriginalSource> sources = new HashSet();
46
47
48 public String getLsid(){
49 return this.lsid;
50 }
51 public void setLsid(String lsid){
52 this.lsid = lsid;
53 }
54
55 public abstract String generateTitle();
56
57 public String getTitleCache(){
58 if (protectedTitleCache){
59 return this.titleCache;
60 }
61 // is title dirty, i.e. equal NULL?
62 if (titleCache == null){
63 this.titleCache = generateTitle();
64 }
65 return titleCache;
66 }
67 public void setTitleCache(String titleCache){
68 this.titleCache = titleCache;
69 this.setProtectedTitleCache(true);
70 }
71 public void setTitleCache(String titleCache, boolean protectCache){
72 this.titleCache = titleCache;
73 this.setProtectedTitleCache(protectCache);
74 }
75
76 @ManyToMany
77 @Cascade({CascadeType.SAVE_UPDATE})
78 public Set<Rights> getRights(){
79 return this.rights;
80 }
81
82 protected void setRights(Set<Rights> rights) {
83 this.rights = rights;
84 }
85 public void addRights(Rights right){
86 this.rights.add(right);
87 }
88 public void removeRights(Rights right){
89 this.rights.remove(right);
90 }
91
92 @OneToMany//(mappedBy="extendedObj")
93 @Cascade({CascadeType.SAVE_UPDATE})
94 public Set<Extension> getExtensions(){
95 return this.extensions;
96 }
97 protected void setExtensions(Set<Extension> extensions) {
98 this.extensions = extensions;
99 }
100 public void addExtension(Extension extension){
101 this.extensions.add(extension);
102 }
103 public void removeExtension(Extension extension){
104 this.extensions.remove(extension);
105 }
106
107
108 public boolean isProtectedTitleCache() {
109 return protectedTitleCache;
110 }
111
112 public void setProtectedTitleCache(boolean protectedTitleCache) {
113 this.protectedTitleCache = protectedTitleCache;
114 }
115
116
117 @OneToMany //(mappedBy="sourcedObj")
118 @Cascade({CascadeType.SAVE_UPDATE})
119 public Set<OriginalSource> getSources() {
120 return this.sources;
121 }
122
123 protected void setSources(Set<OriginalSource> sources) {
124 this.sources = sources;
125 }
126
127 public void addSource(OriginalSource source) {
128 this.sources.add(source);
129 }
130
131 public void removeSource(OriginalSource source) {
132 this.sources.remove(source);
133 }
134 @Override
135 public String toString() {
136 return this.getTitleCache();
137 }
138
139 }