Search in sources :

Example 1 with PaymentFileLoad

use of org.kuali.kfs.pdp.businessobject.PaymentFileLoad in project cu-kfs by CU-CommunityApps.

the class PaymentFileServiceImpl method processPaymentFiles.

/**
 * @see org.kuali.kfs.pdp.service.PaymentFileService#processPaymentFiles(org.kuali.kfs.sys.batch.BatchInputFileType)
 */
@Override
public void processPaymentFiles(BatchInputFileType paymentInputFileType) {
    List<String> fileNamesToLoad = batchInputFileService.listInputFileNamesWithDoneFile(paymentInputFileType);
    for (String incomingFileName : fileNamesToLoad) {
        try {
            if (LOG.isDebugEnabled()) {
                LOG.debug("processPaymentFiles() Processing " + incomingFileName);
            }
            // collect various information for status of load
            LoadPaymentStatus status = new LoadPaymentStatus();
            status.setMessageMap(new MessageMap());
            // process payment file
            PaymentFileLoad paymentFile = processPaymentFile(paymentInputFileType, incomingFileName, status.getMessageMap());
            if (paymentFile != null && paymentFile.isPassedValidation()) {
                // load payment data
                loadPayments(paymentFile, status, incomingFileName);
                createOutputFile(status, incomingFileName);
            } else {
                // if we encounter an error for the payment file, we will remove the .done file so it will not be parse again
                LOG.error("Encounter a problem while processing payment file: " + incomingFileName + " .  Removing the done file to stop re-process.");
                removeDoneFile(incomingFileName);
            }
        } catch (RuntimeException e) {
            LOG.error("Caught exception trying to load payment file: " + incomingFileName, e);
        // swallow exception so we can continue processing files, the errors have been reported by email
        }
    }
}
Also used : LoadPaymentStatus(org.kuali.kfs.pdp.businessobject.LoadPaymentStatus) MessageMap(org.kuali.kfs.krad.util.MessageMap) PaymentFileLoad(org.kuali.kfs.pdp.businessobject.PaymentFileLoad)

Example 2 with PaymentFileLoad

use of org.kuali.kfs.pdp.businessobject.PaymentFileLoad 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 3 with PaymentFileLoad

use of org.kuali.kfs.pdp.businessobject.PaymentFileLoad in project cu-kfs by CU-CommunityApps.

the class PaymentFileServiceImpl method parsePaymentFile.

/**
 * Calls <code>BatchInputFileService</code> to validate XML against schema and parse.
 *
 * @param paymentInputFileType <code>BatchInputFileType</code> for payment files
 * @param incomingFileName name of the payment file to parse
 * @param errorMap any errors encountered while parsing are adding to
 * @return <code>PaymentFile</code> containing the parsed values
 */
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() });
    }
    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 4 with PaymentFileLoad

use of org.kuali.kfs.pdp.businessobject.PaymentFileLoad in project cu-kfs by CU-CommunityApps.

the class CuPaymentFileServiceImpl method getCustomerProfileFromUnparsableFile.

/**
 * @param incomingFileName
 * @param paymentFile
 * @return
 */
private PaymentFileLoad getCustomerProfileFromUnparsableFile(String incomingFileName, PaymentFileLoad paymentFile) {
    FileInputStream exFileContents;
    try {
        exFileContents = 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);
    }
    try {
        InputStreamReader inputReader = new InputStreamReader(exFileContents);
        BufferedReader bufferedReader = new BufferedReader(inputReader);
        String line = "";
        boolean found = false;
        String chartVal = "";
        String unitVal = "";
        String subUnitVal = "";
        while (!found && (line = bufferedReader.readLine()) != null) {
            // Use multiple ifs instead of else/ifs because all values could occur on the same line.
            if (StringUtils.contains(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.CHART_OPEN)) {
                chartVal = StringUtils.substringBetween(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.CHART_OPEN, CUPdpConstants.CustomerProfilePrimaryKeyTags.CHART_CLOSE);
            }
            if (StringUtils.contains(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.UNIT_OPEN)) {
                unitVal = StringUtils.substringBetween(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.UNIT_OPEN, CUPdpConstants.CustomerProfilePrimaryKeyTags.UNIT_CLOSE);
            }
            if (StringUtils.contains(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.SUBUNIT_OPEN)) {
                subUnitVal = StringUtils.substringBetween(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.SUBUNIT_OPEN, CUPdpConstants.CustomerProfilePrimaryKeyTags.SUBUNIT_CLOSE);
                found = true;
            }
        }
        if (found) {
            // Note: the pdpEmailServiceImpl doesn't actually use the customer object from the paymentFile, but rather retrieves an instance using
            // the values provided for chart, unit and sub_unit.  However, it doesn't make sense to even populate the paymentFile object if
            // the values retrieved don't map to a valid customer object, so we will retrieve the object here to validate the values.
            CustomerProfile customer = customerProfileService.get(chartVal, unitVal, subUnitVal);
            if (ObjectUtils.isNotNull(customer)) {
                if (ObjectUtils.isNull(paymentFile)) {
                    paymentFile = new PaymentFileLoad();
                }
                paymentFile.setChart(chartVal);
                paymentFile.setUnit(unitVal);
                paymentFile.setSubUnit(subUnitVal);
                paymentFile.setCustomer(customer);
            }
        }
    } catch (Exception ex) {
        LOG.error("Attempts to retrieve the customer profile from the unparsable XML file failed with the following error.", ex);
    } finally {
        try {
            exFileContents.close();
        } catch (IOException io) {
            LOG.error("File stream object could not be closed.", io);
        }
    }
    return paymentFile;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) CustomerProfile(org.kuali.kfs.pdp.businessobject.CustomerProfile) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PaymentFileLoad(org.kuali.kfs.pdp.businessobject.PaymentFileLoad) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.kuali.kfs.sys.exception.ParseException)

Aggregations

PaymentFileLoad (org.kuali.kfs.pdp.businessobject.PaymentFileLoad)4 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ParseException (org.kuali.kfs.sys.exception.ParseException)3 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1 CustomerProfile (org.kuali.kfs.pdp.businessobject.CustomerProfile)1 LoadPaymentStatus (org.kuali.kfs.pdp.businessobject.LoadPaymentStatus)1