Search in sources :

Example 1 with AccountingLineParser

use of org.kuali.kfs.sys.businessobject.AccountingLineParser in project cu-kfs by CU-CommunityApps.

the class KualiAccountingDocumentActionBase method uploadAccountingLines.

/**
 * This method determines whether we are uploading source or target lines, and then calls uploadAccountingLines
 * directly on the document object. This method handles retrieving the actual upload file as an input stream into
 * the document.
 *
 * @param isSource
 * @param form
 * @throws FileNotFoundException
 * @throws IOException
 */
protected void uploadAccountingLines(boolean isSource, ActionForm form) throws FileNotFoundException, IOException {
    KualiAccountingDocumentFormBase tmpForm = (KualiAccountingDocumentFormBase) form;
    List importedLines = null;
    AccountingDocument financialDocument = tmpForm.getFinancialDocument();
    AccountingLineParser accountingLineParser = financialDocument.getAccountingLineParser();
    // import the lines
    String errorPathPrefix = null;
    try {
        if (isSource) {
            errorPathPrefix = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + KFSConstants.SOURCE_ACCOUNTING_LINE_ERRORS;
            FormFile sourceFile = tmpForm.getSourceFile();
            checkUploadFile(sourceFile);
            importedLines = accountingLineParser.importSourceAccountingLines(sourceFile.getFileName(), sourceFile.getInputStream(), financialDocument);
        } else {
            errorPathPrefix = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + KFSConstants.TARGET_ACCOUNTING_LINE_ERRORS;
            FormFile targetFile = tmpForm.getTargetFile();
            checkUploadFile(targetFile);
            importedLines = accountingLineParser.importTargetAccountingLines(targetFile.getFileName(), targetFile.getInputStream(), financialDocument);
        }
    } catch (AccountingLineParserException e) {
        GlobalVariables.getMessageMap().putError(errorPathPrefix, e.getErrorKey(), e.getErrorParameters());
    }
    // add line to list for those lines which were successfully imported
    if (importedLines != null) {
        for (Object importedLineObject : importedLines) {
            AccountingLine importedLine = (AccountingLine) importedLineObject;
            insertAccountingLine(isSource, tmpForm, importedLine);
        }
    }
}
Also used : AccountingLineParser(org.kuali.kfs.sys.businessobject.AccountingLineParser) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) TargetAccountingLine(org.kuali.kfs.sys.businessobject.TargetAccountingLine) AccountingLineParserException(org.kuali.kfs.sys.exception.AccountingLineParserException) List(java.util.List) ArrayList(java.util.ArrayList) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) FormFile(org.apache.struts.upload.FormFile)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 FormFile (org.apache.struts.upload.FormFile)1 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)1 AccountingLineParser (org.kuali.kfs.sys.businessobject.AccountingLineParser)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1 TargetAccountingLine (org.kuali.kfs.sys.businessobject.TargetAccountingLine)1 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)1 AccountingLineParserException (org.kuali.kfs.sys.exception.AccountingLineParserException)1