use of org.kuali.kfs.sys.exception.FileStorageException in project cu-kfs by CU-CommunityApps.
the class CuBatchInputFileServiceImpl method save.
@Override
public String save(Person user, BatchInputFileType batchInputFileType, String fileUserIdentifier, InputStream fileContents, Object parsedObject) throws FileStorageException {
if (user == null || batchInputFileType == null || fileContents == null) {
LOG.error(INVALID_ARGUEMENT);
throw new IllegalArgumentException(INVALID_ARGUEMENT);
}
if (!isFileUserIdentifierProperlyFormatted(fileUserIdentifier)) {
LOG.error(NOT_PROPERLY_FORMATTED + fileUserIdentifier);
throw new IllegalArgumentException(NOT_PROPERLY_FORMATTED + fileUserIdentifier);
}
// defer to batch input type to add any security or other needed information to the file name
String saveFileName = batchInputFileType.getDirectoryPath() + "/" + batchInputFileType.getFileName(user.getPrincipalName(), parsedObject, fileUserIdentifier);
if (!StringUtils.isBlank(batchInputFileType.getFileExtension())) {
saveFileName += "." + batchInputFileType.getFileExtension();
}
// construct the file object and check for existence
File fileToSave = new File(saveFileName);
if (fileToSave.exists()) {
LOG.error("cannot store file, name already exists " + saveFileName);
throw new FileStorageException("Cannot store file because the name " + saveFileName + " already exists on the file system.");
}
try {
FileOutputStream fos = new FileOutputStream(fileToSave);
while (fileContents.available() > 0) {
fos.write(fileContents.read());
}
fos.flush();
fos.close();
// isDoneFileRequired function.
if (!(batchInputFileType instanceof CuBatchInputFileType) || ((CuBatchInputFileType) batchInputFileType).isDoneFileRequired()) {
createDoneFile(fileToSave, batchInputFileType);
}
// CU Mod
batchInputFileType.process(saveFileName, parsedObject);
} catch (IOException e) {
LOG.error("unable to save contents to file " + saveFileName, e);
throw new RuntimeException("errors encountered while writing file " + saveFileName, e);
}
return saveFileName;
}
use of org.kuali.kfs.sys.exception.FileStorageException in project cu-kfs by CU-CommunityApps.
the class ConcurRequestExtractFileServiceImpl method processFile.
public boolean processFile(String requestExtractFullyQualifiedFileName) {
boolean processingSuccessful = false;
ConcurRequestExtractFile requestExtractFile = loadFileIntoParsedDataObject(requestExtractFullyQualifiedFileName);
ConcurRequestExtractBatchReportData reportData = new ConcurRequestExtractBatchReportData();
reportData.setConcurFileName(parseRequestExtractFileNameFrom(requestExtractFullyQualifiedFileName));
if (getConcurRequestExtractFileValidationService().requestExtractHeaderRowValidatesToFileContents(requestExtractFile, reportData)) {
List<String> uniqueRequestIdsInFile = new ArrayList<String>();
for (ConcurRequestExtractRequestDetailFileLine detailFileLine : requestExtractFile.getRequestDetails()) {
getConcurRequestExtractFileValidationService().performRequestDetailLineValidation(detailFileLine, uniqueRequestIdsInFile);
}
requestExtractFile.setFileName(parseRequestExtractFileNameFrom(requestExtractFullyQualifiedFileName));
processingSuccessful = getConcurCashAdvancePdpFeedFileService().createPdpFeedFileForValidatedDetailFileLines(requestExtractFile, reportData);
if (processingSuccessful && StringUtils.isNotBlank(requestExtractFile.getFullyQualifiedPdpFileName())) {
try {
getConcurCashAdvancePdpFeedFileService().createDoneFileForPdpFile(requestExtractFile.getFullyQualifiedPdpFileName());
} catch (IOException ioe) {
LOG.error("processFile: ConcurCashAdvancePdpFeedFileService().createDoneFileForPdpFile generated IOException attempting to create .done file for generated PdpFeedFile: " + requestExtractFile.getFullyQualifiedPdpFileName());
processingSuccessful = false;
} catch (FileStorageException fse) {
LOG.error("processFile: ConcurCashAdvancePdpFeedFileService().createDoneFileForPdpFile generated FileStorageException attempting to create .done file for generated PdpFeedFile: " + requestExtractFile.getFullyQualifiedPdpFileName());
processingSuccessful = false;
}
}
}
File reportFile = getConcurRequestExtractReportService().generateReport(reportData);
getConcurRequestExtractReportService().sendResultsEmail(reportData, reportFile);
LOG.debug("method processFile:: requestExtractFile data after processing: " + KFSConstants.NEWLINE + requestExtractFile.toString());
return processingSuccessful;
}
use of org.kuali.kfs.sys.exception.FileStorageException in project cu-kfs by CU-CommunityApps.
the class DisencumbranceKualiBatchInputFileSetAction method save.
/**
* Override method to create a disencumbrance file for upload
*
* @see org.kuali.kfs.sys.web.struts.KualiBatchInputFileSetAction#save(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
DisencumbranceKualiBatchInputFileSetForm batchInputFileSetForm = (DisencumbranceKualiBatchInputFileSetForm) form;
BatchUpload batchUpload = ((KualiBatchInputFileSetForm) form).getBatchUpload();
BatchInputFileSetType batchType = retrieveBatchInputFileSetTypeImpl(batchUpload.getBatchInputTypeName());
boolean requiredValuesForFilesMissing = false;
boolean errorCreatingDisencFile = false;
if (StringUtils.isBlank(batchUpload.getFileUserIdentifer())) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SET_IDENTIFIER_SELECTED, new String[] {});
requiredValuesForFilesMissing = true;
}
BatchInputFileSetService batchInputFileSetService = SpringContext.getBean(BatchInputFileSetService.class);
if (!batchInputFileSetService.isFileUserIdentifierProperlyFormatted(batchUpload.getFileUserIdentifer())) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_SET_IDENTIFIER_BAD_FORMAT);
requiredValuesForFilesMissing = true;
}
Map<String, InputStream> typeToStreamMap = new HashMap<String, InputStream>();
String path = CUKFSConstants.STAGING_DIR + System.getProperty("file.separator") + CUKFSConstants.LD_DIR + System.getProperty("file.separator") + CUKFSConstants.ENTERPRISE_FEED_DIR;
String selectedDataFile = batchInputFileSetForm.getSelectedDataFile();
if (StringUtils.isNotEmpty(selectedDataFile)) {
String dataFilePath = BatchFileUtils.resolvePathToAbsolutePath(path + System.getProperty("file.separator") + selectedDataFile);
File dataFile = new File(dataFilePath).getAbsoluteFile();
if (dataFile == null) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SELECTED_SAVE_FOR_FILE_TYPE, new String[] { batchType.getFileTypeDescription().get(KFSConstants.DATA_FILE_TYPE) });
requiredValuesForFilesMissing = true;
} else {
// call service to create disencumbrance
LaborLedgerEnterpriseFeedService ldService = SpringContext.getBean(LaborLedgerEnterpriseFeedService.class);
InputStream disencumFileInputStream = null;
disencumFileInputStream = ldService.createDisencumbrance(new FileInputStream(dataFile));
if (disencumFileInputStream == null) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CUKFSKeyConstants.MESSAGE_CREATE_DISENCUMBRANCE_ERROR);
errorCreatingDisencFile = true;
} else {
typeToStreamMap.put(KFSConstants.DATA_FILE_TYPE, disencumFileInputStream);
}
}
}
String selectedReconFile = batchInputFileSetForm.getSelectedReconFile();
if (StringUtils.isNotEmpty(selectedReconFile)) {
String reconFilePath = BatchFileUtils.resolvePathToAbsolutePath(path + System.getProperty("file.separator") + selectedReconFile);
File reconFile = new File(reconFilePath).getAbsoluteFile();
if (reconFile == null) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SELECTED_SAVE_FOR_FILE_TYPE, new String[] { batchType.getFileTypeDescription().get(KFSConstants.RECON_FILE_TYPE) });
requiredValuesForFilesMissing = true;
} else {
typeToStreamMap.put(KFSConstants.RECON_FILE_TYPE, new FileInputStream(reconFile));
}
}
if (requiredValuesForFilesMissing || errorCreatingDisencFile) {
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
try {
Map<String, String> typeToSavedFileNames = batchInputFileSetService.save(GlobalVariables.getUserSession().getPerson(), batchType, batchUpload.getFileUserIdentifer(), typeToStreamMap);
} catch (FileStorageException e) {
LOG.error("Error occured while trying to save file set (probably tried to save a file that already exists).", e);
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_SAVE_ERROR, new String[] { e.getMessage() });
return mapping.findForward(KFSConstants.MAPPING_BASIC);
} catch (ValidationException e) {
LOG.error("Error occured while trying to validate file set.", e);
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_VALIDATION_ERROR);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
KNSGlobalVariables.getMessageList().add(CUKFSKeyConstants.MESSAGE_CREATE_DISENCUMBRANCE_SUCCESSFUL);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.sys.exception.FileStorageException in project cu-kfs by CU-CommunityApps.
the class TransactionOverrideCsvBatchInputFileType method writeValidationErrorFile.
/**
* Prints the header line and the problem lines to a separate file;
* should only be called if one or more override lines contained errors.
*
* @param fileName The filename and path to use; typically the name that would have been used if the parser's shouldSave() method had returned true.
* @param invalidLines The error lines that should be printed to the file.
*/
protected void writeValidationErrorFile(String fileName, List<String> invalidLines) {
fileName = fileName.substring(0, fileName.lastIndexOf('.')) + "_error" + fileName.substring(fileName.lastIndexOf('.'));
File errorFile = new File(fileName);
if (errorFile.exists()) {
throw new FileStorageException("Transaction override error file already exists: " + fileName);
}
BufferedWriter writer = null;
try {
// Create the file, and add a header line and the error lines.
writer = new BufferedWriter(new PrintWriter(errorFile));
writer.write(StringUtils.join(getCsvHeaderList(), '\t'));
writer.write('\n');
for (String invalidLine : invalidLines) {
writer.write(invalidLine);
writer.write('\n');
}
writer.flush();
} catch (IOException e) {
throw new FileStorageException("Encountered error while writing transaction error output file", e);
} finally {
IOUtils.closeQuietly(writer);
}
LOG.warn("Found " + Integer.toString(invalidLines.size()) + " error lines, these have been written to a new error file.");
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CUTaxConstants.CUTaxKeyConstants.ERROR_BATCH_UPLOAD_INVALID_TRANSACTION_OVERRIDES, Integer.toString(invalidLines.size()));
}
Aggregations