View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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  public class NoteServiceImpl implements NoteService {
31  
32  	private NoteDAO noteDAO;
33  
34  	private AttachmentService attachmentService;
35  
36  	public Note getNoteByNoteId(Long noteId) {
37  		return getNoteDAO().getNoteByNoteId(noteId);
38  	}
39  
40  	public List getNotesByRouteHeaderId(Long routeHeaderId) {
41  		return getNoteDAO().getNotesByRouteHeaderId(routeHeaderId);
42  	}
43  
44  	public void saveNote(Note note) {
45  		try {
46  			if (! note.getAttachments().isEmpty()){
47  				for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) {
48  					Attachment attachment = (Attachment) iter.next();
49  					if (attachment.getAttachedObject()!= null){
50  						attachmentService.persistAttachedFileAndSetAttachmentBusinessObjectValue(attachment);
51  					}
52  				}
53  			}
54  			getNoteDAO().saveNote(note);
55  		} catch (Exception e) {
56  			throw new RuntimeException(e);
57  		}
58  	}
59  
60  	public void deleteNote(Note note) {
61  		try {
62  			for (Iterator iter = note.getAttachments().iterator(); iter.hasNext();) {
63  				Attachment attachment = (Attachment) iter.next();
64  				attachmentService.deleteAttachedFile(attachment);
65  			}
66  			getNoteDAO().deleteNote(note);
67  		} catch (Exception e) {
68  			throw new RuntimeException("caught exception deleting attachment", e);
69  		}
70  	}
71  
72  	public NoteDAO getNoteDAO() {
73  		return noteDAO;
74  	}
75  
76  	public void setNoteDAO(NoteDAO noteDAO) {
77  		this.noteDAO = noteDAO;
78  	}
79  
80  	public void deleteAttachment(Attachment attachment) {
81  		this.noteDAO.deleteAttachment(attachment);
82  		try {
83  			attachmentService.deleteAttachedFile(attachment);
84  		} catch (Exception e) {
85  			throw new RuntimeException("caught exception deleting attachment", e);
86  		}
87  	}
88  
89  	public File findAttachmentFile(Attachment attachment) {
90  		try {
91  			return attachmentService.findAttachedFile(attachment);
92  		} catch (Exception e) {
93  			throw new RuntimeException(e);
94  		}
95  
96  	}
97  
98  	public Attachment findAttachment(Long attachmentId) {
99  		return noteDAO.findAttachment(attachmentId);
100 	}
101 
102 	public AttachmentService getAttachmentService() {
103 		return attachmentService;
104 	}
105 
106 	public void setAttachmentService(AttachmentService attachmentService) {
107 		this.attachmentService = attachmentService;
108 	}
109 }