use of org.kuali.kfs.sys.exception.ParseException in project cu-kfs by CU-CommunityApps.
the class VendorBatchServiceImpl method maintainVendors.
/*
* process each parsed data record and add/update vendor accordingly
*/
private boolean maintainVendors(String fileName, BatchInputFileType batchInputFileType, StringBuilder processResults) {
boolean result = true;
// load up the file into a byte array
byte[] fileByteContent = safelyLoadFileBytes(fileName);
LOG.info("Attempting to parse the file");
Object parsedObject = null;
try {
parsedObject = batchInputFileService.parse(batchInputFileType, fileByteContent);
} catch (ParseException e) {
String errorMessage = "Error parsing batch file: " + e.getMessage();
LOG.error(errorMessage, e);
throw new RuntimeException(errorMessage);
}
// make sure we got the type we expected, then cast it
if (!(parsedObject instanceof List)) {
String errorMessage = "Parsed file was not of the expected type. Expected [" + List.class + "] but got [" + parsedObject.getClass() + "].";
criticalError(errorMessage);
}
List<VendorBatchDetail> vendors = (List<VendorBatchDetail>) parsedObject;
for (VendorBatchDetail vendorBatch : vendors) {
// process each line to add/update vendor accordingly
String returnVal = KFSConstants.EMPTY_STRING;
if (StringUtils.isBlank(vendorBatch.getVendorNumber())) {
processResults.append("add vendor : " + vendorBatch.getLogData() + NEW_LINE);
returnVal = addVendor(vendorBatch);
} else {
processResults.append("update vendor : " + vendorBatch.getLogData() + NEW_LINE);
returnVal = updateVendor(vendorBatch);
}
if (StringUtils.startsWith(returnVal, "Failed request")) {
// TODO : there is error. need to handle here or before exit
LOG.error(returnVal);
result = false;
processResults.append(returnVal + NEW_LINE);
} else {
LOG.info("Document " + returnVal + " routed.");
processResults.append("Document " + returnVal + " routed." + NEW_LINE);
}
}
return result;
}
use of org.kuali.kfs.sys.exception.ParseException in project cu-kfs by CU-CommunityApps.
the class PayeeACHAccountExtractServiceImpl method loadACHBatchDetailFile.
/**
* Processes a single ACH input file.
*/
// Portions of this method are based on the code and logic from CustomerLoadServiceImpl.loadFile
protected List<String> loadACHBatchDetailFile(String inputFileName, BatchInputFileType batchInputFileType) {
List<String> failedRowsErrors = new ArrayList();
byte[] fileByteContent = safelyLoadFileBytes(inputFileName);
LOG.info("loadACHBatchDetailFile: Attempting to parse the file.");
Object parsedObject = null;
try {
parsedObject = batchInputFileService.parse(batchInputFileType, fileByteContent);
} catch (ParseException e) {
String errorMessage = "loadACHBatchDetailFile: Error parsing batch file: " + e.getMessage();
LOG.error(errorMessage, e);
throw new RuntimeException(errorMessage);
}
if (!(parsedObject instanceof List)) {
String errorMessage = "loadACHBatchDetailFile: Parsed file was not of the expected type. Expected [" + List.class + "] but got [" + parsedObject.getClass() + "].";
criticalError(errorMessage);
}
List<PayeeACHAccountExtractDetail> achDetails = (List<PayeeACHAccountExtractDetail>) parsedObject;
for (PayeeACHAccountExtractDetail achDetail : achDetails) {
String error = processACHBatchDetail(achDetail);
if (StringUtils.isNotBlank(error)) {
failedRowsErrors.add(error);
}
}
return failedRowsErrors;
}
use of org.kuali.kfs.sys.exception.ParseException in project cu-kfs by CU-CommunityApps.
the class CuPaymentFileServiceImpl method parsePaymentFile.
@Override
protected PaymentFileLoad parsePaymentFile(BatchInputFileType paymentInputFileType, String incomingFileName, MessageMap errorMap) {
FileInputStream fileContents;
try {
fileContents = new FileInputStream(incomingFileName);
} catch (FileNotFoundException e1) {
LOG.error("file to load not found " + incomingFileName, e1);
throw new RuntimeException("Cannot find the file requested to be loaded " + incomingFileName, e1);
}
// do the parse
PaymentFileLoad paymentFile = null;
try {
byte[] fileByteContent = IOUtils.toByteArray(fileContents);
paymentFile = (PaymentFileLoad) batchInputFileService.parse(paymentInputFileType, fileByteContent);
} catch (IOException e) {
LOG.error("error while getting file bytes: " + e.getMessage(), e);
throw new RuntimeException("Error encountered while attempting to get file bytes: " + e.getMessage(), e);
} catch (ParseException e1) {
LOG.error("Error parsing xml " + e1.getMessage());
errorMap.putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_PARSING_XML, new String[] { e1.getMessage() });
// Get customer object from unparsable file so error email can be sent.
paymentFile = getCustomerProfileFromUnparsableFile(incomingFileName, paymentFile);
}
return paymentFile;
}
use of org.kuali.kfs.sys.exception.ParseException in project cu-kfs by CU-CommunityApps.
the class ProcurementCardLoadFlatTransactionsServiceImpl method loadProcurementCardFile.
/**
* Validates and parses the given file, then stores transactions into a temp table.
*
* @param fileName The name of the file to be parsed.
* @return This method always returns true. An exception is thrown if a problem occurs while loading the file.
*
* @see org.kuali.kfs.fp.batch.service.ProcurementCardCreateDocumentService#loadProcurementCardFile()
*/
@SuppressWarnings("unchecked")
public boolean loadProcurementCardFile(String fileName) {
FileInputStream fileContents;
try {
fileContents = new FileInputStream(fileName);
} catch (FileNotFoundException e1) {
LOG.error("file to parse not found " + fileName, e1);
throw new RuntimeException("Cannot find the file requested to be parsed " + fileName + " " + e1.getMessage(), e1);
}
Collection<?> pcardTransactions = null;
try {
byte[] fileByteContent = IOUtils.toByteArray(fileContents);
pcardTransactions = (Collection<?>) batchInputFileService.parse(procurementCardInputFileType, fileByteContent);
} catch (IOException e) {
LOG.error("error while getting file bytes: " + e.getMessage(), e);
throw new RuntimeException("Error encountered while attempting to get file bytes: " + e.getMessage(), e);
} catch (ParseException e) {
LOG.error(ERROR_PREFIX + e.getMessage());
throw new RuntimeException(ERROR_PREFIX + e.getMessage(), e);
}
if (pcardTransactions == null || pcardTransactions.isEmpty()) {
LOG.warn("No PCard transactions in input file " + fileName);
}
loadTransactions((List<? extends PersistableBusinessObject>) pcardTransactions);
LOG.info("Total transactions loaded: " + Integer.toString(pcardTransactions.size()));
return true;
}
use of org.kuali.kfs.sys.exception.ParseException in project cu-kfs by CU-CommunityApps.
the class VendorInactivateConvertBatchServiceImpl method inactivateConvert.
/**
*/
public boolean inactivateConvert(String fileName, BatchInputFileType batchInputFileType) {
boolean result = true;
// load up the file into a byte array
byte[] fileByteContent = safelyLoadFileBytes(fileName);
LOG.info("Attempting to parse the file");
Object parsedObject = null;
try {
parsedObject = batchInputFileService.parse(batchInputFileType, fileByteContent);
} catch (ParseException e) {
String errorMessage = "Error parsing batch file: " + e.getMessage();
LOG.error(errorMessage, e);
throw new RuntimeException(errorMessage);
}
// make sure we got the type we expected, then cast it
if (!(parsedObject instanceof List)) {
String errorMessage = "Parsed file was not of the expected type. Expected [" + List.class + "] but got [" + parsedObject.getClass() + "].";
criticalError(errorMessage);
}
List<VendorInactivateConvertBatch> vendors = ((List<VendorInactivateConvertBatch>) parsedObject);
for (VendorInactivateConvertBatch vendor : vendors) {
String[] vendorId = vendor.getVendorId().split("-");
Collection<VendorDetail> vendorDets = businessObjectService.findMatching(VendorDetail.class, Collections.singletonMap("vendorHeaderGeneratedIdentifier", vendorId[0]));
GlobalVariables.setUserSession(new UserSession("kfs"));
VendorDetail vnd = cuVendorService.getByVendorNumber(vendor.getVendorId());
if (ObjectUtils.isNull(vnd)) {
LOG.info("Vendor with id: " + vendor.getVendorId() + " does not exist in the database.");
}
if ((ObjectUtils.isNotNull(vnd))) {
VendorHeader vHead = businessObjectService.findBySinglePrimaryKey(VendorHeader.class, vnd.getVendorHeaderGeneratedIdentifier());
if (vendor.getAction().equalsIgnoreCase("inactivate") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
inactivateVendor(vnd, vendor.getNote(), vendor.getReason());
} else if (vendor.getAction().equalsIgnoreCase("activate") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
activateVendor(vnd, vendor.getNote(), vendor.getReason());
} else if (vendor.getAction().equalsIgnoreCase("convert") && ((vendorDets.size() == 1) || !(vendorId[1].equalsIgnoreCase("0")))) {
convertVendor(vHead, vnd, vendor.getNote(), vendor.getConvertType());
} else if (vendorDets.size() > 1) {
LOG.info("failed to process for " + vnd.getVendorNumber() + ", This vendor has child records. These must be processed through the application");
} else {
String errorMessage = "Failed to parse vendor action expected inactivate or convert but recevied " + vendor.getAction();
criticalError(errorMessage);
}
}
}
return result;
}
Aggregations