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.krad.service;
017
018import org.kuali.rice.krad.bo.Attachment;
019import org.kuali.rice.krad.bo.Note;
020import org.kuali.rice.krad.bo.PersistableBusinessObject;
021
022import java.io.IOException;
023import java.io.InputStream;
024
025/**
026 * Defines the methods common to all AttachmentService implementations
027 *
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030public interface AttachmentService {
031    /**
032     * Stores the given fileContents and returns referring Attachment object which acts as a momento to the archived object.
033     *
034     * @param parent - the document to which the attachment belongs
035     * @param uploadedFileName - the name of the uploaded file
036     * @param mimeType - the uploaded file's mime type
037     * @param  fileSize - the size of the uploaded file in bytes
038     * @param  fileContents - an input stream used to read the file's contents
039     * @param attachmentType -the attachment type code
040     *
041     * @return Attachment - the attachment, having been written to the file system
042     * @throws IOException
043     */
044    public Attachment createAttachment(PersistableBusinessObject parent, String uploadedFileName, String mimeType, int fileSize, InputStream fileContents, String attachmentType) throws IOException;
045
046    /**
047     * Retrieves a given Attachments contents from the corresponding Attachment object
048     *
049     * @param attachment - the attachment whose contents are to be retrieved
050     *
051     * @return OutputStream
052     * @throws IOException
053     */
054    public InputStream retrieveAttachmentContents(Attachment attachment) throws IOException;
055
056    /**
057     * Deletes a given DocumentAttachment contents from the corresponding Attachment object
058     *
059     * @param attachment - the attachment whose contents are to be deleted
060     */
061    public void deleteAttachmentContents(Attachment attachment);
062    
063    /**
064     * 
065     * Moves attachments on notes from the pending directory to the real one
066     * @param note the Note from which to move attachments.  If this Note does not
067     * have an attachment then this method does nothing.
068     * 
069     * @throws IllegalArgumentException if the given Note is null
070     * @throws IllegalArgumentException if the Note does not have a valid object id
071     */
072    public void moveAttachmentWherePending(Note note);
073    
074    /**
075     * Deletes pending attachments that were last modified before the given time.  Java does not have easy access to a file's creation
076     * time, so we use modification time instead.
077     * 
078     * @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
079     *  methods return time in this format.  If a pending attachment was modified before this time, then it will be deleted (unless an error occurs)
080     */
081    public void deletePendingAttachmentsModifiedBefore(long modificationTime);
082    
083    public Attachment getAttachmentByNoteId(Long noteId);
084}