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