Search in sources :

Example 1 with FormatException

use of org.kuali.rice.core.web.format.FormatException in project cu-kfs by CU-CommunityApps.

the class AdvanceDepositServiceImpl method getEmailMessageText.

private String getEmailMessageText(AchIncomeFile achIncomeFile, String payerMessage) {
    StringBuilder message = new StringBuilder();
    int totalPostedTransation = achTotalPostedTransactions + wiredTotalPostedTransactions;
    KualiDecimal totalPostedTransactionAmount = achTotalPostedTransactionAmount.add(wiredTotalPostedTransactionAmount);
    String fileDateTime;
    try {
        fileDateTime = getFormattedTimestamp(achIncomeFile, "fileDate/Time").toString();
    } catch (FormatException e) {
        // use the original file Date/Time string if encountered invalid format
        fileDateTime = achIncomeFile.getFileDate() + " " + achIncomeFile.getFileTime();
    }
    message.append("File Date: " + fileDateTime);
    message.append("\n");
    message.append("                    ");
    message.append("COUNT               ");
    message.append("        AMOUNT     ");
    message.append("\n");
    message.append(StringUtils.rightPad("ACH Posted", 20));
    message.append(StringUtils.rightPad(achTotalPostedTransactions + "", 20));
    message.append(StringUtils.leftPad(getFormattedAmount("##,##,##0.00", achTotalPostedTransactionAmount), 20));
    message.append("\n");
    message.append(StringUtils.rightPad("Wire Posted", 20));
    message.append(StringUtils.rightPad(wiredTotalPostedTransactions + "", 20));
    message.append(StringUtils.leftPad(getFormattedAmount("##,##,##0.00", wiredTotalPostedTransactionAmount), 20));
    message.append("\n");
    message.append(StringUtils.rightPad("Total Posted", 20));
    message.append(StringUtils.rightPad(totalPostedTransation + "", 20));
    message.append(StringUtils.leftPad(getFormattedAmount("##,##,##0.00", totalPostedTransactionAmount), 20));
    message.append("\n");
    message.append("\n");
    message.append(StringUtils.rightPad("ACH Skipped", 20));
    message.append(StringUtils.rightPad(achTotalSkippedTransactions + "", 20));
    message.append(StringUtils.leftPad(getFormattedAmount("##,##,##0.00", achTotalSkippedTransactionAmount), 20));
    message.append("\n");
    message.append(StringUtils.rightPad("Wire Skipped", 20));
    message.append(StringUtils.rightPad(wiredTotalSkippedTransactions + "", 20));
    message.append(StringUtils.leftPad(getFormattedAmount("##,##,##0.00", wiredTotalSkippedTransactionAmount), 20));
    message.append("\n");
    if (StringUtils.isNotBlank(payerMessage)) {
        message.append("\n");
        message.append("Transactions Missing Payer Name: ");
        message.append("\n");
        message.append(payerMessage);
    }
    return message.toString();
}
Also used : KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) FormatException(org.kuali.rice.core.web.format.FormatException)

Example 2 with FormatException

use of org.kuali.rice.core.web.format.FormatException in project cu-kfs by CU-CommunityApps.

the class TransactionOverrideCsvBatchInputFileType method convertParsedLineToVO.

/**
 * Transforms each parsed line into a TransactionOverride BO if content is valid,
 * or into a String representation of the parsed line if content is invalid.
 * Assumes that TransactionOverrideCsv is the header enum.
 *
 * @param parsedLine The line to process, as a Map from header names to values.
 * @param lineNumber The current line number, starting from 1.
 * @param docNumberMaxLength The max length of the BO's document number property.
 * @param boxNumberMaxLength The max length of the BO's tax box property.
 * @return A TransactionOverride object if a valid line, otherwise a tab-delimited String representation of the line.
 */
protected Object convertParsedLineToVO(Map<String, String> parsedLine, int lineNumber, int docNumberMaxLength, int boxNumberMaxLength) {
    boolean valid = true;
    TransactionOverride transOverride = new TransactionOverride();
    // Verify that exactly one type of tax box was specified, and that the tax box has the expected max length. Also setup tax box properties if valid.
    String box1099 = parsedLine.get(TransactionOverrideCsv.Form_1099_Box.toString());
    String box1042S = parsedLine.get(TransactionOverrideCsv.Form_1042S_Box.toString());
    if (StringUtils.isBlank(box1099)) {
        if (StringUtils.isBlank(box1042S)) {
            LOG.error("Found a line that does not specify a 1099 or 1042S tax box override. Line number: " + Integer.toString(lineNumber));
            valid = false;
        } else if (box1042S.length() > boxNumberMaxLength) {
            LOG.error("Found a line with a 1042S box number that is too long. Line number: " + Integer.toString(lineNumber));
            valid = false;
        } else {
            // Validation succeeded; configure override of a 1042S tax box.
            transOverride.setTaxType(CUTaxConstants.TAX_TYPE_1042S);
            transOverride.setBoxNumber(NULL_STRING.equalsIgnoreCase(box1042S) ? CUTaxConstants.TAX_1042S_UNKNOWN_BOX_KEY : box1042S);
        }
    } else if (StringUtils.isNotBlank(box1042S)) {
        LOG.error("Found a line that specifies both a 1099 and 1042S tax box override. Line number: " + Integer.toString(lineNumber));
        valid = false;
    } else if (box1099.length() > CUTaxConstants.TAX_1099_MAX_BUCKET_LENGTH && !NULL_STRING.equalsIgnoreCase(box1099)) {
        LOG.error("Found a line with a 1099 box number that is too long. Line number: " + Integer.toString(lineNumber));
        valid = false;
    } else {
        // Validation succeeded; configure override of a 1099 tax box.
        transOverride.setTaxType(CUTaxConstants.TAX_TYPE_1099);
        transOverride.setBoxNumber(NULL_STRING.equalsIgnoreCase(box1099) ? CUTaxConstants.TAX_1099_UNKNOWN_BOX_KEY : box1099);
    }
    // Setup document number, and verify that the value is non-blank and is not too large.
    transOverride.setDocumentNumber(parsedLine.get(TransactionOverrideCsv.Doc_Number.toString()));
    if (StringUtils.isBlank(transOverride.getDocumentNumber())) {
        LOG.error("Found a line with a blank document number. Line number: " + Integer.toString(lineNumber));
        valid = false;
    } else if (transOverride.getDocumentNumber().length() > docNumberMaxLength) {
        LOG.error("Found a line with a document number that is too long. Line number: " + Integer.toString(lineNumber));
        valid = false;
    }
    // Setup document line number, which should be a valid integer.
    try {
        transOverride.setFinancialDocumentLineNumber(Integer.valueOf(parsedLine.get(TransactionOverrideCsv.Doc_Line_Number.toString())));
    } catch (NumberFormatException e) {
        LOG.error("Found a line whose document line number is null or invalid. Line number: " + Integer.toString(lineNumber));
        valid = false;
    }
    // Setup university/payment date, which should be a valid SQL Date.
    try {
        transOverride.setUniversityDate((java.sql.Date) dateFormatter.convertFromPresentationFormat(parsedLine.get(TransactionOverrideCsv.Payment_Date.toString())));
        if (transOverride.getUniversityDate() == null) {
            LOG.error("Found a line with a null payment date. Line number: " + Integer.toString(lineNumber));
            valid = false;
        }
    } catch (FormatException | ClassCastException e) {
        LOG.error("Found a line with an invalid payment date. Line number: " + Integer.toString(lineNumber));
        valid = false;
    }
    if (valid) {
        // No validation errors found; return the newly-constructed object.
        return transOverride;
    } else {
        // Validation failed; return the line as a tab-limited String instead (with the values ordered accordingly).
        List<String> lineValues = new ArrayList<String>();
        for (String headerName : getCsvHeaderList()) {
            lineValues.add(parsedLine.get(headerName));
        }
        return StringUtils.join(lineValues, '\t');
    }
}
Also used : TransactionOverride(edu.cornell.kfs.tax.businessobject.TransactionOverride) ArrayList(java.util.ArrayList) FormatException(org.kuali.rice.core.web.format.FormatException)

Example 3 with FormatException

use of org.kuali.rice.core.web.format.FormatException in project cu-kfs by CU-CommunityApps.

the class AdvanceDepositServiceImpl method getFormattedTimestamp.

private Timestamp getFormattedTimestamp(AchIncomeFile achIncomeFile, String fieldName) {
    String fileDateTime = achIncomeFile.getFileDate() + achIncomeFile.getFileTime();
    // need to use 24 hour format, since otherwise exception will be thrown if the time falls in PM range.
    SimpleDateFormat dateFormat = new SimpleDateFormat(CuFPConstants.ACH_INCOME_FILE_DATE_FORMAT);
    dateFormat.setLenient(false);
    try {
        java.util.Date parsedDate = dateFormat.parse(fileDateTime);
        return new Timestamp(parsedDate.getTime());
    } catch (ParseException e) {
        throw new FormatException(fieldName + " must be of the format " + CuFPConstants.ACH_INCOME_FILE_DATE_FORMAT + "\n" + e);
    }
}
Also used : ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) FormatException(org.kuali.rice.core.web.format.FormatException)

Aggregations

FormatException (org.kuali.rice.core.web.format.FormatException)3 TransactionOverride (edu.cornell.kfs.tax.businessobject.TransactionOverride)1 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)1