use of org.kuali.kfs.krad.exception.ValidationException in project cu-kfs by CU-CommunityApps.
the class ConcurStandardAccountingExtractServiceImpl method loadConcurStandardAccountingExtractFile.
private ConcurStandardAccountingExtractFile loadConcurStandardAccountingExtractFile(String standardAccountingExtractFileName) {
ConcurStandardAccountingExtractFile concurStandardAccountingExtractFile;
File standardAccountingExtractFile = new File(standardAccountingExtractFileName);
List parsed = (List) batchInputFileService.parse(batchInputFileType, safelyLoadFileBytes(standardAccountingExtractFile));
if (parsed == null || parsed.size() != 1) {
LOG.error("parseStandardAccoutingExtractFileToStandardAccountingExtractFile, Unable to parse the file into exactly 1 POJO");
throw new ValidationException("parseStandardAccoutingExtractFileToStandardAccountingExtractFile, did not parse the file into exactly 1 parse file ");
}
concurStandardAccountingExtractFile = (ConcurStandardAccountingExtractFile) parsed.get(0);
concurStandardAccountingExtractFile.setOriginalFileName(standardAccountingExtractFile.getName());
return concurStandardAccountingExtractFile;
}
use of org.kuali.kfs.krad.exception.ValidationException in project cu-kfs by CU-CommunityApps.
the class AccountingXmlDocumentDownloadAttachmentServiceImpl method createAttachmentFromBackupLink.
@Override
public Attachment createAttachmentFromBackupLink(Document document, AccountingXmlDocumentBackupLink accountingXmlDocumentBackupLink) {
if (StringUtils.isBlank(accountingXmlDocumentBackupLink.getCredentialGroupCode())) {
LOG.error("createAttachmentFromBackupLink, the Credential Group Code is blank");
throw new ValidationException("Unable to download attachment with blank Credential Group Code: " + accountingXmlDocumentBackupLink.getLinkUrl());
}
try {
byte[] formFile = downloadByteArray(accountingXmlDocumentBackupLink);
if (formFile.length > 0) {
String uploadFileName = accountingXmlDocumentBackupLink.getFileName();
String mimeType = URLConnection.guessContentTypeFromName(uploadFileName);
int fileSize = (int) formFile.length;
String attachmentType = null;
if (LOG.isDebugEnabled()) {
LOG.debug("createAttachmentFromBackupLink, uploadFileName: " + uploadFileName + " mimeType: " + mimeType + " fileSize: " + fileSize);
}
InputStream inputStream = new ByteArrayInputStream(formFile);
Attachment attachment = attachmentService.createAttachment(document, uploadFileName, mimeType, fileSize, inputStream, attachmentType);
return attachment;
} else {
LOG.error("createAttachmentFromBackupLink, the form file is NULL");
throw new ValidationException("Unable to download attachment: " + accountingXmlDocumentBackupLink.getLinkUrl());
}
} catch (IOException e) {
LOG.error("createAttachmentFromBackupLink, Unable to download attachment: " + accountingXmlDocumentBackupLink.getLinkUrl(), e);
throw new ValidationException("Unable to download attachment: " + accountingXmlDocumentBackupLink.getLinkUrl());
}
}
use of org.kuali.kfs.krad.exception.ValidationException in project cu-kfs by CU-CommunityApps.
the class DisbursementVoucherDocumentBatchServiceImpl method loadDisbursementVouchers.
/**
* @see com.rsmart.kuali.kfs.fp.batch.service.DisbursementVoucherDocumentBatchService#loadDisbursementVouchers(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchFeed,
* com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchStatus, java.lang.String,
* org.kuali.kfs.kns.util.MessageMap)
*/
public void loadDisbursementVouchers(DisbursementVoucherBatchFeed batchFeed, DisbursementVoucherBatchStatus batchStatus, String incomingFileName, MessageMap MessageMap) {
// get new batch record for the load
DisbursementVoucherBatch disbursementVoucherBatch = getNewDisbursementVoucherBatch();
businessObjectService.save(disbursementVoucherBatch);
batchStatus.setUnitCode(batchFeed.getUnitCode());
boolean batchHasErrors = false;
for (BatchDisbursementVoucherDocument batchDisbursementVoucherDocument : batchFeed.getBatchDisbursementVoucherDocuments()) {
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_READ, 1);
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_READ, batchDisbursementVoucherDocument.getSourceAccountingLines().size());
// get defaults for DV chart/org
DisbursementVoucherBatchDefault batchDefault = null;
if (StringUtils.isNotBlank(batchFeed.getUnitCode())) {
batchDefault = getDisbursementVoucherBatchDefault(batchFeed.getUnitCode());
}
MessageMap documentMessageMap = new MessageMap();
batchFeedHelperService.performForceUppercase(DisbursementVoucherDocument.class.getName(), batchDisbursementVoucherDocument);
// create and route doc as system user
// create and route doc as system user
UserSession actualUserSession = GlobalVariables.getUserSession();
GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
MessageMap globalMessageMap = GlobalVariables.getMessageMap();
GlobalVariables.setMessageMap(documentMessageMap);
DisbursementVoucherDocument disbursementVoucherDocument = null;
try {
disbursementVoucherDocument = populateDisbursementVoucherDocument(disbursementVoucherBatch, batchDisbursementVoucherDocument, batchDefault, documentMessageMap);
// if the document is valid create GLPEs, Save and Approve
if (documentMessageMap.hasNoErrors()) {
businessObjectService.save(disbursementVoucherDocument.getExtension());
documentService.routeDocument(disbursementVoucherDocument, "", null);
if (documentMessageMap.hasNoErrors()) {
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_WRITTEN, 1);
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_WRITTEN, disbursementVoucherDocument.getSourceAccountingLines().size());
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_GLPE_RECORDS_WRITTEN, disbursementVoucherDocument.getGeneralLedgerPendingEntries().size());
batchStatus.getBatchDisbursementVoucherDocuments().add(disbursementVoucherDocument);
}
}
} catch (WorkflowException e) {
LOG.error("Unable to route DV: " + e.getMessage());
throw new RuntimeException("Unable to route DV: " + e.getMessage(), e);
} catch (ValidationException e1) {
// will be reported in audit report
} finally {
GlobalVariables.setUserSession(actualUserSession);
GlobalVariables.setMessageMap(globalMessageMap);
}
if (documentMessageMap.hasErrors()) {
batchHasErrors = true;
}
// populate summary line and add to report
DisbursementVoucherBatchSummaryLine batchSummaryLine = populateBatchSummaryLine(disbursementVoucherDocument, documentMessageMap);
batchStatus.getBatchSummaryLines().add(batchSummaryLine);
}
// indicate in global map there were errors (for batch upload screen)
if (batchHasErrors) {
MessageMap.putError(KFSConstants.GLOBAL_ERRORS, FPKeyConstants.ERROR_BATCH_DISBURSEMENT_VOUCHER_ERRORS_NOTIFICATION);
}
batchFeedHelperService.removeDoneFile(incomingFileName);
}
use of org.kuali.kfs.krad.exception.ValidationException in project cu-kfs by CU-CommunityApps.
the class DisencumbranceKualiBatchInputFileSetAction method save.
/**
* Override method to create a disencumbrance file for upload
*
* @see org.kuali.kfs.sys.web.struts.KualiBatchInputFileSetAction#save(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
DisencumbranceKualiBatchInputFileSetForm batchInputFileSetForm = (DisencumbranceKualiBatchInputFileSetForm) form;
BatchUpload batchUpload = ((KualiBatchInputFileSetForm) form).getBatchUpload();
BatchInputFileSetType batchType = retrieveBatchInputFileSetTypeImpl(batchUpload.getBatchInputTypeName());
boolean requiredValuesForFilesMissing = false;
boolean errorCreatingDisencFile = false;
if (StringUtils.isBlank(batchUpload.getFileUserIdentifer())) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SET_IDENTIFIER_SELECTED, new String[] {});
requiredValuesForFilesMissing = true;
}
BatchInputFileSetService batchInputFileSetService = SpringContext.getBean(BatchInputFileSetService.class);
if (!batchInputFileSetService.isFileUserIdentifierProperlyFormatted(batchUpload.getFileUserIdentifer())) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_SET_IDENTIFIER_BAD_FORMAT);
requiredValuesForFilesMissing = true;
}
Map<String, InputStream> typeToStreamMap = new HashMap<String, InputStream>();
String path = CUKFSConstants.STAGING_DIR + System.getProperty("file.separator") + CUKFSConstants.LD_DIR + System.getProperty("file.separator") + CUKFSConstants.ENTERPRISE_FEED_DIR;
String selectedDataFile = batchInputFileSetForm.getSelectedDataFile();
if (StringUtils.isNotEmpty(selectedDataFile)) {
String dataFilePath = BatchFileUtils.resolvePathToAbsolutePath(path + System.getProperty("file.separator") + selectedDataFile);
File dataFile = new File(dataFilePath).getAbsoluteFile();
if (dataFile == null) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SELECTED_SAVE_FOR_FILE_TYPE, new String[] { batchType.getFileTypeDescription().get(KFSConstants.DATA_FILE_TYPE) });
requiredValuesForFilesMissing = true;
} else {
// call service to create disencumbrance
LaborLedgerEnterpriseFeedService ldService = SpringContext.getBean(LaborLedgerEnterpriseFeedService.class);
InputStream disencumFileInputStream = null;
disencumFileInputStream = ldService.createDisencumbrance(new FileInputStream(dataFile));
if (disencumFileInputStream == null) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, CUKFSKeyConstants.MESSAGE_CREATE_DISENCUMBRANCE_ERROR);
errorCreatingDisencFile = true;
} else {
typeToStreamMap.put(KFSConstants.DATA_FILE_TYPE, disencumFileInputStream);
}
}
}
String selectedReconFile = batchInputFileSetForm.getSelectedReconFile();
if (StringUtils.isNotEmpty(selectedReconFile)) {
String reconFilePath = BatchFileUtils.resolvePathToAbsolutePath(path + System.getProperty("file.separator") + selectedReconFile);
File reconFile = new File(reconFilePath).getAbsoluteFile();
if (reconFile == null) {
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SELECTED_SAVE_FOR_FILE_TYPE, new String[] { batchType.getFileTypeDescription().get(KFSConstants.RECON_FILE_TYPE) });
requiredValuesForFilesMissing = true;
} else {
typeToStreamMap.put(KFSConstants.RECON_FILE_TYPE, new FileInputStream(reconFile));
}
}
if (requiredValuesForFilesMissing || errorCreatingDisencFile) {
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
try {
Map<String, String> typeToSavedFileNames = batchInputFileSetService.save(GlobalVariables.getUserSession().getPerson(), batchType, batchUpload.getFileUserIdentifer(), typeToStreamMap);
} catch (FileStorageException e) {
LOG.error("Error occured while trying to save file set (probably tried to save a file that already exists).", e);
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_SAVE_ERROR, new String[] { e.getMessage() });
return mapping.findForward(KFSConstants.MAPPING_BASIC);
} catch (ValidationException e) {
LOG.error("Error occured while trying to validate file set.", e);
GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_BATCH_UPLOAD_FILE_VALIDATION_ERROR);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
KNSGlobalVariables.getMessageList().add(CUKFSKeyConstants.MESSAGE_CREATE_DISENCUMBRANCE_SUCCESSFUL);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.krad.exception.ValidationException 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;
}
Aggregations