1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.notes.service.impl; |
17 | |
|
18 | |
import java.io.File; |
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import org.kuali.rice.kew.notes.Attachment; |
23 | |
import org.kuali.rice.kew.notes.Note; |
24 | |
import org.kuali.rice.kew.notes.dao.NoteDAO; |
25 | |
import org.kuali.rice.kew.notes.service.AttachmentService; |
26 | |
import org.kuali.rice.kew.notes.service.NoteService; |
27 | |
|
28 | |
|
29 | 0 | public class NoteServiceImpl implements NoteService { |
30 | |
|
31 | |
private NoteDAO noteDAO; |
32 | |
|
33 | |
private AttachmentService attachmentService; |
34 | |
|
35 | |
public Note getNoteByNoteId(String noteId) { |
36 | 0 | return getNoteDAO().getNoteByNoteId(noteId); |
37 | |
} |
38 | |
|
39 | |
public List<Note> getNotesByDocumentId(String documentId) { |
40 | 0 | return getNoteDAO().getNotesByDocumentId(documentId); |
41 | |
} |
42 | |
|
43 | |
public void saveNote(Note note) { |
44 | |
try { |
45 | 0 | if (! note.getAttachments().isEmpty()){ |
46 | 0 | for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) { |
47 | 0 | Attachment attachment = (Attachment) iter.next(); |
48 | 0 | if (attachment.getAttachedObject()!= null){ |
49 | 0 | attachmentService.persistAttachedFileAndSetAttachmentBusinessObjectValue(attachment); |
50 | |
} |
51 | 0 | } |
52 | |
} |
53 | 0 | getNoteDAO().saveNote(note); |
54 | 0 | } catch (Exception e) { |
55 | 0 | throw new RuntimeException(e); |
56 | 0 | } |
57 | 0 | } |
58 | |
|
59 | |
public void deleteNote(Note note) { |
60 | |
try { |
61 | 0 | for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) { |
62 | 0 | Attachment attachment = (Attachment) iter.next(); |
63 | 0 | attachmentService.deleteAttachedFile(attachment); |
64 | 0 | } |
65 | 0 | getNoteDAO().deleteNote(note); |
66 | 0 | } catch (Exception e) { |
67 | 0 | throw new RuntimeException("caught exception deleting attachment", e); |
68 | 0 | } |
69 | 0 | } |
70 | |
|
71 | |
public NoteDAO getNoteDAO() { |
72 | 0 | return noteDAO; |
73 | |
} |
74 | |
|
75 | |
public void setNoteDAO(NoteDAO noteDAO) { |
76 | 0 | this.noteDAO = noteDAO; |
77 | 0 | } |
78 | |
|
79 | |
public void deleteAttachment(Attachment attachment) { |
80 | 0 | this.noteDAO.deleteAttachment(attachment); |
81 | |
try { |
82 | 0 | attachmentService.deleteAttachedFile(attachment); |
83 | 0 | } catch (Exception e) { |
84 | 0 | throw new RuntimeException("caught exception deleting attachment", e); |
85 | 0 | } |
86 | 0 | } |
87 | |
|
88 | |
public File findAttachmentFile(Attachment attachment) { |
89 | |
try { |
90 | 0 | return attachmentService.findAttachedFile(attachment); |
91 | 0 | } catch (Exception e) { |
92 | 0 | throw new RuntimeException(e); |
93 | |
} |
94 | |
|
95 | |
} |
96 | |
|
97 | |
public Attachment findAttachment(String attachmentId) { |
98 | 0 | return noteDAO.findAttachment(attachmentId); |
99 | |
} |
100 | |
|
101 | |
public AttachmentService getAttachmentService() { |
102 | 0 | return attachmentService; |
103 | |
} |
104 | |
|
105 | |
public void setAttachmentService(AttachmentService attachmentService) { |
106 | 0 | this.attachmentService = attachmentService; |
107 | 0 | } |
108 | |
} |