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