001/* 002 * Copyright 2007 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.ole.sys.batch.service; 017 018import java.io.InputStream; 019import java.util.List; 020 021import org.kuali.ole.sys.batch.BatchInputFileType; 022import org.kuali.ole.sys.exception.FileStorageException; 023import org.kuali.rice.kim.api.identity.Person; 024import org.kuali.rice.krad.exception.AuthorizationException; 025 026/** 027 * Interface defining methods to manage batch input files. 028 */ 029public interface BatchInputFileService { 030 /** 031 * Unmarshalls the file contents to an Object using the digestor and digestor rules file specified in the batch input type. 032 * 033 * @param batchInputFileType - batch input file type for the file to parse 034 * @param fileByteContent - byte contents of file to parse 035 * @return - Object built from the file contents based on its xml unmarshalling rules 036 */ 037 public Object parse(BatchInputFileType batchInputFileType, byte[] fileByteContent); 038 039 /** 040 * Using the input type object parses and validates the file contents by calling validate on the batch input type. If there were 041 * validation errors, GlobalVariables.errorMap will contain the error messages. 042 * 043 * @param inputType - instance of a BatchInputFileType 044 * @param parsedObject - the Object built from parsing xml contents 045 * @return boolean - true if validation was successful, false if there were errors 046 */ 047 public boolean validate(BatchInputFileType inputType, Object parsedObject); 048 /** 049 * Stores the inputstream as a file on the server, identified by the given user file name. 050 * 051 * @param user - user who is requesting the save 052 * @param inputType - instance of a BatchInputFileType 053 * @param fileUserIdentifier - file identifier specified by user 054 * @param fileContents - contents of the uploaded file 055 * @param parsedObject - object parsed from the input file 056 * @return String - name of file that was saved, or null if errors were enountered 057 * @throws FileStorageException - if errors were encountered while attempting to write the file 058 */ 059 public String save(Person user, BatchInputFileType inputType, String fileUserIdentifier, InputStream fileContents, Object parsedObject) throws AuthorizationException, FileStorageException; 060 061 /** 062 * Stores the inputstream as a file on the server, identified by the given user file name. 063 * 064 * @param user - user who is requesting the save 065 * @param inputType - instance of a BatchInputFileType 066 * @param fileUserIdentifier - file identifier specified by user 067 * @param fileContents - contents of the uploaded file 068 * @param parsedObject - object parsed from the input file 069 * @param destinationFilePath - destination path selected by user for storing the ole format xml. 070 * @param extension - extension of the file selected through marc file upload screen 071 * @return String - name of file that was saved, or null if errors were enountered 072 * @throws FileStorageException - if errors were encountered while attempting to write the file 073 */ 074 public String save(Person user, BatchInputFileType inputType, String fileUserIdentifier, InputStream fileContents, Object parsedObject,String destinationFilePath,String extension) throws AuthorizationException, FileStorageException; 075 076 /** 077 * Checks if the batch input type is active (can be used for upload). 078 * 079 * @param batchInputFileType - input type to check is active 080 * @return boolean - true if type is active, false if not active 081 */ 082 public boolean isBatchInputTypeActive(BatchInputFileType batchInputFileType); 083 084 /** 085 * Returns a list of batch type file names (without path) that the given user has permissions to manage. Path is intentionally 086 * excluded to prevent security problems arising from giving users access to the full path. 087 * 088 * @param user - user for checking permissions 089 * @return List<String> - List of filenames 090 */ 091 public List<String> listBatchTypeFilesForUser(BatchInputFileType batchInputFileType, Person user) throws AuthorizationException; 092 093 /** 094 * Returns a list of existing input files for the batch type that have an associated .done file 095 * 096 * @param batchInputFileType - batch type to retieve files for 097 * @return List<String> - List of filenames 098 */ 099 public List<String> listInputFileNamesWithDoneFile(BatchInputFileType batchInputFileType); 100 101 /** 102 * Returns whether a file user identifier is properly formatted. 103 * 104 * @param fileUserIdentifier 105 * @return 106 */ 107 public boolean isFileUserIdentifierProperlyFormatted(String fileUserIdentifier); 108 109} 110