use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class EzraServiceImpl method routeAwardDocument.
private void routeAwardDocument(Award award, Award oldAward) {
GlobalVariables.clear();
GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
// DocumentService docService = SpringContext.getBean(DocumentService.class);
MaintenanceDocument awardDoc = null;
try {
awardDoc = (MaintenanceDocument) documentService.getNewDocument("AWRD");
} catch (WorkflowException we) {
we.printStackTrace();
}
LOG.info("Created a new Award doc. " + award.getProposalNumber());
awardDoc.getDocumentHeader().setDocumentDescription("Auto creation of new award : " + award.getProposalNumber());
if (ObjectUtils.isNotNull(oldAward)) {
awardDoc.getOldMaintainableObject().setBusinessObject(oldAward);
award.setVersionNumber(oldAward.getVersionNumber());
awardDoc.getDocumentHeader().setDocumentDescription(award.getProposalNumber() + " by auto edit");
}
awardDoc.getNewMaintainableObject().setBusinessObject(award);
;
try {
documentService.saveDocument(awardDoc);
// documentService.routeDocument(awardDoc, "Automatically created and routed", null);
awardDoc.getDocumentHeader().getWorkflowDocument().route("Automatically created and routed");
} catch (WorkflowException we) {
we.printStackTrace();
} catch (RuntimeException rte) {
LOG.error(rte);
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuProcessPdpCancelPaidServiceImpl method processPdpCancel.
/**
* Default implementation uses most of the "while" loop contents from the ProcessPdpCancelPaidServiceImpl.processPdpCancels method,
* with additional CU-related changes as needed. This implementation also runs within its own transaction.
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public void processPdpCancel(PaymentDetail paymentDetail, Date processDate) {
String documentTypeCode = paymentDetail.getFinancialDocumentTypeCode();
String documentNumber = paymentDetail.getCustPaymentDocNbr();
boolean primaryCancel = paymentDetail.getPrimaryCancelledPayment();
boolean disbursedPayment = PdpConstants.PaymentStatusCodes.CANCEL_PAYMENT.equals(paymentDetail.getPaymentGroup().getPaymentStatusCode());
// KFSPTS-2719
boolean crCancel = false;
PaymentDetailExtendedAttribute paymentDetailExtendedAttribute = (PaymentDetailExtendedAttribute) paymentDetail.getExtension();
if (ObjectUtils.isNotNull(paymentDetailExtendedAttribute)) {
crCancel = paymentDetailExtendedAttribute.getCrCancelledPayment();
}
if (purchasingAccountsPayableModuleService.isPurchasingBatchDocument(documentTypeCode)) {
((CuPurchasingAccountsPayableModuleService) purchasingAccountsPayableModuleService).handlePurchasingBatchCancels(documentNumber, documentTypeCode, primaryCancel, disbursedPayment, crCancel);
} else {
PaymentSourceToExtractService<PaymentSource> extractService = getPaymentSourceToExtractService(paymentDetail);
if (extractService != null) {
try {
PaymentSource dv = (PaymentSource) documentService.getByDocumentHeaderId(documentNumber);
if (dv != null) {
if (disbursedPayment || primaryCancel || crCancel) {
if (!crCancel) {
extractService.cancelPayment(dv, processDate);
}
} else {
extractService.resetFromExtraction(dv);
}
}
} catch (WorkflowException we) {
throw new RuntimeException("Could not retrieve document #" + documentNumber, we);
}
} else {
LOG.warn("processPdpCancel() Unknown document type (" + documentTypeCode + ") for document ID: " + documentNumber);
return;
}
}
paymentGroupService.processCancelledGroup(paymentDetail.getPaymentGroup(), processDate);
}
use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class PaymentWorksDataProcessingIntoKfsServiceImpl method createKfsVendorMaintenaceDocument.
private MaintenanceDocument createKfsVendorMaintenaceDocument(PaymentWorksVendor pmwVendor, Map<String, List<PaymentWorksIsoFipsCountryItem>> paymentWorksIsoToFipsCountryMap, Map<String, SupplierDiversity> paymentWorksToKfsDiversityMap, PaymentWorksNewVendorRequestsBatchReportData reportData) {
MaintenanceDocument vendorMaintenceDoc = null;
try {
KfsVendorDataWrapper kfsVendorDataWrapper = getPaymentWorksVendorToKfsVendorDetailConversionService().createKfsVendorDetailFromPmwVendor(pmwVendor, paymentWorksIsoToFipsCountryMap, paymentWorksToKfsDiversityMap);
if (kfsVendorDataWrapper.noProcessingErrorsGenerated()) {
vendorMaintenceDoc = buildVendorMaintenanceDocument(pmwVendor, kfsVendorDataWrapper);
LOG.info("createKfsVendorMaintenaceDocument: vendorMaintenceDoc created for pmwVendorId = " + pmwVendor.getPmwVendorRequestId());
} else {
reportData.getPendingPaymentWorksVendorsThatCouldNotBeProcessed().incrementRecordCount();
reportData.addPmwVendorsThatCouldNotBeProcessed(new PaymentWorksBatchReportRawDataItem(pmwVendor.toString(), kfsVendorDataWrapper.getErrorMessages()));
LOG.info("createKfsVendorMaintenaceDocument: vendorMaintenceDoc not created due to pmw-to-kfs data conversion error(s): " + kfsVendorDataWrapper.getErrorMessages().toString());
}
} catch (WorkflowException we) {
List<String> edocCreateErrors = convertReportDataValidationErrors(GlobalVariables.getMessageMap().getErrorMessages());
captureKfsProcessingErrorsForVendor(pmwVendor, reportData, edocCreateErrors);
LOG.error("createKfsVendorMaintenaceDocument: eDoc creation error(s): " + edocCreateErrors.toString());
LOG.error("createKfsVendorMaintenaceDocument: eDoc creation exception caught: " + we.getMessage());
vendorMaintenceDoc = null;
} finally {
GlobalVariables.getMessageMap().clearErrorMessages();
}
return vendorMaintenceDoc;
}
use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method createPaymentRequest.
protected PaymentRequestDocument createPaymentRequest(ElectronicInvoiceOrderHolder orderHolder) {
LOG.info("Creating Payment Request document");
KNSGlobalVariables.getMessageList().clear();
validateInvoiceOrderValidForPREQCreation(orderHolder);
if (LOG.isInfoEnabled()) {
if (orderHolder.isInvoiceRejected()) {
LOG.info("Not possible to convert einvoice details into payment request");
} else {
LOG.info("Payment request document creation validation succeeded");
}
}
if (orderHolder.isInvoiceRejected()) {
return null;
}
PaymentRequestDocument preqDoc = null;
try {
preqDoc = (PaymentRequestDocument) SpringContext.getBean(DocumentService.class).getNewDocument("PREQ");
} catch (WorkflowException e) {
String extraDescription = "Error=" + e.getMessage();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_WORKLOW_EXCEPTION, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
LOG.error("Error creating Payment request document - " + e.getMessage());
return null;
}
PurchaseOrderDocument poDoc = orderHolder.getPurchaseOrderDocument();
if (poDoc == null) {
throw new RuntimeException("Purchase Order document (POId=" + poDoc.getPurapDocumentIdentifier() + ") does not exist in the system");
}
preqDoc.getDocumentHeader().setDocumentDescription(generatePREQDocumentDescription(poDoc));
try {
preqDoc.updateAndSaveAppDocStatus(PurapConstants.PaymentRequestStatuses.APPDOC_IN_PROCESS);
} catch (WorkflowException we) {
throw new RuntimeException("Unable to save route status data for document: " + preqDoc.getDocumentNumber(), we);
}
preqDoc.setInvoiceDate(orderHolder.getInvoiceDate());
preqDoc.setInvoiceNumber(orderHolder.getInvoiceNumber());
preqDoc.setVendorInvoiceAmount(new KualiDecimal(orderHolder.getInvoiceNetAmount()));
preqDoc.setAccountsPayableProcessorIdentifier("E-Invoice");
preqDoc.setVendorCustomerNumber(orderHolder.getCustomerNumber());
preqDoc.setPaymentRequestElectronicInvoiceIndicator(true);
if (orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
preqDoc.setAccountsPayablePurchasingDocumentLinkIdentifier(orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier());
}
// Copied from PaymentRequestServiceImpl.populatePaymentRequest()
// set bank code to default bank code in the system parameter
// KFSPTS-1891
boolean hasPaymentMethodCode = false;
if (preqDoc instanceof PaymentRequestDocument) {
String vendorPaymentMethodCode = ((VendorDetailExtension) poDoc.getVendorDetail().getExtension()).getDefaultB2BPaymentMethodCode();
if (StringUtils.isNotEmpty(vendorPaymentMethodCode)) {
((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(vendorPaymentMethodCode);
hasPaymentMethodCode = true;
} else {
((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(DEFAULT_EINVOICE_PAYMENT_METHOD_CODE);
}
}
Bank defaultBank = null;
if (hasPaymentMethodCode) {
defaultBank = SpringContext.getBean(CUPaymentMethodGeneralLedgerPendingEntryService.class).getBankForPaymentMethod(((CuPaymentRequestDocument) preqDoc).getPaymentMethodCode());
} else {
// default to baseline behavior - extended documents not in use
// Copied from PaymentRequestServiceImpl.populatePaymentRequest()
// set bank code to default bank code in the system parameter
defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(PaymentRequestDocument.class);
}
if (defaultBank != null) {
preqDoc.setBankCode(defaultBank.getBankCode());
preqDoc.setBank(defaultBank);
}
RequisitionDocument reqDoc = SpringContext.getBean(RequisitionService.class).getRequisitionById(poDoc.getRequisitionIdentifier());
String reqDocInitiator = reqDoc.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
try {
Person user = KimApiServiceLocator.getPersonService().getPerson(reqDocInitiator);
setProcessingCampus(preqDoc, user.getCampusCode());
} catch (Exception e) {
String extraDescription = "Error setting processing campus code - " + e.getMessage();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList = SpringContext.getBean(AccountsPayableService.class).expiredOrClosedAccountsList(poDoc);
if (expiredOrClosedAccountList == null) {
expiredOrClosedAccountList = new HashMap();
}
if (LOG.isInfoEnabled()) {
LOG.info(expiredOrClosedAccountList.size() + " accounts has been found as Expired or Closed");
}
preqDoc.populatePaymentRequestFromPurchaseOrder(orderHolder.getPurchaseOrderDocument(), expiredOrClosedAccountList);
// need to populate here for ext price. it become per item
// KFSPTS-1719. convert 1st matching inv item that is qty, but po is non-qty
checkQtyInvItemForNoQtyOrder(preqDoc, orderHolder);
populateItemDetails(preqDoc, orderHolder);
// KFSUPGRADE-485, KFSPTS-1719
if (CollectionUtils.isNotEmpty(((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems())) {
for (ElectronicInvoiceItemHolder invItem : ((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems()) {
PurchaseOrderItem item = (PurchaseOrderItem) ObjectUtils.deepCopy((Serializable) orderHolder.getPurchaseOrderDocument().getItems().get(invItem.getInvoiceItemLineNumber() - 1));
item.setItemLineNumber(invItem.getInvoiceItemLineNumber());
item.setItemDescription(((CuElectronicInvoiceItemHolder) invItem).getReferenceDescription());
// this will be populated to reqitem.poitemunitprice
item.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
PaymentRequestItem paymentRequestItem = new PaymentRequestItem(item, preqDoc, expiredOrClosedAccountList);
((CuPaymentRequestItemExtension) paymentRequestItem.getExtension()).setInvLineNumber(Integer.parseInt(((CuElectronicInvoiceItemHolder) invItem).getInvLineNumber()));
// need following in case inv item is qty item
paymentRequestItem.setItemQuantity(new KualiDecimal(invItem.getInvoiceItemQuantity()));
paymentRequestItem.setItemUnitOfMeasureCode(invItem.getInvoiceItemUnitOfMeasureCode());
paymentRequestItem.setPurchaseOrderItemUnitPrice(invItem.getInvoiceItemUnitPrice());
// if non qty don't need this unit price set, then this need to have a check
if (invItem.getInvoiceItemQuantity() != null && (new KualiDecimal(invItem.getInvoiceItemQuantity())).isPositive()) {
paymentRequestItem.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
}
paymentRequestItem.setItemCatalogNumber(invItem.getCatalogNumberStripped());
preqDoc.getItems().add(paymentRequestItem);
((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem((CuElectronicInvoiceItemHolder) invItem);
populateItemDetailsForNonMatching(preqDoc, orderHolder);
((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem(null);
}
}
/**
* Validate totals,paydate
*/
// PaymentRequestDocumentRule.processCalculateAccountsPayableBusinessRules
SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedCalculateAccountsPayableEvent(preqDoc));
SpringContext.getBean(PaymentRequestService.class).calculatePaymentRequest(preqDoc, true);
processItemsForDiscount(preqDoc, orderHolder);
if (orderHolder.isInvoiceRejected()) {
return null;
}
SpringContext.getBean(PaymentRequestService.class).calculatePaymentRequest(preqDoc, false);
/**
* PaymentRequestReview
*/
// PaymentRequestDocumentRule.processRouteDocumentBusinessRules
SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedPaymentRequestForEInvoiceEvent(preqDoc));
if (GlobalVariables.getMessageMap().hasErrors()) {
if (LOG.isInfoEnabled()) {
LOG.info("***************Error in rules processing - " + GlobalVariables.getMessageMap());
}
Map<String, AutoPopulatingList<ErrorMessage>> errorMessages = GlobalVariables.getMessageMap().getErrorMessages();
String errors = errorMessages.toString();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, errors, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
if (KNSGlobalVariables.getMessageList().size() > 0) {
if (LOG.isInfoEnabled()) {
LOG.info("Payment request contains " + KNSGlobalVariables.getMessageList().size() + " warning message(s)");
for (int i = 0; i < KNSGlobalVariables.getMessageList().size(); i++) {
LOG.info("Warning " + i + " - " + KNSGlobalVariables.getMessageList().get(i));
}
}
}
addShipToNotes(preqDoc, orderHolder);
try {
// KFSUPGRADE-490: Do save-only operations for just non-EIRT-generated PREQs.
if (orderHolder.isRejectDocumentHolder()) {
SpringContext.getBean(DocumentService.class).routeDocument(preqDoc, null, null);
} else {
SpringContext.getBean(DocumentService.class).saveDocument(preqDoc, DocumentSystemSaveEvent.class);
}
} catch (WorkflowException e) {
e.printStackTrace();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_FAILURE, e.getMessage(), orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
} catch (ValidationException e) {
String extraDescription = GlobalVariables.getMessageMap().toString();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
return preqDoc;
}
use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method rejectElectronicInvoiceFile.
protected void rejectElectronicInvoiceFile(ElectronicInvoiceLoad eInvoiceLoad, String fileDunsNumber, File invoiceFile, String extraDescription, String rejectReasonTypeCode) {
if (LOG.isInfoEnabled()) {
LOG.info("Rejecting the entire invoice file - " + invoiceFile.getName());
}
ElectronicInvoiceLoadSummary eInvoiceLoadSummary = getOrCreateLoadSummary(eInvoiceLoad, fileDunsNumber);
eInvoiceLoadSummary.addFailedInvoiceOrder();
eInvoiceLoad.insertInvoiceLoadSummary(eInvoiceLoadSummary);
ElectronicInvoiceRejectDocument eInvoiceRejectDocument = null;
try {
eInvoiceRejectDocument = (ElectronicInvoiceRejectDocument) SpringContext.getBean(DocumentService.class).getNewDocument("EIRT");
eInvoiceRejectDocument.setInvoiceProcessTimestamp(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
eInvoiceRejectDocument.setVendorDunsNumber(fileDunsNumber);
eInvoiceRejectDocument.setDocumentCreationInProgress(true);
if (invoiceFile != null) {
eInvoiceRejectDocument.setInvoiceFileName(invoiceFile.getName());
}
List<ElectronicInvoiceRejectReason> list = new ArrayList<ElectronicInvoiceRejectReason>(1);
String message = "Complete failure document has been created for the Invoice with Filename '" + invoiceFile.getName() + "' due to the following error:\n";
emailTextErrorList.append(message);
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(rejectReasonTypeCode, extraDescription, invoiceFile.getName());
list.add(rejectReason);
emailTextErrorList.append(" - " + rejectReason.getInvoiceRejectReasonDescription());
emailTextErrorList.append("\n\n");
eInvoiceRejectDocument.setInvoiceRejectReasons(list);
eInvoiceRejectDocument.getDocumentHeader().setDocumentDescription("Complete failure");
// KFSCNTRB-1369: Need to Save document
SpringContext.getBean(DocumentService.class).saveDocument(eInvoiceRejectDocument);
String noteText = "Invoice file";
// if (invoiceFile.length() > 0) {
// empty file will casuse attachment creation exception. Hence, job will be stopped
attachInvoiceXMLWithRejectDoc(eInvoiceRejectDocument, invoiceFile, noteText);
// }
eInvoiceLoad.addInvoiceReject(eInvoiceRejectDocument);
} catch (WorkflowException e) {
throw new RuntimeException(e);
}
if (LOG.isInfoEnabled()) {
LOG.info("Complete failure document has been created (DocNo:" + eInvoiceRejectDocument.getDocumentNumber() + ")");
}
}
Aggregations