001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: */
016: package org.kuali.kfs.service;
017:
018: import java.io.File;
019: import java.io.FileNotFoundException;
020: import java.io.InputStream;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import org.kuali.core.bo.user.UniversalUser;
025: import org.kuali.core.exceptions.AuthorizationException;
026: import org.kuali.kfs.batch.BatchInputFileSetType;
027: import org.kuali.kfs.exceptions.FileStorageException;
028:
029: /**
030: * This interface defines the methods needed to save/download/delete file sets in the batch upload system
031: */
032: public interface BatchInputFileSetService {
033:
034: /**
035: * Stores the input streams (the values in the Map parameter) as files on the server, identified by the given user file name and
036: * file user identifier
037: *
038: * @param user - user who is requesting the save
039: * @param inputType - instance of a BatchInputFileSetType
040: * @param fileUserIdentifer - file identifier specified by user
041: * @param typeToStreamMap - contents of the uploaded files, keyed by the input file type
042: * @return a Map of type to file name mappings of the saved files
043: * @throws FileStorageException - if errors were encountered while attempting to write the file
044: */
045: public Map<String, String> save(UniversalUser user,
046: BatchInputFileSetType inputType, String fileUserIdentifer,
047: Map<String, InputStream> typeToStreamMap,
048: boolean suppressDoneFileCreation)
049: throws AuthorizationException, FileStorageException;
050:
051: /**
052: * Returns the contents of a batch input file contained on the server if the user has permissions for the files batch input
053: * type.
054: *
055: * @param user - user who is requesting the download
056: * @param inputType - instance of a BatchInputFileSetType
057: * @param fileType - the type of the file to retrieve
058: * @param fileUserIdentifier file identifier specified by user
059: * @return File - File representation of the batch input, or null if errors occured. Check GlobalVariables.errorMap for error
060: * messages.
061: * @throws AuthorizationException - if user does not have permission to view batch files of this type FileNotFoundException - if
062: * given file does not exist on the file system
063: */
064: public File download(UniversalUser user,
065: BatchInputFileSetType inputType, String fileType,
066: String fileUserIdentifier) throws AuthorizationException,
067: FileNotFoundException;
068:
069: /**
070: * Deletes a batch input file contained on the server if the user has permissions for the files batch input type. Also deletes
071: * the associated .done file if one exists. If the file set may not be deleted, then the GlobalVariable's error map will be
072: * populated with the reason why.
073: *
074: * @param user - user who is requesting the delete
075: * @param inputType - instance of a BatchInputFileSetType
076: * @param fileUserIdentifier file identifier specified by user
077: * @return whether the file was successfully downloaded
078: * @throws AuthorizationException - if user does not have permission to delete batch files of this type FileNotFoundException -
079: * if given file does not exist on the file system
080: */
081: public boolean delete(UniversalUser user,
082: BatchInputFileSetType inputType, String fileUserIdentifier)
083: throws AuthorizationException, FileNotFoundException;
084:
085: /**
086: * Checks if the batch input type is active (can be used for upload).
087: *
088: * @param BatchInputFileSetType - input type to check is active
089: * @return boolean - true if type is active, false if not active
090: */
091: public boolean isBatchInputTypeActive(
092: BatchInputFileSetType batchInputFileSetType);
093:
094: /**
095: * Checks if the user has permissions to manage the batch input type.
096: *
097: * @param batchInputFileSetType - input type to check user permissions on
098: * @param user - user to check
099: * @return boolean - true if user has permissions for the type, false if the user does not have permission
100: */
101: public boolean isUserAuthorizedForBatchType(
102: BatchInputFileSetType batchInputFileSetType,
103: UniversalUser user);
104:
105: /**
106: * Returns a list of batch type file names (including path) that the given user has permissions to manage.
107: *
108: * @param user - user for checking permissions
109: * @return List<String> - List of filenames
110: */
111: public Set<String> listBatchTypeFileUserIdentifiersForUser(
112: BatchInputFileSetType batchInputFileSetType,
113: UniversalUser user) throws AuthorizationException;
114:
115: /**
116: * Returns whether a file set identifier is properly formatted.
117: *
118: * @param fileUserIdentifier
119: * @return
120: */
121: public boolean isFileUserIdentifierProperlyFormatted(
122: String fileUserIdentifier);
123:
124: /**
125: * Returns whether a file set for a given user has already been processed
126: *
127: * @param user
128: * @param inputType
129: * @param fileUserIdentifier
130: * @return
131: */
132: public boolean hasBeenProcessed(UniversalUser user,
133: BatchInputFileSetType inputType, String fileUserIdentifier);
134: }
|