Search in sources :

Example 21 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class CreateAccountingDocumentServiceImpl method createAndRouteAccountingDocumentFromXml.

protected void createAndRouteAccountingDocumentFromXml(AccountingXmlDocumentEntry accountingXmlDocument, CreateAccountingDocumentReportItemDetail reportDetail, CreateAccountingDocumentReportItem reportItem) {
    try {
        LOG.info("createAndRouteAccountingDocumentFromXml: 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("createAndRouteAccountingDocumentFromXml: Finished processing and routing accounting document " + document.getDocumentNumber() + " of type: " + accountingXmlDocument.getDocumentTypeCode());
        reportDetail.setSuccessfullyRouted(true);
        reportDetail.setDocumentNumber(document.getDocumentNumber());
        reportItem.getDocumentsSuccessfullyRouted().add(reportDetail);
    } catch (RuntimeException | WorkflowException e) {
        reportDetail.setSuccessfullyRouted(false);
        if (e instanceof ValidationException) {
            String errorMessage = buildValidationErrorMessage((ValidationException) e);
            LOG.error("createAndRouteAccountingDocumentFromXml: Could not route accounting document - " + errorMessage);
            reportDetail.setErrorMessage(errorMessage);
        } else {
            LOG.error("createAndRouteAccountingDocumentFromXml: Error processing accounting XML document", e);
            reportDetail.setErrorMessage("Non validation error: " + e.getMessage());
            reportItem.setNonBusinessRuleFailure(true);
        }
        reportItem.getDocumentsInError().add(reportDetail);
    } finally {
        GlobalVariables.getMessageMap().clearErrorMessages();
    }
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument)

Example 22 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class ProcurementCardCreateDocumentServiceImpl method createProcurementCardDocument.

/**
 * Creates a ProcurementCardDocument from the List of transactions given.
 *
 * @param transactions List of ProcurementCardTransaction objects to be used for creating the document.
 * @return A ProcurementCardDocument populated with the transactions provided.
 */
@SuppressWarnings({ "rawtypes", "deprecation" })
@Override
public ProcurementCardDocument createProcurementCardDocument(List transactions) {
    ProcurementCardDocument pcardDocument = null;
    try {
        // get new document from doc service
        pcardDocument = buildNewProcurementCardDocument();
        List<CapitalAssetInformation> capitalAssets = pcardDocument.getCapitalAssetInformation();
        for (CapitalAssetInformation capitalAsset : capitalAssets) {
            if (ObjectUtils.isNotNull(capitalAsset) && ObjectUtils.isNotNull(capitalAsset.getCapitalAssetInformationDetails())) {
                capitalAsset.setDocumentNumber(pcardDocument.getDocumentNumber());
            }
        }
        ProcurementCardTransaction trans = (ProcurementCardTransaction) transactions.get(0);
        String errorText = validateTransaction(trans);
        createCardHolderRecord(pcardDocument, trans);
        // for each transaction, create transaction detail object and then acct lines for the detail
        int transactionLineNumber = 1;
        KualiDecimal documentTotalAmount = KualiDecimal.ZERO;
        ProcurementCardTransaction transaction = null;
        for (Object transactionObj : transactions) {
            transaction = (ProcurementCardTransaction) transactionObj;
            // create transaction detail record with accounting lines
            errorText += createTransactionDetailRecord(pcardDocument, transaction, transactionLineNumber);
            // update document total
            documentTotalAmount = documentTotalAmount.add(transaction.getFinancialDocumentTotalAmount());
            transactionLineNumber++;
        }
        pcardDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(documentTotalAmount);
        // pcardDocument.getDocumentHeader().setDocumentDescription("SYSTEM Generated");
        transaction = (ProcurementCardTransaction) transactions.get(0);
        String cardHolderName = transaction.getCardHolderName();
        String vendorName = transaction.getVendorName();
        String transactionType = ((ProcurementCardTransactionExtendedAttribute) transaction.getExtension()).getTransactionType();
        if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
            VENDOR_NAME_MAX_LENGTH = 16;
        } else {
            VENDOR_NAME_MAX_LENGTH = 19;
        }
        if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() > VENDOR_NAME_MAX_LENGTH) {
            cardHolderName = cardHolderName.substring(0, CARD_HOLDER_MAX_LENGTH);
            vendorName = vendorName.substring(0, VENDOR_NAME_MAX_LENGTH);
        }
        if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() <= VENDOR_NAME_MAX_LENGTH) {
            Integer endIndice = 0;
            if ((CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length())) > cardHolderName.length()) {
                endIndice = cardHolderName.length();
            } else {
                endIndice = CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length());
            }
            cardHolderName = cardHolderName.substring(0, endIndice);
        }
        if (vendorName.length() > VENDOR_NAME_MAX_LENGTH && cardHolderName.length() <= CARD_HOLDER_MAX_LENGTH) {
            Integer endIndice = 0;
            if ((VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length())) > vendorName.length()) {
                endIndice = vendorName.length();
            } else {
                endIndice = VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length());
            }
            vendorName = vendorName.substring(0, endIndice);
        }
        String creditCardNumber = transaction.getTransactionCreditCardNumber();
        String lastFour = "";
        if (creditCardNumber.length() > CC_LAST_FOUR) {
            lastFour = creditCardNumber.substring(creditCardNumber.length() - CC_LAST_FOUR);
        }
        String docDesc = cardHolderName + "/" + vendorName + "/" + lastFour;
        if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
            docDesc = transactionType + "/" + cardHolderName + "/" + vendorName + "/" + lastFour;
        }
        if (docDesc.length() > MAX_DOC_DESC_LENGTH) {
            docDesc = docDesc.substring(0, MAX_DOC_DESC_LENGTH);
        }
        pcardDocument.getDocumentHeader().setDocumentDescription(docDesc);
        // Remove duplicate messages from errorText
        String[] messages = StringUtils.split(errorText, ".");
        for (String message : messages) {
            int countMatches = StringUtils.countMatches(errorText, message) - 1;
            errorText = StringUtils.replace(errorText, message + ".", "", countMatches);
        }
        // In case errorText is still too long, truncate it and indicate so.
        Integer documentExplanationMaxLength = dataDictionaryService.getAttributeMaxLength(DocumentHeader.class.getName(), KFSPropertyConstants.EXPLANATION);
        if (documentExplanationMaxLength != null && errorText.length() > documentExplanationMaxLength.intValue()) {
            String truncatedMessage = " ... TRUNCATED.";
            errorText = errorText.substring(0, documentExplanationMaxLength - truncatedMessage.length()) + truncatedMessage;
        }
        pcardDocument.getDocumentHeader().setExplanation(errorText);
    } catch (WorkflowException e) {
        LOG.error("Error creating pcdo documents: " + e.getMessage(), e);
        throw new RuntimeException("Error creating pcdo documents: " + e.getMessage(), e);
    }
    return pcardDocument;
}
Also used : CapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) DocumentHeader(org.kuali.kfs.krad.bo.DocumentHeader) ProcurementCardDocument(org.kuali.kfs.fp.document.ProcurementCardDocument) ProcurementCardTransactionExtendedAttribute(edu.cornell.kfs.fp.businessobject.ProcurementCardTransactionExtendedAttribute) ProcurementCardTransaction(org.kuali.kfs.fp.businessobject.ProcurementCardTransaction) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal)

Example 23 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class SubmitTripWebServiceImpl method buildDistributionIncomeExpenseDocument.

/**
 * @param diDescription
 * @param diExplanation
 * @param tripNumber
 * @param initiatorNetId
 * @return
 * @throws Exception
 */
private String buildDistributionIncomeExpenseDocument(String diDescription, String diExplanation, String tripNumber, String initiatorNetId) throws Exception {
    try {
        if (!isValidDocumentInitiator(initiatorNetId, DISTRIBUTION_INCOME_EXPENSE)) {
            throw new RuntimeException("Initiator identified does not have permission to create a DI.");
        }
    } catch (Exception ex) {
        throw new RuntimeException("Initiator identified does not have permission to create a DI.", ex);
    }
    // create and route doc as system user
    GlobalVariables.setUserSession(new UserSession(initiatorNetId));
    MessageMap documentErrorMap = new MessageMap();
    GlobalVariables.setMessageMap(documentErrorMap);
    // Create document with description provided
    CuDistributionOfIncomeAndExpenseDocument diDoc = null;
    try {
        diDoc = (CuDistributionOfIncomeAndExpenseDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DistributionOfIncomeAndExpenseDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (diDoc != null) {
        diDoc.getDocumentHeader().setDocumentDescription(diDescription);
        diDoc.getDocumentHeader().setExplanation(diExplanation);
        diDoc.getDocumentHeader().setOrganizationDocumentNumber(tripNumber);
        diDoc.setTripAssociationStatusCode(CULegacyTravelServiceImpl.TRIP_ASSOCIATIONS.IS_TRIP_DOC);
        diDoc.setTripId(tripNumber);
        // Persist document
        SpringContext.getBean(DocumentService.class).saveDocument(diDoc);
        return diDoc.getDocumentNumber();
    } else {
        return "";
    }
}
Also used : UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) MessageMap(org.kuali.kfs.krad.util.MessageMap) DocumentService(org.kuali.kfs.krad.service.DocumentService) CuDistributionOfIncomeAndExpenseDocument(edu.cornell.kfs.fp.document.CuDistributionOfIncomeAndExpenseDocument)

Example 24 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class RecurringDisbursementVoucherDocumentServiceImpl method noteChangeOnRecurringDV.

private void noteChangeOnRecurringDV(RecurringDisbursementVoucherDocument recurringDV, String noteText, Set<String> setOfStrings) {
    if (!setOfStrings.isEmpty()) {
        Note note = buildNoteBase();
        note.setNoteText(noteText + StringUtils.join(setOfStrings, ", "));
        ;
        recurringDV.addNote(note);
        try {
            getDocumentService().saveDocument(recurringDV);
        } catch (WorkflowException e) {
            throw new RuntimeException("noteChangeOnRecurringDV() Unable to save note.", e);
        }
    }
}
Also used : Note(org.kuali.kfs.krad.bo.Note) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException)

Example 25 with WorkflowException

use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.

the class RecurringDisbursementVoucherDocumentServiceImpl method cancelDisbursementVouchersFinalizedNotExtracted.

@Override
public Set<String> cancelDisbursementVouchersFinalizedNotExtracted(RecurringDisbursementVoucherDocument recurringDisbursementVoucherDocument, String cancelMessage) {
    Set<String> canceledDVs = new HashSet<String>();
    for (RecurringDisbursementVoucherDetail detail : recurringDisbursementVoucherDocument.getRecurringDisbursementVoucherDetails()) {
        String dvDocumentNumber = detail.getDvDocumentNumber();
        if (!isDVCancelable(dvDocumentNumber)) {
            CuDisbursementVoucherDocument dv;
            try {
                dv = (CuDisbursementVoucherDocument) getDocumentService().getByDocumentHeaderId(detail.getDvDocumentNumber());
                if (isDvCancelableFromApprovedNotExtracted(dv)) {
                    Date cancelDate = new Date(Calendar.getInstance().getTimeInMillis());
                    dv.setCancelDate(cancelDate);
                    CuDisbursementVoucherDocument cancledDV = (CuDisbursementVoucherDocument) getDocumentService().saveDocument(dv);
                    getCuDisbursementVoucherExtractionHelperService().getPaymentSourceHelperService().handleEntryCancellation(cancledDV, getCuDisbursementVoucherExtractionHelperService());
                    canceledDVs.add(cancledDV.getDocumentNumber());
                }
            } catch (WorkflowException e) {
                throw new RuntimeException(e);
            }
        }
    }
    noteChangeOnRecurringDV(recurringDisbursementVoucherDocument, "The following disbursement vouchers were canceled after it was approved but before payments were created: ", canceledDVs);
    return canceledDVs;
}
Also used : CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) RecurringDisbursementVoucherDetail(edu.cornell.kfs.fp.businessobject.RecurringDisbursementVoucherDetail) Date(java.sql.Date) HashSet(java.util.HashSet)

Aggregations

WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)52 ArrayList (java.util.ArrayList)12 DocumentService (org.kuali.kfs.krad.service.DocumentService)11 Document (org.kuali.kfs.krad.document.Document)9 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)7 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)7 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)6 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)6 Date (java.sql.Date)5 HashMap (java.util.HashMap)5 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)5 ValidationException (org.kuali.kfs.krad.exception.ValidationException)5 RemoteException (java.rmi.RemoteException)4 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)4 Person (org.kuali.kfs.kim.api.identity.Person)4 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)4 CuElectronicInvoiceRejectDocument (edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument)3 AccountGlobal (org.kuali.kfs.coa.businessobject.AccountGlobal)3 Note (org.kuali.kfs.krad.bo.Note)3 ContractsGrantsInvoiceDocument (org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)3