1
2
3
4
5
6 package pt.digitalis.dif.utils.extensions.document;
7
8 import java.util.Arrays;
9 import java.util.Date;
10
11
12
13
14
15 public class DocumentRepositoryEntry {
16
17
18
19
20
21
22
23 public static enum Fields {
24
25 BYTE_CONTENT {
26
27 @Override
28 public String toString()
29 {
30 return "ByteContent";
31 }
32 },
33
34 CREATION_DATE {
35
36 @Override
37 public String toString()
38 {
39 return "Date";
40 }
41 },
42
43 CREATOR {
44
45 @Override
46 public String toString()
47 {
48 return "Creator";
49 }
50 },
51
52 DESCRIPTION {
53
54 @Override
55 public String toString()
56 {
57 return "Description";
58 }
59 },
60
61 FILENAME {
62
63 @Override
64 public String toString()
65 {
66 return "FileName";
67 }
68 },
69
70 ID {
71
72 @Override
73 public String toString()
74 {
75 return "Id";
76 }
77 },
78
79
80 MIMETYPE {
81
82 @Override
83 public String toString()
84 {
85 return "MimeType";
86 }
87 },
88
89 NAME {
90
91 @Override
92 public String toString()
93 {
94 return "Name";
95 }
96 }
97 }
98
99
100 private static final String BINARY_MIME_TYPE = "binary";
101
102
103 private byte[] bytes;
104
105
106 private Date creationDate;
107
108
109 private String creatorID;
110
111
112
113
114
115 private boolean deleteRequested;
116
117
118 private String description;
119
120
121 private String fileName;
122
123
124 private Long id;
125
126
127 private String mimeType;
128
129
130 private String name;
131
132
133
134
135 public DocumentRepositoryEntry()
136 {
137 super();
138
139 creationDate = new Date();
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 public DocumentRepositoryEntry(Long id, String creatorID, String name, String description, String fileName,
163 Date creationDate, String mimeType, byte[] bytes)
164 {
165 this.id = id;
166 this.creatorID = creatorID;
167 this.name = name;
168 this.description = description;
169 this.fileName = fileName;
170 this.creationDate = creationDate;
171 this.mimeType = mimeType;
172 this.bytes = bytes;
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 public DocumentRepositoryEntry(String creatorID, String name, String description, String fileName,
194 Date creationDate, String mimeType, byte[] bytes)
195 {
196 this.creatorID = creatorID;
197 this.name = name;
198 this.description = description;
199 this.fileName = fileName;
200 this.creationDate = creationDate;
201 this.mimeType = mimeType;
202 this.bytes = bytes;
203 }
204
205
206
207
208 public void calculateMimeType()
209 {
210 if (this.fileName != null)
211 {
212 String[] splitFile = this.fileName.split("\\.");
213 if (splitFile.length >= 2)
214 {
215 this.mimeType = splitFile[splitFile.length - 1];
216
217 }
218 else
219 {
220 this.mimeType = BINARY_MIME_TYPE;
221 }
222 }
223 }
224
225
226
227
228 @Override
229 public boolean equals(Object obj)
230 {
231 if (this == obj)
232 return true;
233 if (obj == null)
234 return false;
235 if (!(obj instanceof DocumentRepositoryEntry))
236 return false;
237 final DocumentRepositoryEntry other = (DocumentRepositoryEntry) obj;
238 if (!Arrays.equals(bytes, other.bytes))
239 return false;
240 if (creationDate == null)
241 {
242 if (other.creationDate != null)
243 return false;
244 }
245 else if (!creationDate.equals(other.creationDate))
246 return false;
247 if (creatorID == null)
248 {
249 if (other.creatorID != null)
250 return false;
251 }
252 else if (!creatorID.equals(other.creatorID))
253 return false;
254 if (description == null)
255 {
256 if (other.description != null)
257 return false;
258 }
259 else if (!description.equals(other.description))
260 return false;
261 if (fileName == null)
262 {
263 if (other.fileName != null)
264 return false;
265 }
266 else if (!fileName.equals(other.fileName))
267 return false;
268 if (id == null)
269 {
270 if (other.id != null)
271 return false;
272 }
273 else if (!id.equals(other.id))
274 return false;
275 if (mimeType == null)
276 {
277 if (other.mimeType != null)
278 return false;
279 }
280 else if (!mimeType.equals(other.mimeType))
281 return false;
282 if (name == null)
283 {
284 if (other.name != null)
285 return false;
286 }
287 else if (!name.equals(other.name))
288 return false;
289 return true;
290 }
291
292
293
294
295
296
297 public byte[] getBytes()
298 {
299 return bytes;
300 }
301
302
303
304
305
306
307 public Date getCreationDate()
308 {
309 return creationDate;
310 }
311
312
313
314
315
316
317 public String getCreatorID()
318 {
319 return creatorID;
320 }
321
322
323
324
325
326
327 public String getDescription()
328 {
329 return description;
330 }
331
332
333
334
335
336
337 public String getFileName()
338 {
339 return fileName;
340 }
341
342
343
344
345
346
347 public Long getId()
348 {
349 return id;
350 }
351
352
353
354
355
356
357 public String getMimeType()
358 {
359 return mimeType;
360 }
361
362
363
364
365
366
367 public String getName()
368 {
369 return name;
370 }
371
372
373
374
375 @Override
376 public int hashCode()
377 {
378 final int prime = 31;
379 int result = 1;
380 result = prime * result + Arrays.hashCode(bytes);
381 result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode());
382 result = prime * result + ((creatorID == null) ? 0 : creatorID.hashCode());
383 result = prime * result + ((description == null) ? 0 : description.hashCode());
384 result = prime * result + ((fileName == null) ? 0 : fileName.hashCode());
385 result = prime * result + ((id == null) ? 0 : id.hashCode());
386 result = prime * result + ((mimeType == null) ? 0 : mimeType.hashCode());
387 result = prime * result + ((name == null) ? 0 : name.hashCode());
388 return result;
389 }
390
391
392
393
394
395
396 public boolean isDeleteRequested()
397 {
398 return deleteRequested;
399 }
400
401
402
403
404
405
406
407 public void setBytes(byte[] bytes)
408 {
409 this.bytes = bytes;
410 }
411
412
413
414
415
416
417
418 public void setCreationDate(Date creationDate)
419 {
420 this.creationDate = creationDate;
421 }
422
423
424
425
426
427
428
429 public void setCreatorID(String creatorID)
430 {
431 this.creatorID = creatorID;
432 }
433
434
435
436
437
438
439
440 public void setDeleteRequested(boolean deleteRequested)
441 {
442 this.deleteRequested = deleteRequested;
443 }
444
445
446
447
448
449
450
451 public void setDescription(String description)
452 {
453 this.description = description;
454 }
455
456
457
458
459
460
461
462 public void setFileName(String fileName)
463 {
464 this.fileName = fileName;
465 }
466
467
468
469
470
471
472
473 public void setId(Long id)
474 {
475 this.id = id;
476 }
477
478
479
480
481
482
483
484 public void setMimeType(String mimeType)
485 {
486 this.mimeType = mimeType;
487 }
488
489
490
491
492
493
494
495 public void setName(String name)
496 {
497 this.name = name;
498 }
499
500 }