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
|
import java.util.HashMap;
|
13
|
import java.util.Map;
|
14
|
|
15
|
import javax.persistence.Basic;
|
16
|
import javax.persistence.FetchType;
|
17
|
import javax.persistence.ManyToOne;
|
18
|
import javax.persistence.MappedSuperclass;
|
19
|
import javax.xml.bind.annotation.XmlAccessType;
|
20
|
import javax.xml.bind.annotation.XmlAccessorType;
|
21
|
import javax.xml.bind.annotation.XmlElement;
|
22
|
import javax.xml.bind.annotation.XmlIDREF;
|
23
|
import javax.xml.bind.annotation.XmlSchemaType;
|
24
|
import javax.xml.bind.annotation.XmlType;
|
25
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
26
|
|
27
|
import org.apache.log4j.Logger;
|
28
|
import org.hibernate.annotations.Type;
|
29
|
import org.hibernate.envers.Audited;
|
30
|
import org.hibernate.search.annotations.Analyze;
|
31
|
import org.hibernate.search.annotations.Field;
|
32
|
import org.hibernate.search.annotations.FieldBridge;
|
33
|
import org.joda.time.DateTime;
|
34
|
|
35
|
import eu.etaxonomy.cdm.hibernate.search.DateTimeBridge;
|
36
|
import eu.etaxonomy.cdm.jaxb.DateTimeAdapter;
|
37
|
import eu.etaxonomy.cdm.model.permission.User;
|
38
|
import eu.etaxonomy.cdm.strategy.match.Match;
|
39
|
import eu.etaxonomy.cdm.strategy.match.MatchMode;
|
40
|
|
41
|
/**
|
42
|
* The class keeps track of versions via a full linked list to different version objects, or a simple updated/updatedBy property in the same object.
|
43
|
*
|
44
|
* Full versioning allows concrete subclasses to keep track of previous or later versions of an object.
|
45
|
* A different version is another (persistent) java object, but with the same UUID.
|
46
|
* The version history is established as a linked list of the version objects in time.
|
47
|
* If versioning via the linked list is used, updated/updatedBy is the same as created/createdBy (better NULL?).
|
48
|
*
|
49
|
* Versioning can be turned off and in this case this class provides updated/updatedBy to
|
50
|
* keep track of the latest change event.
|
51
|
*
|
52
|
* @author m.doering
|
53
|
* @since 08-Nov-2007 13:07:01
|
54
|
*
|
55
|
* @param <T>
|
56
|
*/
|
57
|
@XmlAccessorType(XmlAccessType.FIELD)
|
58
|
@XmlType(name = "VersionableEntity", propOrder = {
|
59
|
"updated",
|
60
|
"updatedBy"
|
61
|
})
|
62
|
@XmlJavaTypeAdapter(value=DateTimeAdapter.class,type=DateTime.class)
|
63
|
@MappedSuperclass
|
64
|
@Audited
|
65
|
public abstract class VersionableEntity
|
66
|
extends CdmBase
|
67
|
implements IVersionableEntity{
|
68
|
|
69
|
private static final long serialVersionUID = 1409299200302758513L;
|
70
|
@SuppressWarnings("unused")
|
71
|
private static final Logger logger = Logger.getLogger(VersionableEntity.class);
|
72
|
|
73
|
@XmlElement(name ="Updated", type = String.class)
|
74
|
@XmlJavaTypeAdapter(DateTimeAdapter.class)
|
75
|
//@XmlElement(name ="Updated")
|
76
|
//@XmlElement(name ="Updated")
|
77
|
@Type(type="dateTimeUserType")
|
78
|
@Basic(fetch = FetchType.LAZY)
|
79
|
@Match(MatchMode.IGNORE)
|
80
|
@Field(analyze = Analyze.NO)
|
81
|
@FieldBridge(impl = DateTimeBridge.class)
|
82
|
private DateTime updated;
|
83
|
|
84
|
@XmlElement(name = "UpdatedBy")
|
85
|
@XmlIDREF
|
86
|
@XmlSchemaType(name = "IDREF")
|
87
|
@ManyToOne(fetch=FetchType.LAZY)
|
88
|
@Match(MatchMode.IGNORE)
|
89
|
private User updatedBy;
|
90
|
|
91
|
@Override
|
92
|
public User getUpdatedBy(){
|
93
|
return this.updatedBy;
|
94
|
}
|
95
|
@Override
|
96
|
public void setUpdatedBy(User updatedBy){
|
97
|
this.updatedBy = updatedBy;
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public DateTime getUpdated(){
|
102
|
return this.updated;
|
103
|
}
|
104
|
@Override
|
105
|
public void setUpdated(DateTime updated){
|
106
|
this.updated = updated;
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* {@inheritDoc}.
|
111
|
* <BR><BR>
|
112
|
* Override CdmBase implementation here to set the method final.
|
113
|
* For discussion on final see {@link CdmBase#equals(Object)}.
|
114
|
*/
|
115
|
@Override
|
116
|
public final boolean equals(Object obj) {
|
117
|
return super.equals(obj);
|
118
|
}
|
119
|
|
120
|
// **************** EMPTY ************************/
|
121
|
|
122
|
@Override
|
123
|
protected boolean checkEmpty(){
|
124
|
return super.checkEmpty()
|
125
|
//nothing to do; updated and updatedBy are not relevant
|
126
|
;
|
127
|
}
|
128
|
|
129
|
//********************** CLONE *****************************************/
|
130
|
|
131
|
/**
|
132
|
* Clones this versionable entity.
|
133
|
* Set fields for nextVersion, previousVersion, updated, updatedBy and createdBy are set to <tt>null</tt>
|
134
|
* The id is set to 0.
|
135
|
* The uuid is created new.
|
136
|
* The createdWhen is set to the current date.
|
137
|
* @see java.lang.Object#clone()
|
138
|
*/
|
139
|
@Override
|
140
|
public VersionableEntity clone() throws CloneNotSupportedException{
|
141
|
|
142
|
VersionableEntity result = (VersionableEntity)super.clone();
|
143
|
|
144
|
result.setUpdated(null);
|
145
|
result.setUpdatedBy(null);
|
146
|
|
147
|
//no changes to: -
|
148
|
return result;
|
149
|
}
|
150
|
|
151
|
|
152
|
/**
|
153
|
* Convenience method to clone a LanguageString map
|
154
|
* @param oldMap
|
155
|
* @return
|
156
|
* @throws CloneNotSupportedException
|
157
|
*/
|
158
|
protected Map<Language,LanguageString> cloneLanguageString(Map<Language,LanguageString> oldMap) throws CloneNotSupportedException{
|
159
|
Map<Language,LanguageString> result = new HashMap<>();
|
160
|
for (Language language : oldMap.keySet()){
|
161
|
LanguageString newLanguageString = oldMap.get(language).clone();
|
162
|
result.put(language, newLanguageString);
|
163
|
}
|
164
|
return result;
|
165
|
}
|
166
|
}
|