001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kew.notes.service.impl; 017 018 import java.io.File; 019 import java.util.Iterator; 020 import java.util.List; 021 022 import org.kuali.rice.kew.notes.Attachment; 023 import org.kuali.rice.kew.notes.Note; 024 import org.kuali.rice.kew.notes.dao.NoteDAO; 025 import org.kuali.rice.kew.notes.service.AttachmentService; 026 import org.kuali.rice.kew.notes.service.NoteService; 027 028 029 public class NoteServiceImpl implements NoteService { 030 031 private NoteDAO noteDAO; 032 033 private AttachmentService attachmentService; 034 035 public Note getNoteByNoteId(String noteId) { 036 return getNoteDAO().getNoteByNoteId(noteId); 037 } 038 039 public List<Note> getNotesByDocumentId(String documentId) { 040 return getNoteDAO().getNotesByDocumentId(documentId); 041 } 042 043 public void saveNote(Note note) { 044 try { 045 if (! note.getAttachments().isEmpty()){ 046 for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) { 047 Attachment attachment = (Attachment) iter.next(); 048 if (attachment.getAttachedObject()!= null){ 049 attachmentService.persistAttachedFileAndSetAttachmentBusinessObjectValue(attachment); 050 } 051 } 052 } 053 getNoteDAO().saveNote(note); 054 } catch (Exception e) { 055 throw new RuntimeException(e); 056 } 057 } 058 059 public void deleteNote(Note note) { 060 try { 061 if (note != null && !note.getAttachments().isEmpty()){ 062 for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) { 063 Attachment attachment = (Attachment) iter.next(); 064 attachmentService.deleteAttachedFile(attachment); 065 } 066 } 067 if (note != null) { 068 getNoteDAO().deleteNote(note); 069 } 070 } catch (Exception e) { 071 throw new RuntimeException("caught exception deleting attachment", e); 072 } 073 } 074 075 public NoteDAO getNoteDAO() { 076 return noteDAO; 077 } 078 079 public void setNoteDAO(NoteDAO noteDAO) { 080 this.noteDAO = noteDAO; 081 } 082 083 public void deleteAttachment(Attachment attachment) { 084 this.noteDAO.deleteAttachment(attachment); 085 try { 086 attachmentService.deleteAttachedFile(attachment); 087 } catch (Exception e) { 088 throw new RuntimeException("caught exception deleting attachment", e); 089 } 090 } 091 092 public File findAttachmentFile(Attachment attachment) { 093 try { 094 return attachmentService.findAttachedFile(attachment); 095 } catch (Exception e) { 096 throw new RuntimeException(e); 097 } 098 099 } 100 101 public Attachment findAttachment(String attachmentId) { 102 return noteDAO.findAttachment(attachmentId); 103 } 104 105 public AttachmentService getAttachmentService() { 106 return attachmentService; 107 } 108 109 public void setAttachmentService(AttachmentService attachmentService) { 110 this.attachmentService = attachmentService; 111 } 112 }