1 /**
2 * Copyright 2005-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.service;
17
18 import org.kuali.rice.krad.bo.Attachment;
19 import org.kuali.rice.krad.bo.Note;
20 import org.kuali.rice.krad.bo.PersistableBusinessObject;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24
25 /**
26 * Defines the methods common to all AttachmentService implementations
27 *
28 * @author Kuali Rice Team (rice.collab@kuali.org)
29 */
30 public interface AttachmentService {
31 /**
32 * Stores the given fileContents and returns referring Attachment object which acts as a momento to the archived object.
33 *
34 * @param parent - the document to which the attachment belongs
35 * @param uploadedFileName - the name of the uploaded file
36 * @param mimeType - the uploaded file's mime type
37 * @param fileSize - the size of the uploaded file in bytes
38 * @param fileContents - an input stream used to read the file's contents
39 * @param attachmentType -the attachment type code
40 *
41 * @return Attachment - the attachment, having been written to the file system
42 * @throws IOException
43 */
44 public Attachment createAttachment(PersistableBusinessObject parent, String uploadedFileName, String mimeType, int fileSize, InputStream fileContents, String attachmentType) throws IOException;
45
46 /**
47 * Retrieves a given Attachments contents from the corresponding Attachment object
48 *
49 * @param attachment - the attachment whose contents are to be retrieved
50 *
51 * @return OutputStream
52 * @throws IOException
53 */
54 public InputStream retrieveAttachmentContents(Attachment attachment) throws IOException;
55
56 /**
57 * Deletes a given DocumentAttachment contents from the corresponding Attachment object
58 *
59 * @param attachment - the attachment whose contents are to be deleted
60 */
61 public void deleteAttachmentContents(Attachment attachment);
62
63 /**
64 *
65 * Moves attachments on notes from the pending directory to the real one
66 * @param note the Note from which to move attachments. If this Note does not
67 * have an attachment then this method does nothing.
68 *
69 * @throws IllegalArgumentException if the given Note is null
70 * @throws IllegalArgumentException if the Note does not have a valid object id
71 */
72 public void moveAttachmentWherePending(Note note);
73
74 /**
75 * Deletes pending attachments that were last modified before the given time. Java does not have easy access to a file's creation
76 * time, so we use modification time instead.
77 *
78 * @param modificationTime the number of milliseconds since "the epoch" (i.e.January 1, 1970, 00:00:00 GMT). java.util.Date and java.util.Calendar's
79 * methods return time in this format. If a pending attachment was modified before this time, then it will be deleted (unless an error occurs)
80 */
81 public void deletePendingAttachmentsModifiedBefore(long modificationTime);
82
83 public Attachment getAttachmentByNoteId(Long noteId);
84 }