Search in sources :

Example 6 with ParseException

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;
}
Also used : VendorBatchDetail(edu.cornell.kfs.vnd.businessobject.VendorBatchDetail) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(org.kuali.kfs.sys.exception.ParseException)

Example 7 with ParseException

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(org.kuali.kfs.sys.exception.ParseException) PayeeACHAccountExtractDetail(edu.cornell.kfs.pdp.businessobject.PayeeACHAccountExtractDetail)

Example 8 with ParseException

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;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException) FileInputStream(java.io.FileInputStream) PaymentFileLoad(org.kuali.kfs.pdp.businessobject.PaymentFileLoad)

Example 9 with ParseException

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;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ParseException(org.kuali.kfs.sys.exception.ParseException) FileInputStream(java.io.FileInputStream)

Example 10 with ParseException

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;
}
Also used : VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) VendorInactivateConvertBatch(edu.cornell.kfs.vnd.businessobject.VendorInactivateConvertBatch) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) UserSession(org.kuali.kfs.krad.UserSession) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(org.kuali.kfs.sys.exception.ParseException)

Aggregations

ParseException (org.kuali.kfs.sys.exception.ParseException)15 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)8 FileInputStream (java.io.FileInputStream)7 FileNotFoundException (java.io.FileNotFoundException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStreamReader (java.io.InputStreamReader)4 List (java.util.List)4 ReceiptProcessing (edu.cornell.kfs.module.receiptProcessing.businessobject.ReceiptProcessing)3 CSVReader (au.com.bytecode.opencsv.CSVReader)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 Date (java.sql.Date)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ProcurementCardDocument (org.kuali.kfs.fp.document.ProcurementCardDocument)2 Attachment (org.kuali.kfs.krad.bo.Attachment)2 Note (org.kuali.kfs.krad.bo.Note)2