Mercurial > hg > openmind
annotate src/main/java/org/mpi/openmind/repository/bo/Node.java @ 33:e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
more comments in code.
author | casties |
---|---|
date | Fri, 26 Aug 2016 11:42:41 +0200 |
parents | c23ae718fdd3 |
children | 5737ab564b94 |
rev | line source |
---|---|
1 | 1 package org.mpi.openmind.repository.bo; |
2 | |
3 import java.io.Serializable; | |
4 import java.text.DateFormat; | |
5 import java.text.SimpleDateFormat; | |
6 import java.util.ArrayList; | |
7 import java.util.Date; | |
8 import java.util.List; | |
9 | |
10 import javax.persistence.Column; | |
11 import javax.persistence.DiscriminatorColumn; | |
12 import javax.persistence.DiscriminatorType; | |
13 import javax.persistence.DiscriminatorValue; | |
14 import javax.persistence.Entity; | |
15 import javax.persistence.GeneratedValue; | |
16 import javax.persistence.GenerationType; | |
17 import javax.persistence.Id; | |
18 import javax.persistence.Inheritance; | |
19 import javax.persistence.InheritanceType; | |
20 import javax.persistence.Table; | |
21 import javax.persistence.Transient; | |
22 | |
23 import org.mpi.openmind.repository.utils.ArabicNormalizerUtils; | |
24 import org.mpi.openmind.repository.utils.NormalizerUtils; | |
25 import org.mpi.openmind.repository.utils.RomanizationLoC; | |
26 | |
27 /** | |
28 * | |
29 * @author jurzua | |
30 */ | |
31 @Entity | |
32 @Table(name="node") | |
33 @Inheritance(strategy=InheritanceType.SINGLE_TABLE) | |
34 @DiscriminatorColumn(name="node_type", discriminatorType=DiscriminatorType.STRING) | |
35 @DiscriminatorValue("NODE") | |
36 public abstract class Node implements Serializable, Cloneable { | |
37 private static final long serialVersionUID = 1L; | |
38 | |
39 public static String TYPE_TBOX = "TBox"; | |
40 public static String TYPE_ABOX = "ABox"; | |
41 public static String TYPE_VARIABLE = "Variable"; | |
42 public static String TYPE_FORMULA = "Formula"; | |
43 public static String TYPE_LINK = "Link"; | |
44 | |
45 public static String SYS_STATUS_CURRENT_VERSION = "CURRENT_VERSION"; | |
46 public static String SYS_STATUS_PREVIOUS_VERSION = "PREVIOUS_VERSION"; | |
47 | |
48 private static SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss" ); | |
49 | |
50 @Id | |
51 @GeneratedValue(strategy = GenerationType.AUTO) | |
52 @Column(name="row_id") | |
53 private Long rowId; | |
54 | |
55 @Transient | |
56 private Date dateModification; | |
57 | |
58 public String getTimeStamp(){ | |
59 return DateFormat.getDateTimeInstance( | |
60 DateFormat.MEDIUM, DateFormat.SHORT).format(getDateModification()); | |
61 } | |
62 | |
63 public Date getDateModification() { | |
64 dateModification = new Date(this.modificationTime); | |
65 return dateModification; | |
66 } | |
67 | |
68 public void setDateModification(Date dateModification) { | |
69 this.dateModification = dateModification; | |
70 } | |
71 | |
72 @Transient | |
73 private List<View> views = new ArrayList<View>(); | |
74 | |
75 public void addView(View view){ | |
76 if(view != null){ | |
77 this.views.add(view); | |
78 } | |
79 } | |
80 | |
81 public List<View> getViews() { | |
82 return views; | |
83 } | |
84 | |
85 public void setViews(List<View> views) { | |
86 this.views = views; | |
87 } | |
88 | |
89 @Column(name="long_value") | |
90 private Long longValue; | |
91 | |
92 @Column(name="binary_value") | |
93 private byte[] binaryValue; | |
94 | |
95 @Column(name="object_class") | |
96 private String objectClass; | |
97 | |
98 @Column(name="user") | |
99 private String user; | |
100 | |
101 //@Type(type = "org.hibernate.type.NumericBooleanType") | |
102 @Column(name="public") | |
103 private Boolean isPublic = Boolean.FALSE; | |
104 | |
105 public String getUser() { | |
106 return user; | |
107 } | |
108 | |
109 public void setUser(String user) { | |
110 this.user = user; | |
111 } | |
112 | |
113 public String getObjectClass() { | |
114 return objectClass; | |
115 } | |
116 | |
117 public void setObjectClass(String objectClass) { | |
118 this.objectClass = objectClass; | |
119 } | |
120 | |
121 public Long getLongValue() { | |
122 return longValue; | |
123 } | |
124 | |
125 | |
126 public void setLongValue(Long longValue) { | |
127 this.longValue = longValue; | |
128 } | |
129 | |
130 public byte[] getBinaryValue() { | |
131 return binaryValue; | |
132 } | |
133 | |
134 public void setBinaryValue(byte[] binaryValue) { | |
135 this.binaryValue = binaryValue; | |
136 } | |
137 | |
138 @Column(name="modification_time") | |
139 private Long modificationTime; | |
140 | |
141 @Column(name="id") | |
142 private Long id; | |
143 | |
144 //lenght 16777215= Medium text | |
145 @Column(name="own_value", columnDefinition="mediumtext") | |
146 private String ownValue; | |
147 | |
148 //, length=16777215 | |
149 @Column(name="normalized_own_value", columnDefinition="mediumtext") | |
150 private String normalizedOwnValue; | |
151 | |
152 //, length=16777215 | |
153 @Column(name="normalized_arabic_own_value", columnDefinition="mediumtext") | |
154 private String normalizedArabicOwnValue; | |
155 | |
156 @Column(name="version") | |
157 private Long version; | |
158 | |
159 @Column(name="status") | |
160 private String status; | |
161 | |
162 @Column(name="system_status") | |
163 private String systemStatus; | |
164 | |
165 @Column(name="type") | |
166 private String type; | |
167 | |
168 @Column(name="content_type") | |
169 private String contentType; | |
170 | |
171 /** | |
172 * Returns true if the entity was made persistent. | |
173 * It means the fields 'id' and 'rowId' are not null. | |
174 * @return | |
175 */ | |
176 public boolean isPersistent(){ | |
177 if(this.getId() == null || this.getRowId() == null) | |
178 return false; | |
179 else | |
180 return true; | |
181 } | |
182 | |
183 public void increaseVersion(){ | |
184 if(this.version == null){ | |
185 this.version = new Long(1); | |
186 }else{ | |
187 this.version++; | |
188 } | |
189 } | |
190 | |
191 public String getOwnValue() { | |
192 return ownValue; | |
193 } | |
194 | |
195 public void setOwnValue(String ownValue) { | |
196 this.ownValue = ownValue; | |
197 this.normalizedOwnValue = NormalizerUtils.normalize(ownValue); | |
198 this.normalizedArabicOwnValue = ArabicNormalizerUtils.normalize(ownValue); | |
199 } | |
200 | |
201 public void autoNormalize(){ | |
202 this.normalizedOwnValue = NormalizerUtils.normalize(ownValue); | |
203 this.normalizedArabicOwnValue = ArabicNormalizerUtils.normalize(ownValue); | |
204 } | |
205 | |
206 public String getRomanizationLoC(){ | |
207 return RomanizationLoC.convert(this.ownValue); | |
208 } | |
209 | |
210 public String getNormalizedOwnValue() { | |
211 return normalizedOwnValue; | |
212 } | |
213 | |
214 public void setNormalizedOwnValue(String normalizedOwnValue) { | |
215 this.normalizedOwnValue = normalizedOwnValue; | |
216 } | |
217 | |
218 public String getNormalizedArabicOwnValue() { | |
219 return normalizedArabicOwnValue; | |
220 } | |
221 | |
222 public void setNormalizedArabicOwnValue(String normalizedArabicOwnValue) { | |
223 this.normalizedArabicOwnValue = normalizedArabicOwnValue; | |
224 } | |
225 | |
226 public String getContentType() { | |
227 return contentType; | |
228 } | |
229 | |
230 public void setContentType(String contentType) { | |
231 this.contentType = contentType; | |
232 } | |
233 | |
234 public Long getRowId() { | |
235 return rowId; | |
236 } | |
237 | |
238 public void setRowId(Long rowId) { | |
239 this.rowId = rowId; | |
240 } | |
241 | |
242 public Long getId() { | |
243 return id; | |
244 } | |
245 | |
246 public void setId(Long id) { | |
247 this.id = id; | |
248 } | |
249 | |
250 public Long getModificationTime() { | |
251 return modificationTime; | |
252 } | |
253 | |
254 public void setModificationTime(Long modificationTime) { | |
255 this.modificationTime = modificationTime; | |
256 } | |
257 | |
258 public String getStatus() { | |
259 return status; | |
260 } | |
261 | |
262 public void setStatus(String status) { | |
263 this.status = status; | |
264 } | |
265 | |
266 public String getSystemStatus() { | |
267 return systemStatus; | |
268 } | |
269 | |
33
e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents:
25
diff
changeset
|
270 /** |
e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents:
25
diff
changeset
|
271 * Set the system_status of this Node. |
e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents:
25
diff
changeset
|
272 * |
e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents:
25
diff
changeset
|
273 * @param systemStatus |
e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
casties
parents:
25
diff
changeset
|
274 */ |
1 | 275 public void setSystemStatus(String systemStatus) { |
276 this.systemStatus = systemStatus; | |
277 } | |
278 | |
279 public String getType() { | |
280 return type; | |
281 } | |
282 | |
283 public void setType(String type) { | |
284 this.type = type; | |
285 } | |
286 | |
287 public Long getVersion() { | |
288 return version; | |
289 } | |
290 | |
291 public void setVersion(Long version) { | |
292 this.version = version; | |
293 } | |
294 | |
295 /* | |
296 @Override | |
297 public int hashCode() { | |
298 int hash = 0; | |
299 hash += (rowId != null ? rowId.hashCode() : 0); | |
300 return hash; | |
301 }*/ | |
302 @Override | |
303 public int hashCode() { | |
304 if(this.rowId == null){ | |
305 return super.hashCode(); | |
306 }else{ | |
307 return rowId.hashCode(); | |
308 } | |
309 } | |
310 | |
311 /** | |
312 * Clones this object and every object contained by it. | |
313 * This method was implemented because the cache. The cache must return a cloned version of a object, | |
314 * otherwise when the object is modified, it becomes dirty and the cache could not recognize the change of the state. | |
315 */ | |
316 @Override | |
317 public Object clone() { | |
318 try { | |
319 Node clone = (Node)super.clone(); | |
320 clone.setViews(new ArrayList<View>()); | |
321 for(View view : this.views){ | |
322 clone.addView((View)view.clone()); | |
323 } | |
324 return clone; | |
325 } | |
326 catch (CloneNotSupportedException e) { | |
327 throw new InternalError(e.toString()); | |
328 } | |
329 } | |
330 | |
331 public Boolean getIsPublic() { | |
332 return isPublic; | |
333 } | |
334 | |
335 public void setIsPublic(Boolean isPublic) { | |
336 this.isPublic = isPublic; | |
337 } | |
338 | |
339 public String getPrivacity(){ | |
340 if(isPublic != null) | |
341 return (isPublic) ? "public" : "private"; | |
342 return "private"; | |
343 } | |
344 | |
345 @Override | |
346 public boolean equals(Object object) { | |
347 // TODO: Warning - this method won't work in the case the id fields are not set | |
348 if (!(object instanceof Node)) { | |
349 return false; | |
350 } | |
351 Node other = (Node) object; | |
352 | |
353 if(this.rowId != null && other.rowId != null && this.rowId.longValue() == other.rowId.longValue()) | |
354 return true; | |
355 | |
356 /* | |
357 if ((this.rowId == null && other.rowId != null) || (this.rowId != null && !this.rowId.equals(other.rowId))) { | |
358 return false; | |
359 }*/ | |
360 return false; | |
361 } | |
362 | |
363 @Override | |
364 public String toString() { | |
25
c23ae718fdd3
clean up and more logging when saving attributes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
365 String rowIdString = (this.getRowId() == null) ? "" : "rowId=" + this.getRowId() + ", "; |
c23ae718fdd3
clean up and more logging when saving attributes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
366 String idString = (this.getId() == null) ? "" : "id=" + getId() + ", "; |
1 | 367 |
25
c23ae718fdd3
clean up and more logging when saving attributes.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
368 return "Node[" + rowIdString + idString + "name=" + this.getObjectClass() + ", ownValue=" + this.getOwnValue() + ", sysStatus=" + this.getSystemStatus() + "]"; |
1 | 369 } |
370 } |