Search in sources :

Example 6 with WorkflowException

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

the class RecurringDisbursementVoucherDocumentServiceImpl method addNoteToAutoApproveDv.

private void addNoteToAutoApproveDv(CuDisbursementVoucherDocument dv, String noteText) throws WorkflowException {
    Note note = buildNoteBase();
    note.setNoteText(noteText);
    dv.addNote(note);
    try {
        getDocumentService().saveDocument(dv);
    } catch (WorkflowException e) {
        LOG.error("addNoteToAutoApproveDv: Unable to save note for DV Document ID::" + dv.getDocumentNumber() + "the exception was: ", e);
        throw e;
    }
}
Also used : Note(org.kuali.kfs.krad.bo.Note) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException)

Example 7 with WorkflowException

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

the class CuContractsAndGrantsResponsibilityPlusPayPeriodRoleTypeServiceImpl method documentIsWithinPayPeriodLimit.

/*
     * Helper method for determining if the difference between the document's create date period and
     * the earliest account pay period is within the given limit. Assumed to be within limit unless
     * proven otherwise.
     */
private boolean documentIsWithinPayPeriodLimit(String documentNumber, int limit) {
    boolean withinLimit = true;
    AccountingDocument document;
    // Get the document, which is expected to be an accounting one.
    try {
        document = (AccountingDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(documentNumber);
    } catch (WorkflowException e) {
        document = null;
    } catch (ClassCastException e) {
        document = null;
    }
    // Skip non-existent or non-retrievable documents, and have them default to within-limit routing.
    if (document == null) {
        return true;
    }
    // Make sure source/target lines containing the extra labor-ledger-related data actually exist on the document.
    boolean hasLLSourceLine = document.getSourceAccountingLineClass() != null && CollectionUtils.isNotEmpty(document.getSourceAccountingLines()) && LaborLedgerExpenseTransferAccountingLine.class.isAssignableFrom(document.getSourceAccountingLineClass());
    boolean hasLLTargetLine = document.getTargetAccountingLineClass() != null && CollectionUtils.isNotEmpty(document.getTargetAccountingLines()) && LaborLedgerExpenseTransferAccountingLine.class.isAssignableFrom(document.getTargetAccountingLineClass());
    if (hasLLSourceLine || hasLLTargetLine) {
        // Locate the earliest source/target line.
        LaborLedgerExpenseTransferAccountingLine earliestLine = null;
        if (hasLLSourceLine) {
            earliestLine = findEarliestPayPeriodAccountingLine(document.getSourceAccountingLines());
        }
        if (hasLLTargetLine) {
            if (earliestLine != null) {
                LaborLedgerExpenseTransferAccountingLine earliestTargetLine = findEarliestPayPeriodAccountingLine(document.getTargetAccountingLines());
                earliestLine = (earliestTargetLine == null) ? earliestLine : findEarliestPayPeriodAccountingLine(Arrays.asList(earliestLine, earliestTargetLine));
            } else {
                earliestLine = findEarliestPayPeriodAccountingLine(document.getTargetAccountingLines());
            }
        }
        // If an earliest line was found, then proceed with the within-limit determination.
        if (earliestLine != null) {
            // Prepare helper constants.
            final int NUM_MONTHS = 12;
            final int FY_OFFSET = 6;
            // Get the creation date, and calculate its corresponding fiscal year and pay period.
            DateTime dateCreated = document.getDocumentHeader().getWorkflowDocument().getDateCreated();
            int dateCreatedFiscalYear;
            int dateCreatedPayPeriod = dateCreated.getMonthOfYear() + FY_OFFSET;
            if (dateCreatedPayPeriod > NUM_MONTHS) {
                dateCreatedPayPeriod -= NUM_MONTHS;
            }
            dateCreatedFiscalYear = dateCreated.getYear() + ((dateCreatedPayPeriod <= FY_OFFSET) ? 1 : 0);
            // Determine difference between the pay period the doc was created in and the earliest impacted source/target account's pay period.
            int payPeriodDifference = ((dateCreatedFiscalYear - earliestLine.getPayrollEndDateFiscalYear().intValue()) * NUM_MONTHS) + dateCreatedPayPeriod - Integer.parseInt(earliestLine.getPayrollEndDateFiscalPeriodCode());
            // Set flag based on whether the difference is within the limit for standard Award node routing.
            withinLimit = payPeriodDifference <= limit;
        }
    }
    return withinLimit;
}
Also used : LaborLedgerExpenseTransferAccountingLine(org.kuali.kfs.integration.ld.LaborLedgerExpenseTransferAccountingLine) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) DateTime(org.joda.time.DateTime)

Example 8 with WorkflowException

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

the class CuPurchaseOrderAmendmentDocument method isSeparationOfDutiesReviewRequired.

protected boolean isSeparationOfDutiesReviewRequired() {
    try {
        Set<Person> priorApprovers = getAllPriorApprovers();
        // 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);
    }
    ParameterService parameterService = SpringContext.getBean(ParameterService.class);
    KualiDecimal maxAllowedAmount = new KualiDecimal(parameterService.getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.SEPARATION_OF_DUTIES_DOLLAR_AMOUNT));
    // if app param amount is greater than or equal to documentTotalAmount... no need for separation of duties
    KualiDecimal totalAmount = getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount();
    if (ObjectUtils.isNotNull(maxAllowedAmount) && ObjectUtils.isNotNull(totalAmount) && (maxAllowedAmount.compareTo(totalAmount) >= 0)) {
        return false;
    } else {
        return true;
    }
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) Person(org.kuali.kfs.kim.api.identity.Person)

Example 9 with WorkflowException

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

the class CuPurapServiceImpl method saveRoutingDataForRelatedDocuments.

// ==== CU Customization (KFSPTS-1656): Save IWantDocument routing data. ====
@Override
public void saveRoutingDataForRelatedDocuments(Integer accountsPayablePurchasingDocumentLinkIdentifier) {
    super.saveRoutingDataForRelatedDocuments(accountsPayablePurchasingDocumentLinkIdentifier);
    try {
        // Save IWNT routing data.
        @SuppressWarnings("unchecked") List<IWantView> iWantViews = getRelatedViews(IWantView.class, accountsPayablePurchasingDocumentLinkIdentifier);
        for (Iterator<IWantView> iterator = iWantViews.iterator(); iterator.hasNext(); ) {
            IWantView view = (IWantView) iterator.next();
            Document doc = documentService.getByDocumentHeaderId(view.getDocumentNumber());
            doc.getDocumentHeader().getWorkflowDocument().saveDocumentData();
        }
    } catch (WorkflowException e) {
        throw new InfrastructureException("unable to save routing data for related docs", e);
    }
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) IWantView(edu.cornell.kfs.module.purap.businessobject.IWantView) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) Document(org.kuali.kfs.krad.document.Document) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) InfrastructureException(org.kuali.kfs.krad.exception.InfrastructureException)

Example 10 with WorkflowException

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

the class CuReceivingServiceImpl method spawnPoAmendmentForUnorderedItems.

protected void spawnPoAmendmentForUnorderedItems(ReceivingDocument receivingDocument, PurchaseOrderDocument po) {
    // if receiving line document
    if (receivingDocument instanceof LineItemReceivingDocument) {
        LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) receivingDocument;
        // if a new item has been added spawn a purchase order amendment
        if (hasNewUnorderedItem((LineItemReceivingDocument) receivingDocument)) {
            String newSessionUserId = KFSConstants.SYSTEM_USER;
            try {
                LogicContainer logicToRun = new LogicContainer() {

                    @Override
                    public Object runLogic(Object[] objects) throws Exception {
                        LineItemReceivingDocument rlDoc = (LineItemReceivingDocument) objects[0];
                        String poDocNumber = (String) objects[1];
                        // create a PO amendment
                        PurchaseOrderAmendmentDocument amendmentPo = (PurchaseOrderAmendmentDocument) purchaseOrderService.createAndSavePotentialChangeDocument(poDocNumber, PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT, PurchaseOrderStatuses.APPDOC_AMENDMENT);
                        // KFSPTS-1769, KFSUPGRADE-339
                        ((CuPurchaseOrderAmendmentDocument) amendmentPo).setSpawnPoa(true);
                        // add new lines to amendement
                        addUnorderedItemsToAmendment(amendmentPo, rlDoc);
                        // route amendment
                        documentService.routeDocument(amendmentPo, null, null);
                        // add note to amendment po document
                        String note = "Purchase Order Amendment " + amendmentPo.getPurapDocumentIdentifier() + " (document id " + amendmentPo.getDocumentNumber() + ") created for new unordered line items due to Receiving (document id " + rlDoc.getDocumentNumber() + ")";
                        Note noteObj = documentService.createNoteFromDocument(amendmentPo, note);
                        amendmentPo.addNote(noteObj);
                        noteService.save(noteObj);
                        return null;
                    }
                };
                purapService.performLogicWithFakedUserSession(newSessionUserId, logicToRun, new Object[] { rlDoc, po.getDocumentNumber() });
            } catch (WorkflowException e) {
                String errorMsg = "Workflow Exception caught: " + e.getLocalizedMessage();
                throw new RuntimeException(errorMsg, e);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) CuPurchaseOrderAmendmentDocument(edu.cornell.kfs.module.purap.document.CuPurchaseOrderAmendmentDocument) LineItemReceivingDocument(org.kuali.kfs.module.purap.document.LineItemReceivingDocument) Note(org.kuali.kfs.krad.bo.Note) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) LogicContainer(org.kuali.kfs.module.purap.document.service.LogicContainer) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException)

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