001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kew.notes.service.impl; 017 018import java.io.File; 019import java.util.Iterator; 020import java.util.List; 021 022import org.kuali.rice.kew.notes.Attachment; 023import org.kuali.rice.kew.notes.Note; 024import org.kuali.rice.kew.notes.dao.NoteDAO; 025import org.kuali.rice.kew.notes.service.AttachmentService; 026import org.kuali.rice.kew.notes.service.NoteService; 027import org.kuali.rice.krad.data.DataObjectService; 028import org.springframework.beans.factory.annotation.Required; 029 030public class NoteServiceImpl implements NoteService { 031 032 private NoteDAO noteDAO; 033 034 private AttachmentService attachmentService; 035 036 private DataObjectService dataObjectService; 037 038 public Note getNoteByNoteId(String noteId) { 039 return getDataObjectService().find(Note.class,noteId); 040 } 041 042 public List<Note> getNotesByDocumentId(String documentId) { 043 return getNoteDAO().getNotesByDocumentId(documentId); 044 } 045 046 public Note saveNote(Note note) { 047 try { 048 if (! note.getAttachments().isEmpty()){ 049 for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) { 050 Attachment attachment = (Attachment) iter.next(); 051 if (attachment.getAttachedObject()!= null){ 052 attachmentService.persistAttachedFileAndSetAttachmentBusinessObjectValue(attachment); 053 } 054 } 055 } 056 return getDataObjectService().save(note); 057 } catch (Exception e) { 058 throw new RuntimeException(e); 059 } 060 } 061 062 public void deleteNote(Note note) { 063 try { 064 if (note != null && !note.getAttachments().isEmpty()){ 065 for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) { 066 Attachment attachment = (Attachment) iter.next(); 067 attachmentService.deleteAttachedFile(attachment); 068 } 069 } 070 if (note != null) { 071 getDataObjectService().delete(note); 072 } 073 } catch (Exception e) { 074 throw new RuntimeException("caught exception deleting attachment", e); 075 } 076 } 077 078 public void deleteAttachment(Attachment attachment) { 079 getDataObjectService().delete(attachment); 080 try { 081 attachmentService.deleteAttachedFile(attachment); 082 } catch (Exception e) { 083 throw new RuntimeException("caught exception deleting attachment", e); 084 } 085 } 086 087 public File findAttachmentFile(Attachment attachment) { 088 try { 089 return attachmentService.findAttachedFile(attachment); 090 } catch (Exception e) { 091 throw new RuntimeException(e); 092 } 093 094 } 095 096 public Attachment findAttachment(String attachmentId) { 097 return getDataObjectService().find(Attachment.class,attachmentId); 098 } 099 100 public AttachmentService getAttachmentService() { 101 return attachmentService; 102 } 103 104 public void setAttachmentService(AttachmentService attachmentService) { 105 this.attachmentService = attachmentService; 106 } 107 108 public DataObjectService getDataObjectService() { 109 return dataObjectService; 110 } 111 112 @Required 113 public void setDataObjectService(DataObjectService dataObjectService) { 114 this.dataObjectService = dataObjectService; 115 } 116 117 public NoteDAO getNoteDAO() { 118 return noteDAO; 119 } 120 121 public void setNoteDAO(NoteDAO noteDAO) { 122 this.noteDAO = noteDAO; 123 } 124}