Search in sources :

Example 41 with WorkflowException

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

the class AutoCancelBatchDaoJdbc method cancelDocuments.

/**
 * @see AutoCancelBatchDao#cancelDocuments()
 */
@Override
public void cancelDocuments() throws Exception {
    final String daysToAutoCancel = parameterService.getParameterValueAsString(AutoCancelBatchStep.class, CUKFSParameterKeyConstants.DAYS_TO_AUTO_CANCEL_PARAMETER);
    if (StringUtils.isNotBlank(daysToAutoCancel)) {
        Map<String, String> cancelIds = findSavedDocumentIds(Integer.parseInt(daysToAutoCancel));
        Set<String> cancelDocumentIds = cancelIds.keySet();
        int canceledDocumentCount = 0;
        for (String docId : cancelDocumentIds) {
            String docTypeId = cancelIds.get(docId);
            if (canAutoCancelDocType(docTypeId)) {
                LOG.info("Retrieving document : " + docId.trim());
                Document document = documentService.getByDocumentHeaderId(docId.trim());
                try {
                    if (!ObjectUtils.isNull(document)) {
                        LOG.info("Document Number to cancel : " + document.getDocumentNumber());
                        canceledDocumentCount++;
                        documentService.prepareWorkflowDocument(document);
                        workflowDocumentService.superUserCancel(document.getDocumentHeader().getWorkflowDocument(), "AutoCancelBatchStep: Older Than " + daysToAutoCancel + " Days");
                        sessionDocumentService.addDocumentToUserSession(GlobalVariables.getUserSession(), document.getDocumentHeader().getWorkflowDocument());
                    }
                } catch (WorkflowException e) {
                    LOG.error("AutoCancelBatchStep Encountered WorkflowException " + document.getDocumentNumber(), e);
                }
            }
        }
        LOG.info("Total number of docs canceled : " + canceledDocumentCount);
    } else {
        LOG.info("ERROR: DAYS_TO_CANCEL parameter is empty or missing");
    }
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) Document(org.kuali.kfs.krad.document.Document)

Example 42 with WorkflowException

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

the class AccountGlobalRule method checkExpirationDate.

/**
 * This method checks to see if any expiration date field rules were violated Loops through each detail object and calls
 * {@link AccountGlobalRule#checkExpirationDate(MaintenanceDocument, AccountGlobalDetail)}
 *
 * @param maintenanceDocument
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument) {
    LOG.info("checkExpirationDate called");
    boolean success = true;
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();
    // and the approver hasn't changed the value
    if (maintenanceDocument.isNew() && ObjectUtils.isNotNull(newExpDate)) {
        Date oldExpDate = null;
        if (maintenanceDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested()) {
            try {
                MaintenanceDocument oldMaintDoc = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(maintenanceDocument.getDocumentNumber());
                AccountGlobal oldAccountGlobal = (AccountGlobal) oldMaintDoc.getDocumentBusinessObject();
                if (ObjectUtils.isNotNull(oldAccountGlobal)) {
                    oldExpDate = oldAccountGlobal.getAccountExpirationDate();
                }
            } catch (WorkflowException ex) {
                LOG.warn("Error retrieving maintenance doc for doc #" + maintenanceDocument.getDocumentNumber() + ". This shouldn't happen.", ex);
            }
        }
        if (ObjectUtils.isNull(oldExpDate) || !oldExpDate.equals(newExpDate)) {
            // KFSUPGRADE-925 check parameter to see if back date is allowed
            Collection<String> fundGroups = SpringContext.getBean(ParameterService.class).getParameterValuesAsString(Account.class, COAParameterConstants.EXPIRATION_DATE_BACKDATING_FUND_GROUPS);
            if (fundGroups == null || (ObjectUtils.isNotNull(newAccountGlobal.getSubFundGroup()) && !fundGroups.contains(newAccountGlobal.getSubFundGroup().getFundGroupCode()))) {
                if (!newExpDate.after(today) && !newExpDate.equals(today)) {
                    putFieldError("accountExpirationDate", COAKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                    success = false;
                }
            }
        }
    }
    // a continuation account is required if the expiration date is completed.
    success &= checkContinuationAccount(maintenanceDocument, newExpDate);
    for (AccountGlobalDetail detail : newAccountGlobal.getAccountGlobalDetails()) {
        success &= checkExpirationDate(maintenanceDocument, detail);
    }
    return success;
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) CuAccountGlobal(edu.cornell.kfs.coa.businessobject.CuAccountGlobal) AccountGlobal(org.kuali.kfs.coa.businessobject.AccountGlobal) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail) Date(java.sql.Date)

Example 43 with WorkflowException

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

the class AccountGlobalRule method checkExpirationDate.

/**
 * This method checks to see if any expiration date field rules were violated in relation to the given detail record
 *
 * @param maintenanceDocument
 * @param detail              the account detail we are investigating
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument, AccountGlobalDetail detail) {
    boolean success = true;
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();
    Date prevExpDate = null;
    // get previous expiration date for possible check later
    if (maintenanceDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested()) {
        try {
            MaintenanceDocument oldMaintDoc = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(maintenanceDocument.getDocumentNumber());
            AccountGlobal oldAccountGlobal = (AccountGlobal) oldMaintDoc.getDocumentBusinessObject();
            if (ObjectUtils.isNotNull(oldAccountGlobal)) {
                prevExpDate = oldAccountGlobal.getAccountExpirationDate();
            }
        } catch (WorkflowException ex) {
            LOG.warn("Error retrieving maintenance doc for doc #" + maintenanceDocument.getDocumentNumber() + ". This shouldn't happen.", ex);
        }
    }
    // load the object by keys
    Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, detail.getPrimaryKeys());
    if (ObjectUtils.isNotNull(account)) {
        Date oldExpDate = account.getAccountExpirationDate();
        // (except for C&G accounts). Only run this test if this maint doc is an edit doc
        if (isUpdatedExpirationDateInvalid(account, newAccountGlobal)) {
            // we're not interested unless the approver changed the value
            if (ObjectUtils.isNull(prevExpDate) || !prevExpDate.equals(newExpDate)) {
                if (newAccountGlobal.getClosed() != null && newAccountGlobal.getClosed()) {
                    /*If the Account is being closed and the date is before today's date, the EXP date can only be today*/
                    putFieldError(KFSPropertyConstants.ACCOUNT_EXPIRATION_DATE, COAKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
                } else {
                    /*If the Account is not being closed and the date is before today's date, the EXP date can only be today or at a later date*/
                    putFieldError(KFSPropertyConstants.ACCOUNT_EXPIRATION_DATE, COAKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                }
                success = false;
            }
        }
        // acct_expiration_dt can not be before acct_effect_dt
        Date effectiveDate = null;
        if (ObjectUtils.isNotNull(newAccountGlobal.getAccountEffectiveDate())) {
            effectiveDate = newAccountGlobal.getAccountEffectiveDate();
        } else {
            effectiveDate = account.getAccountEffectiveDate();
        }
        if (ObjectUtils.isNotNull(effectiveDate) && ObjectUtils.isNotNull(newExpDate)) {
            if (newExpDate.before(effectiveDate)) {
                putFieldError(KFSPropertyConstants.ACCOUNT_EXPIRATION_DATE, CUKFSKeyConstants.ERROR_DOCUMENT_ACCT_GLB_MAINT_EXP_DATE_CANNOT_BE_BEFORE_EFFECTIVE_DATE, new String[] { detail.getAccountNumber() });
                success = false;
            }
        }
    }
    return success;
}
Also used : AppropriationAccount(edu.cornell.kfs.coa.businessobject.AppropriationAccount) Account(org.kuali.kfs.coa.businessobject.Account) IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) CuAccountGlobal(edu.cornell.kfs.coa.businessobject.CuAccountGlobal) AccountGlobal(org.kuali.kfs.coa.businessobject.AccountGlobal) Date(java.sql.Date) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService)

Example 44 with WorkflowException

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

the class DisbursementVoucherDocument method isSeparationOfDutiesReviewRequired.

protected boolean isSeparationOfDutiesReviewRequired() {
    ParameterService parameterService = SpringContext.getBean(ParameterService.class);
    boolean sepOfDutiesRequired = parameterService.getParameterValueAsBoolean(KFSConstants.CoreModuleNamespaces.FINANCIAL, DISBURSEMENT_VOUCHER_TYPE, FPParameterConstants.SEPARATION_OF_DUTIES);
    if (sepOfDutiesRequired) {
        try {
            List<Person> priorApprovers = new ArrayList<>(getAllPriorApprovers());
            // The payee cannot be the only approver
            String payeeEmployeeId = this.getDvPayeeDetail().getDisbVchrPayeeIdNumber();
            if (priorApprovers.size() == 1 && priorApprovers.get(0).getEmployeeId().equals(payeeEmployeeId)) {
                return true;
            }
            // the current approver then no need for separation of duties
            if (priorApprovers.size() > 0) {
                return false;
            }
        } catch (WorkflowException we) {
            LOG.error("Exception while attempting to retrieve all prior approvers from workflow: " + we);
        }
    }
    return false;
}
Also used : ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) Person(org.kuali.kfs.kim.api.identity.Person)

Example 45 with WorkflowException

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

the class ContractsGrantsPaymentHistoryReportLookupableHelperServiceImpl method performLookup.

/*
     * back-port FINP-7396
     */
@Override
public Collection<ContractsGrantsPaymentHistoryReport> performLookup(LookupForm lookupForm, Collection<ResultRow> resultTable, boolean bounded) {
    Map<String, String> lookupFormFields = lookupForm.getFieldsForLookup();
    setBackLocation(lookupForm.getFieldsForLookup().get(KRADConstants.BACK_LOCATION));
    setDocFormKey(lookupForm.getFieldsForLookup().get(KRADConstants.DOC_FORM_KEY));
    Collection<ContractsGrantsPaymentHistoryReport> displayList = new ArrayList<>();
    Map<String, String> invoiceAppliedLookupFields = new HashMap<>();
    if (lookupFormFields.containsKey(ArPropertyConstants.INVOICE_TYPE)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CUSTOMER_INVOICE_DOCUMENT + "." + KFSPropertyConstants.DOCUMENT_HEADER + "." + KFSPropertyConstants.WORKFLOW_DOCUMENT_TYPE_NAME, lookupFormFields.get(ArPropertyConstants.INVOICE_TYPE));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.PAYMENT_NUMBER)) {
        invoiceAppliedLookupFields.put(KFSPropertyConstants.DOCUMENT_NUMBER, lookupFormFields.get(ArPropertyConstants.PAYMENT_NUMBER));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CUSTOMER_INVOICE_DOCUMENT + "." + ArPropertyConstants.CustomerInvoiceDocumentFields.CUSTOMER_NUMBER, lookupFormFields.get(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.PAYMENT_AMOUNT)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CustomerInvoiceDetailFields.INVOICE_ITEM_APPLIED_AMOUNT, lookupFormFields.get(ArPropertyConstants.PAYMENT_AMOUNT));
    }
    if (lookupFormFields.containsKey(ArPropertyConstants.INVOICE_NUMBER)) {
        invoiceAppliedLookupFields.put(ArPropertyConstants.CustomerInvoiceDocumentFields.FINANCIAL_DOCUMENT_REF_INVOICE_NUMBER, lookupFormFields.get(ArPropertyConstants.INVOICE_NUMBER));
    }
    Collection<InvoicePaidApplied> invoicePaidApplieds = getLookupService().findCollectionBySearchHelper(InvoicePaidApplied.class, invoiceAppliedLookupFields, true);
    // For each Cash Control doc, get a list of payment app doc numbers
    try {
        for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
            boolean useInvoicePaidApplied = true;
            final Document doc = getDocumentService().getByDocumentHeaderId(invoicePaidApplied.getDocumentNumber());
            if (doc instanceof PaymentApplicationAdjustableDocument) {
                final PaymentApplicationAdjustableDocument paymentApp = (PaymentApplicationAdjustableDocument) doc;
                if (getFinancialSystemDocumentService().getUnsuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
                    useInvoicePaidApplied = false;
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.APPLIED_INDICATOR))) {
                    final String appliedIndicator = lookupFormFields.get(ArPropertyConstants.APPLIED_INDICATOR);
                    if (KRADConstants.YES_INDICATOR_VALUE.equals(appliedIndicator) && !getFinancialSystemDocumentService().getSuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
                        useInvoicePaidApplied = false;
                    } else if (KRADConstants.NO_INDICATOR_VALUE.equals(appliedIndicator) && !getFinancialSystemDocumentService().getPendingDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
                        useInvoicePaidApplied = false;
                    }
                }
                final DateTime dateFinalized = paymentApp.getDocumentHeader().getWorkflowDocument().getDateFinalized();
                Date paymentAppFinalDate = null;
                if (dateFinalized != null) {
                    paymentAppFinalDate = dateFinalized.toDate();
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.PAYMENT_DATE))) {
                    final Date toPaymentDate = getDateTimeService().convertToDate(lookupFormFields.get(ArPropertyConstants.PAYMENT_DATE));
                    if (paymentAppFinalDate == null || !KfsDateUtils.isSameDay(paymentAppFinalDate, toPaymentDate) && toPaymentDate.before(paymentAppFinalDate)) {
                        useInvoicePaidApplied = false;
                    }
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(KFSPropertyConstants.RANGE_LOWER_BOUND_KEY_PREFIX + ArPropertyConstants.PAYMENT_DATE))) {
                    final Date fromPaymentDate = getDateTimeService().convertToDate(lookupFormFields.get(KFSPropertyConstants.RANGE_LOWER_BOUND_KEY_PREFIX + ArPropertyConstants.PAYMENT_DATE));
                    if (paymentAppFinalDate == null || !KfsDateUtils.isSameDay(paymentAppFinalDate, fromPaymentDate) && fromPaymentDate.after(paymentAppFinalDate)) {
                        useInvoicePaidApplied = false;
                    }
                }
                final ContractsGrantsInvoiceDocument cgInvoiceDocument = getBusinessObjectService().findBySinglePrimaryKey(ContractsGrantsInvoiceDocument.class, invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber());
                OperatorAndValue invoiceAmountOperator = buildOperatorAndValueFromField(lookupFormFields, ArPropertyConstants.INVOICE_AMOUNT);
                if (invoiceAmountOperator != null && !invoiceAmountOperator.applyComparison(cgInvoiceDocument.getTotalDollarAmount())) {
                    useInvoicePaidApplied = false;
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(KFSPropertyConstants.AWARD_NUMBER))) {
                    if (!StringUtils.equals(cgInvoiceDocument.getInvoiceGeneralDetail().getAward().getProposalNumber(), lookupFormFields.get(KFSPropertyConstants.AWARD_NUMBER))) {
                        useInvoicePaidApplied = false;
                    }
                }
                if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.REVERSED_INDICATOR))) {
                    final String reversedIndicator = lookupFormFields.get(ArPropertyConstants.REVERSED_INDICATOR);
                    if (KRADConstants.YES_INDICATOR_VALUE.equals(reversedIndicator) && !cgInvoiceDocument.isInvoiceReversal()) {
                        useInvoicePaidApplied = false;
                    } else if (KRADConstants.NO_INDICATOR_VALUE.equals(reversedIndicator) & cgInvoiceDocument.isInvoiceReversal()) {
                        useInvoicePaidApplied = false;
                    }
                }
                if (useInvoicePaidApplied) {
                    ContractsGrantsPaymentHistoryReport cgPaymentHistoryReport = new ContractsGrantsPaymentHistoryReport();
                    cgPaymentHistoryReport.setPaymentNumber(invoicePaidApplied.getDocumentNumber());
                    cgPaymentHistoryReport.setPaymentDocumentType(paymentApp.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
                    FinancialSystemDocumentHeader documentHeader = (FinancialSystemDocumentHeader) cgInvoiceDocument.getDocumentHeader();
                    cgPaymentHistoryReport.setInvoiceType(documentHeader.getWorkflowDocumentTypeName());
                    cgPaymentHistoryReport.setPaymentAmount(invoicePaidApplied.getInvoiceItemAppliedAmount());
                    cgPaymentHistoryReport.setInvoiceNumber(invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber());
                    if (dateFinalized != null) {
                        cgPaymentHistoryReport.setPaymentDate(new java.sql.Date(dateFinalized.getMillis()));
                    }
                    cgPaymentHistoryReport.setAppliedIndicator(getFinancialSystemDocumentService().getSuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode()));
                    if (ObjectUtils.isNotNull(cgInvoiceDocument.getInvoiceGeneralDetail())) {
                        cgPaymentHistoryReport.setAwardNumber(cgInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber());
                    }
                    cgPaymentHistoryReport.setReversedIndicator(cgInvoiceDocument.isInvoiceReversal());
                    cgPaymentHistoryReport.setCustomerNumber(cgInvoiceDocument.getCustomerNumber());
                    cgPaymentHistoryReport.setCustomerName(cgInvoiceDocument.getCustomer().getCustomerName());
                    cgPaymentHistoryReport.setInvoiceAmount(cgInvoiceDocument.getTotalDollarAmount());
                    displayList.add(cgPaymentHistoryReport);
                }
            }
        }
        buildResultTable(lookupForm, displayList, resultTable);
    } catch (WorkflowException we) {
        throw new RuntimeException("Could not open payment application document related to search", we);
    } catch (ParseException pe) {
        throw new RuntimeException("I tried to validate the date and amount fields related to search, I really " + "did.  But...I guess I didn't try hard enough", pe);
    }
    return displayList;
}
Also used : ContractsGrantsPaymentHistoryReport(org.kuali.kfs.module.ar.businessobject.ContractsGrantsPaymentHistoryReport) HashMap(java.util.HashMap) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) Document(org.kuali.kfs.krad.document.Document) PaymentApplicationAdjustableDocument(org.kuali.kfs.module.ar.document.PaymentApplicationAdjustableDocument) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument) DateTime(org.joda.time.DateTime) Date(java.util.Date) PaymentApplicationAdjustableDocument(org.kuali.kfs.module.ar.document.PaymentApplicationAdjustableDocument) InvoicePaidApplied(org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied) ParseException(java.text.ParseException) ContractsGrantsInvoiceDocument(org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument)

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