Search in sources :

Example 1 with WorkflowException

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

the class AdvanceDepositServiceImpl method createAdvanceDepositDocument.

/**
 * Creates a AdvanceDepositDocument from the List of transactions given.
 *
 * @param transaction List of CashReceiptDocument objects to be used for creating the document.
 * @return A AdvanceDepositDocument populated with the transactions provided.
 */
protected AdvanceDepositDocument createAdvanceDepositDocument(AchIncomeTransaction transaction) {
    AdvanceDepositDocument advanceDepositDocument;
    try {
        String detailReferenceNumber = parameterService.getParameterValueAsString(GenerateAdvanceDepositDocumentsStep.class, CuFPParameterConstants.AdvanceDepositDocument.DETAIL_REFERENCE_NUMBER);
        String detailDescription = parameterService.getParameterValueAsString(GenerateAdvanceDepositDocumentsStep.class, CuFPParameterConstants.AdvanceDepositDocument.DETAIL_DESCRIPTION);
        String bankCode = parameterService.getParameterValueAsString(GenerateAdvanceDepositDocumentsStep.class, CuFPParameterConstants.AdvanceDepositDocument.BANK_CODE);
        String documentDescription = parameterService.getParameterValueAsString(GenerateAdvanceDepositDocumentsStep.class, CuFPParameterConstants.AdvanceDepositDocument.DOCUMENT_DESCRIPTION);
        advanceDepositDocument = (AdvanceDepositDocument) documentService.getNewDocument(KFSConstants.FinancialDocumentTypeCodes.ADVANCE_DEPOSIT);
        advanceDepositDocument.getDocumentHeader().setDocumentDescription(documentDescription);
        advanceDepositDocument.setCampusLocationCode(CuFPConstants.ADVANCE_DEPOSIT_DEFAULT_CAMPUS_CODE);
        advanceDepositDocument.setDepositDate(dateTimeService.convertToSqlDate(transaction.getBankTimestamp()));
        createSourceAccountingLine(transaction, advanceDepositDocument);
        AdvanceDepositDetail advanceDepositDetail = new AdvanceDepositDetail();
        advanceDepositDetail.setDocumentNumber(advanceDepositDocument.getDocumentNumber());
        advanceDepositDetail.setFinancialDocumentAdvanceDepositDate(dateTimeService.convertToSqlDate(transaction.getLoadTimestamp()));
        advanceDepositDetail.setFinancialDocumentAdvanceDepositAmount(transaction.getTransactionAmount());
        advanceDepositDetail.setFinancialDocumentAdvanceDepositReferenceNumber(detailReferenceNumber);
        advanceDepositDetail.setFinancialDocumentAdvanceDepositDescription(detailDescription);
        advanceDepositDetail.setFinancialDocumentBankCode(bankCode);
        Bank bank = bankService.getByPrimaryId(bankCode);
        advanceDepositDetail.setBank(bank);
        advanceDepositDocument.addAdvanceDeposit(advanceDepositDetail);
    } catch (WorkflowException | ParseException e) {
        LOG.error("Error creating advance deposit documents: " + e.getMessage(), e);
        throw new RuntimeException("Error creating advance deposit documents: " + e.getMessage(), e);
    }
    return advanceDepositDocument;
}
Also used : AdvanceDepositDetail(org.kuali.kfs.fp.businessobject.AdvanceDepositDetail) Bank(org.kuali.kfs.sys.businessobject.Bank) AdvanceDepositDocument(org.kuali.kfs.fp.document.AdvanceDepositDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ParseException(java.text.ParseException)

Example 2 with WorkflowException

use of org.kuali.rice.kew.api.exception.WorkflowException 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 3 with WorkflowException

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

the class AdvanceDepositServiceImpl method routeAdvanceDepositDocuments.

/**
 * @see AdvanceDepositService#routeAdvanceDepositDocuments()
 */
public boolean routeAdvanceDepositDocuments() {
    List<String> documentIdList;
    try {
        documentIdList = retrieveAdvanceDepositDocumentsToRoute(KewApiConstants.ROUTE_HEADER_SAVED_CD);
    } catch (WorkflowException | RemoteException e) {
        LOG.error("Error retrieving advance deposit documents for routing: " + e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
    if (LOG.isInfoEnabled()) {
        LOG.info("Advance deposit to Route: " + documentIdList);
    }
    for (String documentId : documentIdList) {
        try {
            AdvanceDepositDocument advanceDocument = (AdvanceDepositDocument) documentService.getByDocumentHeaderId(documentId);
            if (LOG.isInfoEnabled()) {
                LOG.info("Routing advance deposit document # " + documentId + ".");
            }
            documentService.routeDocument(advanceDocument, "document routed by achIncome batch job", null);
        } catch (Exception e) {
            LOG.error("Error routing document # " + documentId + " due to exception: " + e.getMessage());
            logException(e);
        }
    }
    return true;
}
Also used : WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) AdvanceDepositDocument(org.kuali.kfs.fp.document.AdvanceDepositDocument) RemoteException(java.rmi.RemoteException) ValidationException(org.kuali.kfs.krad.exception.ValidationException) MessagingException(javax.mail.MessagingException) ParseException(java.text.ParseException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) FormatException(org.kuali.rice.core.web.format.FormatException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) InvalidAddressException(org.kuali.kfs.krad.exception.InvalidAddressException) IOException(java.io.IOException)

Example 4 with WorkflowException

use of org.kuali.rice.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.rice.kew.api.exception.WorkflowException) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Person(org.kuali.rice.kim.api.identity.Person)

Example 5 with WorkflowException

use of org.kuali.rice.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.rice.kew.api.exception.WorkflowException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) DateTime(org.joda.time.DateTime)

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