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