Search in sources :

Example 1 with ValidationException

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

the class CorporateBilledCorporatePaidCreateDocumentServiceImpl method routeProcurementCardDocuments.

@Override
public boolean routeProcurementCardDocuments() {
    LOG.debug("routeProcurementCardDocuments() started");
    Collection<CorporateBilledCorporatePaidDocument> cbcpDocumentList = retrieveCorporateBilledCorporatePaidDocuments(KewApiConstants.ROUTE_HEADER_SAVED_CD);
    LOG.info("routeProcurementCardDocuments() Number of CBCP documents to Route: " + cbcpDocumentList.size());
    Map<String, String> documentErrors = new HashMap<String, String>();
    List<String> successfulDocuments = new ArrayList<String>();
    for (CorporateBilledCorporatePaidDocument cbcpDocument : cbcpDocumentList) {
        try {
            LOG.info("routeProcurementCardDocuments() Routing CBCP document # " + cbcpDocument.getDocumentNumber() + ".");
            documentService.prepareWorkflowDocument(cbcpDocument);
            documentService.routeDocument(cbcpDocument, "CBCP document automatically routed", new ArrayList<AdHocRouteRecipient>());
            successfulDocuments.add(cbcpDocument.getDocumentNumber());
        } catch (WorkflowException we) {
            documentErrors.put(cbcpDocument.getDocumentNumber(), "Workflow error: " + we.getMessage());
            GlobalVariables.getMessageMap().clearErrorMessages();
            LOG.error("routeProcurementCardDocuments, workflow error routing document # " + cbcpDocument.getDocumentNumber() + " " + we.getMessage(), we);
        } catch (ValidationException ve) {
            documentErrors.put(cbcpDocument.getDocumentNumber(), corporateBilledCorporatePaidRouteStepReportService.buildValidationErrorMessage(ve));
            GlobalVariables.getMessageMap().clearErrorMessages();
            LOG.error("routeProcurementCardDocuments, Error routing document # " + cbcpDocument.getDocumentNumber() + " " + ve.getMessage(), ve);
        }
    }
    createAndEmailReport(cbcpDocumentList, documentErrors, successfulDocuments);
    return true;
}
Also used : CorporateBilledCorporatePaidDocument(edu.cornell.kfs.fp.document.CorporateBilledCorporatePaidDocument) AdHocRouteRecipient(org.kuali.kfs.krad.bo.AdHocRouteRecipient) ValidationException(org.kuali.kfs.krad.exception.ValidationException) HashMap(java.util.HashMap) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList)

Example 2 with ValidationException

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

the class CreateAccountingDocumentServiceImpl method processAccountingDocumentEntryFromXml.

protected void processAccountingDocumentEntryFromXml(AccountingXmlDocumentEntry accountingXmlDocument, CreateAccountingDocumentReportItem reportItem) {
    GlobalVariables.getMessageMap().clearErrorMessages();
    CreateAccountingDocumentReportItemDetail detail = new CreateAccountingDocumentReportItemDetail();
    detail.setIndexNumber(accountingXmlDocument.getIndex().intValue());
    detail.setDocumentType(accountingXmlDocument.getDocumentTypeCode());
    detail.setDocumentDescription(accountingXmlDocument.getDescription());
    detail.setDocumentExplanation(accountingXmlDocument.getExplanation());
    try {
        LOG.info("processAccountingDocumentEntryFromXml: Started processing accounting document of type: " + accountingXmlDocument.getDocumentTypeCode());
        String documentGeneratorBeanName = CuFPConstants.ACCOUNTING_DOCUMENT_GENERATOR_BEAN_PREFIX + accountingXmlDocument.getDocumentTypeCode();
        AccountingDocumentGenerator<? extends AccountingDocument> documentGenerator = findDocumentGenerator(documentGeneratorBeanName);
        AccountingDocument document = documentGenerator.createDocument(this::getNewDocument, accountingXmlDocument);
        document = (AccountingDocument) documentService.routeDocument(document, CuFPConstants.ACCOUNTING_DOCUMENT_XML_ROUTE_ANNOTATION, getAllAdHocRecipients(document));
        LOG.info("processAccountingDocumentEntryFromXml: Finished processing and routing accounting document " + document.getDocumentNumber() + " of type: " + accountingXmlDocument.getDocumentTypeCode());
        detail.setSuccessfullyRouted(true);
        detail.setDocumentNumber(document.getDocumentNumber());
        reportItem.getDocumentsSuccessfullyRouted().add(detail);
    } catch (Exception e) {
        detail.setSuccessfullyRouted(false);
        if (e instanceof ValidationException) {
            String errorMessage = buildValidationErrorMessage((ValidationException) e);
            LOG.error("processAccountingDocumentEntryFromXml: Could not route accounting document - " + errorMessage);
            detail.setErrorMessage(errorMessage);
        } else {
            LOG.error("processAccountingDocumentEntryFromXml: Error processing accounting XML document", e);
            detail.setErrorMessage("Non validation error: " + e.getMessage());
        }
        reportItem.getDocumentsInError().add(detail);
    } finally {
        GlobalVariables.getMessageMap().clearErrorMessages();
    }
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) ValidationException(org.kuali.kfs.krad.exception.ValidationException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) IOException(java.io.IOException) CreateAccountingDocumentReportItemDetail(edu.cornell.kfs.fp.batch.CreateAccountingDocumentReportItemDetail)

Example 3 with ValidationException

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

the class PreEncumbranceDocument method processExplicitGeneralLedgerPendingEntry.

/**
 * This method processes all necessary information to build an explicit general ledger entry, and then adds that to the
 * document.
 *
 * @param accountingDocument
 * @param sequenceHelper
 * @param accountingLine
 * @param explicitEntry
 * @return boolean True if the explicit entry generation was successful, false otherwise.
 */
@Override
protected void processExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySequenceHelper sequenceHelper, GeneralLedgerPendingEntrySourceDetail glpeSourceDetail, GeneralLedgerPendingEntry explicitEntry) {
    if (glpeSourceDetail instanceof PreEncumbranceSourceAccountingLine) {
        int rowId = ((AccountingLine) glpeSourceDetail).getSequenceNumber() - 1;
        PreEncumbranceSourceAccountingLine pesal = (PreEncumbranceSourceAccountingLine) glpeSourceDetail;
        if (ObjectUtils.isNotNull(pesal.getAutoDisEncumberType())) {
            if (ObjectUtils.isNull(pesal.getStartDate()) || ObjectUtils.isNull(pesal.getPartialTransactionCount()) || ObjectUtils.isNull(pesal.getPartialAmount())) {
                throw new ValidationException("Insufficient information for GLPE generation");
            }
            Date generatedEndDate = PreEncumbranceAccountingLineUtil.generateEndDate(pesal.getStartDate(), Integer.parseInt(pesal.getPartialTransactionCount()), pesal.getAutoDisEncumberType());
            pesal.setEndDate(generatedEndDate);
            TreeMap<Date, KualiDecimal> datesAndAmounts = PreEncumbranceAccountingLineUtil.generateDatesAndAmounts(pesal.getAutoDisEncumberType(), pesal.getStartDate(), pesal.getEndDate(), Integer.parseInt(pesal.getPartialTransactionCount()), pesal.getAmount(), pesal.getPartialAmount(), rowId);
            Iterator<Date> it = datesAndAmounts.keySet().iterator();
            boolean isErrorCorrection = false;
            Date today = new Date(Calendar.getInstance().getTimeInMillis());
            if (pesal.getAmount().isNegative()) {
                // we are doing error correction
                LOG.info("Error correction!");
                isErrorCorrection = true;
            }
            while (it.hasNext()) {
                Date revDate = it.next();
                if (isErrorCorrection && revDate.before(today)) {
                    break;
                }
                KualiDecimal partialAmount = datesAndAmounts.get(revDate);
                GeneralLedgerPendingEntry explicitPartialEntry = new GeneralLedgerPendingEntry();
                SpringContext.getBean(GeneralLedgerPendingEntryService.class).populateExplicitGeneralLedgerPendingEntry(this, glpeSourceDetail, sequenceHelper, explicitPartialEntry);
                explicitPartialEntry.setFinancialDocumentReversalDate(revDate);
                explicitPartialEntry.setTransactionLedgerEntryAmount(isErrorCorrection ? partialAmount.negated() : partialAmount);
                customizeExplicitGeneralLedgerPendingEntry(glpeSourceDetail, explicitPartialEntry);
                addPendingEntry(explicitPartialEntry);
                sequenceHelper.increment();
                GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(explicitPartialEntry);
                processOffsetGeneralLedgerPendingEntry(sequenceHelper, glpeSourceDetail, explicitPartialEntry, offsetEntry);
                sequenceHelper.increment();
            }
            // no need to do the following stuff, as we're generating a bunch of custom GL pending entries above
            return;
        }
    }
    // populate the explicit entry
    SpringContext.getBean(GeneralLedgerPendingEntryService.class).populateExplicitGeneralLedgerPendingEntry(this, glpeSourceDetail, sequenceHelper, explicitEntry);
    // hook for children documents to implement document specific GLPE field mappings
    customizeExplicitGeneralLedgerPendingEntry(glpeSourceDetail, explicitEntry);
    addPendingEntry(explicitEntry);
    sequenceHelper.increment();
    // handle the offset entry
    GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(explicitEntry);
    boolean success = processOffsetGeneralLedgerPendingEntry(sequenceHelper, glpeSourceDetail, explicitEntry, offsetEntry);
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) PreEncumbranceSourceAccountingLine(edu.cornell.kfs.fp.businessobject.PreEncumbranceSourceAccountingLine) GeneralLedgerPendingEntryService(org.kuali.kfs.sys.service.GeneralLedgerPendingEntryService) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Date(java.sql.Date)

Example 4 with ValidationException

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

the class WebUtils method getMultipartParameters.

public static void getMultipartParameters(HttpServletRequest request, ActionServletWrapper servletWrapper, ActionForm form, ActionMapping mapping) {
    Map params = new HashMap();
    try {
        CommonsMultipartRequestHandler multipartHandler = new CommonsMultipartRequestHandler();
        if (multipartHandler != null) {
            // Set servlet and mapping info
            if (servletWrapper != null) {
                // from pojoformbase
                // servlet only affects tempdir on local disk
                servletWrapper.setServletFor(multipartHandler);
            }
            multipartHandler.setMapping((ActionMapping) request.getAttribute(Globals.MAPPING_KEY));
            // Initialize multipart request class handler
            multipartHandler.handleRequest(request);
            Collection<FormFile> files = multipartHandler.getFileElements().values();
            Enumeration keys = multipartHandler.getFileElements().keys();
            while (keys.hasMoreElements()) {
                Object key = keys.nextElement();
                FormFile file = (FormFile) multipartHandler.getFileElements().get(key);
                long maxSize = WebUtils.getMaxUploadSize(form);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(file.getFileSize());
                }
                if (maxSize > 0 && Long.parseLong(file.getFileSize() + "") > maxSize) {
                    GlobalVariables.getMessageMap().putError(key.toString(), RiceKeyConstants.ERROR_UPLOADFILE_SIZE, new String[] { file.getFileName(), Long.toString(maxSize) });
                }
            }
            // get file elements for kualirequestprocessor
            if (servletWrapper == null) {
                request.setAttribute(KRADConstants.UPLOADED_FILE_REQUEST_ATTRIBUTE_KEY, getFileParametersForMultipartRequest(request, multipartHandler));
            }
        }
    } catch (ServletException e) {
        throw new ValidationException("unable to handle multipart request " + e.getMessage(), e);
    }
}
Also used : ServletException(javax.servlet.ServletException) Enumeration(java.util.Enumeration) ValidationException(org.kuali.kfs.krad.exception.ValidationException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MessageMap(org.kuali.kfs.krad.util.MessageMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CommonsMultipartRequestHandler(org.apache.struts.upload.CommonsMultipartRequestHandler) FormFile(org.apache.struts.upload.FormFile)

Example 5 with ValidationException

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

the class PaymentWorksDataProcessingIntoKfsServiceImpl method kfsVendorMaintenanceDocumentValidated.

private boolean kfsVendorMaintenanceDocumentValidated(MaintenanceDocument vendorMaintenceDoc, PaymentWorksNewVendorRequestsBatchReportData reportData, PaymentWorksVendor pmwVendor) {
    boolean documentValidated = false;
    try {
        vendorMaintenceDoc.validateBusinessRules(new RouteDocumentEvent(vendorMaintenceDoc));
        LOG.info("kfsVendorMaintenanceDocumentValidated: vendorMaintenceDoc validate.");
        documentValidated = true;
    } catch (ValidationException ve) {
        List<String> validationErrors = convertReportDataValidationErrors(GlobalVariables.getMessageMap().getErrorMessages());
        captureKfsProcessingErrorsForVendor(pmwVendor, reportData, validationErrors);
        LOG.error("kfsVendorMaintenanceDocumentValidated: eDoc validation error(s): " + validationErrors.toString());
        LOG.error("kfsVendorMaintenanceDocumentValidated: eDoc validation exception caught: " + ve.getMessage());
    } finally {
        GlobalVariables.getMessageMap().clearErrorMessages();
    }
    return documentValidated;
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) RouteDocumentEvent(org.kuali.kfs.krad.rules.rule.event.RouteDocumentEvent) ArrayList(java.util.ArrayList) AutoPopulatingList(org.springframework.util.AutoPopulatingList) List(java.util.List)

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