Search in sources :

Example 36 with WorkflowException

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

the class CuElectronicInvoiceHelperServiceImpl method createRejectDocument.

public ElectronicInvoiceRejectDocument createRejectDocument(ElectronicInvoice eInvoice, ElectronicInvoiceOrder electronicInvoiceOrder, ElectronicInvoiceLoad eInvoiceLoad) {
    LOG.info("Creating reject document [DUNS=" + eInvoice.getDunsNumber() + ",POID=" + electronicInvoiceOrder.getInvoicePurchaseOrderID() + "]");
    ElectronicInvoiceRejectDocument eInvoiceRejectDocument;
    try {
        eInvoiceRejectDocument = (ElectronicInvoiceRejectDocument) SpringContext.getBean(DocumentService.class).getNewDocument("EIRT");
        eInvoiceRejectDocument.setInvoiceProcessTimestamp(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
        String rejectdocDesc = generateRejectDocumentDescription(eInvoice, electronicInvoiceOrder);
        eInvoiceRejectDocument.getDocumentHeader().setDocumentDescription(rejectdocDesc);
        eInvoiceRejectDocument.setDocumentCreationInProgress(true);
        eInvoiceRejectDocument.setFileLevelData(eInvoice);
        eInvoiceRejectDocument.setInvoiceOrderLevelData(eInvoice, electronicInvoiceOrder);
        SpringContext.getBean(DocumentService.class).saveDocument(eInvoiceRejectDocument);
        String noteText = "Invoice file";
        attachInvoiceXMLWithRejectDoc(eInvoiceRejectDocument, getInvoiceFile(eInvoice.getFileName()), noteText);
        eInvoiceLoad.addInvoiceReject(eInvoiceRejectDocument);
    } catch (WorkflowException e) {
        throw new RuntimeException(e);
    }
    LOG.info("Reject document has been created (DocNo=" + eInvoiceRejectDocument.getDocumentNumber() + ")");
    emailTextErrorList.append("DUNS Number - " + eInvoice.getDunsNumber() + " " + eInvoice.getVendorName() + ":\n");
    emailTextErrorList.append("An e-invoice from file '" + eInvoice.getFileName() + "' has been rejected due to the following error(s):\n");
    // get note text max length from DD
    int noteTextMaxLength = NOTE_TEXT_DEFAULT_MAX_LENGTH;
    Integer noteTextLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(Note.class, KRADConstants.NOTE_TEXT_PROPERTY_NAME);
    if (noteTextLength != null) {
        noteTextMaxLength = noteTextLength.intValue();
    }
    // KFSUPGRADE-489/KITI-2643 - Modified to fix bug reported in KFSPTS-292
    // Ensure that we don't overflow the maximum size of the note by creating
    // separate notes if necessary.
    ArrayList<StringBuffer> rejectReasonNotes = new ArrayList<StringBuffer>();
    StringBuffer rejectReasonNote = new StringBuffer();
    String rejectReason = "";
    rejectReasonNote.append("This reject document has been created because of the following reason(s):\n");
    int index = 1;
    for (ElectronicInvoiceRejectReason reason : eInvoiceRejectDocument.getInvoiceRejectReasons()) {
        emailTextErrorList.append("    - " + reason.getInvoiceRejectReasonDescription() + "\n");
        emailTextErrorList.append("    - PO  " + eInvoiceRejectDocument.getPurchaseOrderIdentifier() + "\n");
        emailTextErrorList.append("    - EIRT  " + eInvoiceRejectDocument.getDocumentNumber() + "\n");
        // addRejectReasonsToNote("Reject Reason " + index + ". " + reason.getInvoiceRejectReasonDescription(), eInvoiceRejectDocument);
        rejectReason = " " + index + ". " + reason.getInvoiceRejectReasonDescription() + "\n";
        if (rejectReasonNote.length() + rejectReason.length() > noteTextMaxLength) {
            rejectReasonNotes.add(rejectReasonNote);
            rejectReasonNote = new StringBuffer();
            rejectReasonNote.append("Reject document creation reasons continued:\n");
        }
        rejectReasonNote.append(rejectReason);
        index++;
    }
    rejectReasonNotes.add(rejectReasonNote);
    emailTextErrorList.append("\n");
    for (StringBuffer noteText : rejectReasonNotes) {
        addRejectReasonsToNote(noteText.toString(), eInvoiceRejectDocument);
    }
    return eInvoiceRejectDocument;
}
Also used : ElectronicInvoiceRejectDocument(org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument) CuElectronicInvoiceRejectDocument(edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) ElectronicInvoiceRejectReason(org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceRejectReason) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) DocumentService(org.kuali.kfs.krad.service.DocumentService) FinancialSystemDocumentService(org.kuali.kfs.sys.document.service.FinancialSystemDocumentService) DataDictionaryService(org.kuali.kfs.krad.service.DataDictionaryService)

Example 37 with WorkflowException

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

the class CuElectronicInvoiceHelperServiceImpl method routePREQDocuments.

/**
 * @return
 */
protected boolean routePREQDocuments() {
    Collection<String> documentIdList = null;
    try {
        documentIdList = retrieveDocumentsToRoute(KewApiConstants.ROUTE_HEADER_SAVED_CD, PaymentRequestDocument.class);
    } catch (WorkflowException e1) {
        LOG.error("Error retrieving preq documents for routing: " + e1.getMessage(), e1);
        throw new RuntimeException(e1.getMessage(), e1);
    } catch (RemoteException re) {
        LOG.error("Error retrieving preq documents for routing: " + re.getMessage(), re);
        throw new RuntimeException(re.getMessage(), re);
    }
    // Collections.reverse(documentIdList);
    LOG.info("PREQs to Route: " + documentIdList);
    DocumentService documentService = SpringContext.getBean(DocumentService.class);
    WorkflowDocumentService workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
    for (String preqDocumentId : documentIdList) {
        try {
            LOG.info("Retrieving PREQ document # " + preqDocumentId + ".");
            PaymentRequestDocument preqDocument = (PaymentRequestDocument) documentService.getByDocumentHeaderId(preqDocumentId);
            LOG.info("Routing PREQ document # " + preqDocumentId + ".");
            if (preqDocument.getPaymentRequestElectronicInvoiceIndicator()) {
                documentService.prepareWorkflowDocument(preqDocument);
                LOG.info("PREQ document # " + preqDocumentId + " prepared for workflow.");
                // calling workflow service to bypass business rule checks
                workflowDocumentService.route(preqDocument.getDocumentHeader().getWorkflowDocument(), "Routed by electronic invoice batch job", null);
                LOG.info("PREQ document # " + preqDocumentId + " routed.");
            }
        } catch (WorkflowException e) {
            LOG.error("Error routing document # " + preqDocumentId + " " + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return true;
}
Also used : WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) RemoteException(java.rmi.RemoteException) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) DocumentService(org.kuali.kfs.krad.service.DocumentService) FinancialSystemDocumentService(org.kuali.kfs.sys.document.service.FinancialSystemDocumentService)

Example 38 with WorkflowException

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

the class CuPdpExtractServiceImpl method updatePaymentRequest.

@Override
protected void updatePaymentRequest(PaymentRequestDocument paymentRequestDocument, Person puser, Date processRunDate) {
    try {
        PaymentRequestDocument doc = (PaymentRequestDocument) documentService.getByDocumentHeaderId(paymentRequestDocument.getDocumentNumber());
        doc.setExtractedTimestamp(new Timestamp(processRunDate.getTime()));
        SpringContext.getBean(PurapService.class).saveDocumentNoValidation(doc);
        // RICE20 replaced searchableAttributeProcessingService.indexDocument with DocumentAttributeIndexingQueue.indexDocument
        DocumentTypeService documentTypeService = SpringContext.getBean(DocumentTypeService.class);
        DocumentType documentType = documentTypeService.getDocumentTypeByName(doc.getFinancialDocumentTypeCode());
        DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(documentType.getApplicationId());
        queue.indexDocument(doc.getDocumentNumber());
    } catch (WorkflowException e) {
        throw new IllegalArgumentException("Unable to retrieve payment request: " + paymentRequestDocument.getDocumentNumber());
    }
}
Also used : PurapService(org.kuali.kfs.module.purap.document.service.PurapService) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DocumentType(org.kuali.rice.kew.api.doctype.DocumentType) DocumentAttributeIndexingQueue(org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) DocumentTypeService(org.kuali.rice.kew.api.doctype.DocumentTypeService) Timestamp(java.sql.Timestamp)

Example 39 with WorkflowException

use of org.kuali.rice.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.rice.kew.api.exception.WorkflowException) Document(org.kuali.kfs.krad.document.Document)

Example 40 with WorkflowException

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

the class CuDisbursementVoucherExtractionHelperServiceImplTest method test.

public void test() {
    CuDisbursementVoucherDocument dv = null;
    try {
        dv = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
    } catch (WorkflowException e) {
        throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
    }
    if (dv != null) {
        dv.getDocumentHeader().setDocumentDescription("Test Document Description");
        dv.getDocumentHeader().setExplanation("Stuff");
        dv.initiateDocument();
        VendorDetail vendor = SpringContext.getBean(VendorService.class).getVendorDetail("13366-0");
        VendorAddress vendoraddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), "RM", "");
        System.out.println(vendoraddress.getVendorCityName() + "\n");
        dv.templateVendor(vendor, vendoraddress);
        dv.setPayeeAssigned(true);
        dv.getDvPayeeDetail().setDisbVchrPaymentReasonCode("S");
        dv.setDisbVchrCheckTotalAmount(new KualiDecimal(86.00));
        dv.setDisbVchrPaymentMethodCode("P");
        dv.setDisbVchrCheckStubText("check text");
        dv.setCampusCode("IT");
        SourceAccountingLine accountingLine = new SourceAccountingLine();
        accountingLine.setChartOfAccountsCode("IT");
        accountingLine.setAccountNumber("G081040");
        accountingLine.setFinancialObjectCode("2045");
        accountingLine.setAmount((new KualiDecimal(86.00)));
        accountingLine.setPostingYear(dv.getPostingYear());
        accountingLine.setDocumentNumber(dv.getDocumentNumber());
        dv.addSourceAccountingLine(accountingLine);
        try {
            documentService.saveDocument(dv);
        } catch (WorkflowException e) {
            throw new RuntimeException("Error saving new disbursement voucher document: " + e.getMessage(), e);
        }
    }
    Date transactionTimestamp = new Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime());
    Date processRunDate = new java.sql.Date(transactionTimestamp.getTime());
    PaymentGroup pg = cuDisbursementVoucherExtractionHelperService.createPaymentGroup(dv, processRunDate);
    assertTrue(pg.getPaymentDetails().get(0).getCustPaymentDocNbr().equalsIgnoreCase(dv.getDocumentNumber()));
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) DocumentService(org.kuali.kfs.krad.service.DocumentService) Date(java.sql.Date) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorService(org.kuali.kfs.vnd.document.service.VendorService) CuDisbursementVoucherDocument(edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService)

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