Search in sources :

Example 11 with ValidationException

use of org.kuali.kfs.krad.exception.ValidationException in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method loadElectronicInvoices.

public ElectronicInvoiceLoad loadElectronicInvoices() {
    LOG.debug("loadElectronicInvoices() started");
    // add a step to check for directory paths
    prepareDirectories(getRequiredDirectoryNames());
    String rejectDirName = getRejectDirName();
    String acceptDirName = getAcceptDirName();
    String extractFailureDirName = getExtractFailureDirName();
    emailTextErrorList = new StringBuffer();
    int failedCnt = 0;
    LOG.info("Invoice Base Directory - " + electronicInvoiceInputFileType.getDirectoryPath());
    LOG.info("Invoice Accept Directory - " + acceptDirName);
    LOG.info("Invoice Reject Directory - " + rejectDirName);
    if (StringUtils.isBlank(rejectDirName)) {
        throw new RuntimeException("Reject directory name should not be empty");
    }
    if (StringUtils.isBlank(acceptDirName)) {
        throw new RuntimeException("Accept directory name should not be empty");
    }
    if (StringUtils.isBlank(extractFailureDirName)) {
        throw new RuntimeException("ExtractFailure directory name should not be empty");
    }
    File[] filesToBeProcessed = getFilesToBeProcessed();
    ElectronicInvoiceLoad eInvoiceLoad = new ElectronicInvoiceLoad();
    if (filesToBeProcessed == null || filesToBeProcessed.length == 0) {
        StringBuffer mailText = new StringBuffer();
        mailText.append("\n\n");
        mailText.append(PurapConstants.ElectronicInvoice.NO_FILES_PROCESSED_EMAIL_MESSAGE);
        mailText.append("\n\n");
        sendSummary(mailText);
        return eInvoiceLoad;
    }
    try {
        FileUtils.forceMkdir(new File(acceptDirName));
        FileUtils.forceMkdir(new File(rejectDirName));
        FileUtils.forceMkdir(new File(extractFailureDirName));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    LOG.info(filesToBeProcessed.length + " file(s) available for processing");
    StringBuilder emailMsg = new StringBuilder();
    for (File xmlFile : filesToBeProcessed) {
        LOG.info("Processing " + xmlFile.getName() + "....");
        byte[] modifiedXML = addNamespaceDefinition(eInvoiceLoad, xmlFile);
        try {
            processElectronicInvoice(eInvoiceLoad, xmlFile, modifiedXML);
        } catch (Exception e) {
            String msg = xmlFile.getName() + "\n";
            LOG.error(msg);
            // since getMessage() is empty we'll compose the stack trace and nicely format it.
            StackTraceElement[] elements = e.getStackTrace();
            StringBuffer trace = new StringBuffer();
            trace.append(e.getClass().getName());
            if (e.getMessage() != null) {
                trace.append(": ");
                trace.append(e.getMessage());
            }
            trace.append("\n");
            for (int j = 0; j < elements.length; ++j) {
                StackTraceElement element = elements[j];
                trace.append("    at ");
                trace.append(describeStackTraceElement(element));
                trace.append("\n");
            }
            LOG.error(trace);
            // KFSUPGRADE-480, KFSUPGRADE-484 : Cu channged email message, the failCnt and emailMsg are not referenced
            // in CU's email.  So, this is not critical.  But may be good to see these logs.
            emailMsg.append(msg);
            msg += "\n--------------------------------------------------------------------------------------\n" + trace;
            logProcessElectronicInvoiceError(msg);
            failedCnt++;
            // one of the scenario is that save EIRT failed vecause of validation failed.  So, no EIRT will
            // be created.
            boolean moveFiles = BooleanUtils.toBoolean(parameterService.getParameterValueAsString(ElectronicInvoiceStep.class, PurapParameterConstants.ElectronicInvoiceParameters.FILE_MOVE_AFTER_LOAD_IND));
            if (moveFiles) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(xmlFile.getName() + " has caused by saving EIRT failure.");
                }
                boolean success = this.moveFile(xmlFile, getExtractFailureDirName());
                if (!success) {
                    String errorMessage = "File with name '" + xmlFile.getName() + "' could not be moved";
                    throw new PurError(errorMessage);
                }
                updateSummaryCounts(EXTRACT_FAILURES);
            }
            /**
             * Clear the error map, so that subsequent EIRT routing isn't prevented since rice
             * is throwing a ValidationException if the error map is not empty before routing the doc.
             */
            GlobalVariables.getMessageMap().clearErrorMessages();
        // Do not execute rest of code below
        // continue;
        }
    }
    StringBuffer finalText = buildLoadSummary(eInvoiceLoad);
    sendSummary(finalText);
    // Need to clear the counts after each run, so the totals don't show cumulative counts with each subsequent run.
    clearLoadCounts();
    LOG.info("Processing completed");
    return eInvoiceLoad;
}
Also used : ElectronicInvoiceLoad(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoad) IOException(java.io.IOException) ValidationException(org.kuali.kfs.krad.exception.ValidationException) IOException(java.io.IOException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) CxmlParseException(org.kuali.kfs.module.purap.exception.CxmlParseException) PurError(org.kuali.kfs.module.purap.exception.PurError) File(java.io.File)

Example 12 with ValidationException

use of org.kuali.kfs.krad.exception.ValidationException in project cu-kfs by CU-CommunityApps.

the class CuPurchaseOrderServiceImplTest method testPerformPurchaseOrderFirstTransmitViaPrinting.

public void testPerformPurchaseOrderFirstTransmitViaPrinting() throws Exception {
    PurchaseOrderDocument po = PurchaseOrderFixture.PO_NON_B2B_OPEN.createPurchaseOrderdDocument(documentService);
    try {
        purchaseOrderService.performPurchaseOrderFirstTransmitViaPrinting(po);
        assertTrue(po.getPurchaseOrderFirstTransmissionTimestamp() != null);
        assertTrue(po.getPurchaseOrderLastTransmitTimestamp() != null);
    } catch (ValidationException e) {
        LOG.warn("Caught ValidationException while trying to retransmit PO with doc id " + po.getDocumentNumber());
    }
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument)

Aggregations

ValidationException (org.kuali.kfs.krad.exception.ValidationException)12 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MessageMap (org.kuali.kfs.krad.util.MessageMap)2 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)2 CxmlParseException (org.kuali.kfs.module.purap.exception.CxmlParseException)2 DisbursementVoucherBatch (com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatch)1 DisbursementVoucherBatchDefault (com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchDefault)1 DisbursementVoucherBatchSummaryLine (com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchSummaryLine)1 BatchDisbursementVoucherDocument (com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument)1 ConcurStandardAccountingExtractFile (edu.cornell.kfs.concur.batch.businessobject.ConcurStandardAccountingExtractFile)1 CreateAccountingDocumentReportItemDetail (edu.cornell.kfs.fp.batch.CreateAccountingDocumentReportItemDetail)1 PreEncumbranceSourceAccountingLine (edu.cornell.kfs.fp.businessobject.PreEncumbranceSourceAccountingLine)1