Search in sources :

Example 26 with WorkflowException

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

the class RecurringDisbursementVoucherDocumentServiceImpl method autoApproveDisbursementVouchersSpawnedByRecurringDvs.

@Override
public boolean autoApproveDisbursementVouchersSpawnedByRecurringDvs() {
    LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: Entered.");
    int approvalCount = 0;
    int errorCount = 0;
    List<String> dvDocIdsCausingError = new ArrayList<String>();
    Collection<String> dvDocIds = getRecurringDisbursementVoucherSearchDao().findSavedDvIdsSpawnedByRecurringDvForCurrentAndPastFiscalPeriods(getCurrentFiscalPeriodEndDate());
    if (ObjectUtils.isNotNull(dvDocIds) && !(dvDocIds.isEmpty())) {
        for (String dvDocId : dvDocIds) {
            LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: Processing start for DV ID:: " + dvDocId);
            CuDisbursementVoucherDocument dv = null;
            try {
                dv = getDisbursementVoucher(dvDocId);
            } catch (WorkflowException e) {
                dvDocIdsCausingError.add(new String("DocId=" + dvDocId));
                errorCount++;
            }
            if (ObjectUtils.isNotNull(dv)) {
                if (isKfsSystemUserDvInitiator(dv)) {
                    try {
                        addNoteToAutoApproveDv(dv, "Batch job Submit and Blanket Approve performed for DV spawned by Recurring DV.");
                        try {
                            blanketApproveDisbursementVoucherDocument(dv);
                            approvalCount++;
                        } catch (WorkflowException e) {
                            dvDocIdsCausingError.add(new String("DocId=" + dvDocId));
                            errorCount++;
                        }
                    } catch (WorkflowException e) {
                        dvDocIdsCausingError.add(new String("DocId=" + dvDocId));
                        errorCount++;
                    }
                } else {
                    LOG.error("autoApproveDisbursementVouchersSpawnedByRecurringDvs: Detected document initiator was not KFS System user. Auto blanket approval was NOT attemtped for document ID: " + dv.getDocumentNumber());
                    dvDocIdsCausingError.add(new String("DocId=" + dvDocId));
                    errorCount++;
                }
            }
        }
    } else {
        LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: No DV's spwned by Recurring DV found. Nothing will be auto approved. ");
    }
    LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: **************** Batch Job Processing Results ****************");
    LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: Number of Disbursement Vouchers that generated Errors:: " + errorCount);
    for (Iterator iterator = dvDocIdsCausingError.iterator(); iterator.hasNext(); ) {
        LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: Erroring " + (String) iterator.next());
    }
    LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: Number of Disbursement Vouchers successfuly Blanket Approved (fully processed):: " + approvalCount);
    LOG.info("autoApproveDisbursementVouchersSpawnedByRecurringDvs: Leaving.");
    return errorCount == 0;
}
Also used : CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 27 with WorkflowException

use of org.kuali.rice.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, KFSConstants.ChartApcParms.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", KFSKeyConstants.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.rice.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 28 with WorkflowException

use of org.kuali.rice.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();
        // 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, KFSKeyConstants.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, KFSKeyConstants.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.rice.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 29 with WorkflowException

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

the class EzraServiceImpl method routeProposalDocument.

private void routeProposalDocument(Proposal proposal) {
    GlobalVariables.clear();
    GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
    MaintenanceDocument proposalDoc = null;
    try {
        proposalDoc = (MaintenanceDocument) documentService.getNewDocument("PRPL");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    proposalDoc.getDocumentHeader().setDocumentDescription("Auto creation of new proposal: " + proposal.getProposalNumber());
    proposalDoc.getNewMaintainableObject().setBusinessObject(proposal);
    try {
        documentService.saveDocument(proposalDoc);
        proposalDoc.getDocumentHeader().getWorkflowDocument().route("Automatically created and routed");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 30 with WorkflowException

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

the class EzraServiceImpl method routeAgencyDocument.

private void routeAgencyDocument(Agency agency, Agency oldAgency) {
    GlobalVariables.clear();
    GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
    // DocumentService docService = SpringContext.getBean(DocumentService.class);
    MaintenanceDocument agencyDoc = null;
    try {
        agencyDoc = (MaintenanceDocument) documentService.getNewDocument("AGCY");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    agencyDoc.getDocumentHeader().setDocumentDescription("Auto creation of new agency: " + agency.getAgencyNumber());
    if (ObjectUtils.isNotNull(oldAgency)) {
        agencyDoc.getOldMaintainableObject().setBusinessObject(oldAgency);
        agencyDoc.getDocumentHeader().setDocumentDescription(agency.getAgencyNumber() + " by auto edit");
    }
    Maintainable agencyMaintainable = agencyDoc.getNewMaintainableObject();
    agencyMaintainable.setBusinessObject(agency);
    agencyDoc.setNewMaintainableObject(agencyMaintainable);
    try {
        documentService.saveDocument(agencyDoc);
        agencyDoc.getDocumentHeader().getWorkflowDocument().route("Automatically created and routed");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable)

Aggregations

WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)44 DocumentService (org.kuali.kfs.krad.service.DocumentService)14 ArrayList (java.util.ArrayList)8 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)7 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)7 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)7 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)6 UserSession (org.kuali.kfs.krad.UserSession)6 FinancialSystemDocumentService (org.kuali.kfs.sys.document.service.FinancialSystemDocumentService)6 Date (java.sql.Date)5 RemoteException (java.rmi.RemoteException)4 ValidationException (org.kuali.kfs.krad.exception.ValidationException)4 WorkflowDocumentService (org.kuali.kfs.krad.workflow.service.WorkflowDocumentService)4 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)4 CuElectronicInvoiceRejectDocument (edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument)3 HashMap (java.util.HashMap)3 AccountGlobal (org.kuali.kfs.coa.businessobject.AccountGlobal)3 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)3 Note (org.kuali.kfs.krad.bo.Note)3 Document (org.kuali.kfs.krad.document.Document)3