use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoad in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImplTest method testPaymentRequestDocumentCreation.
public void testPaymentRequestDocumentCreation() throws Exception {
String acceptFile = "accept.xml";
changeCurrentUser(UserNameFixture.ccs1);
RequisitionDocument reqDoc = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition();
Integer reqId = reqDoc.getPurapDocumentIdentifier();
changeCurrentUser(kfs);
PurchaseOrderDocument poDocument = createPODoc(reqId);
poDocument.setVendorShippingPaymentTermsCode("AL");
poDocument.setVendorPaymentTermsCode("00N30");
poDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(poDocument, documentService);
String poNumber = String.valueOf(poDocument.getPurapDocumentIdentifier());
String vendorDUNS = "133251074";
String xmlChunk = CuElectronicInvoiceHelperServiceFixture.getCXMLForPaymentDocCreation(vendorDUNS, poNumber);
writeXMLFile(xmlChunk, acceptFile);
ElectronicInvoiceLoad load = cuElectronicInvoiceHelperService.loadElectronicInvoices();
assertFalse(load.containsRejects());
File acceptedFileInAcceptDir = new File(electronicInvoiceInputFileType.getDirectoryPath() + File.separator + "accept" + File.separator + acceptFile);
assertTrue(acceptedFileInAcceptDir.exists());
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoad in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImplTest method testRejectDocumentCreationInvalidData.
public void testRejectDocumentCreationInvalidData() throws Exception {
String rejectFile = "reject.xml";
RequisitionDocument reqDoc = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition();
Integer reqId = reqDoc.getPurapDocumentIdentifier();
PurchaseOrderDocument poDocument = createPODoc(reqId);
poDocument.setVendorShippingPaymentTermsCode("AL");
poDocument.setVendorPaymentTermsCode("00N30");
poDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(poDocument, documentService);
String poNumber = String.valueOf(poDocument.getPurapDocumentIdentifier());
String vendorDUNS = "133251074";
String xmlChunk = CuElectronicInvoiceHelperServiceFixture.getCXMLForRejectDocCreation(vendorDUNS, poNumber);
writeXMLFile(xmlChunk, rejectFile);
ElectronicInvoiceLoad load = cuElectronicInvoiceHelperService.loadElectronicInvoices();
assertTrue(load.containsRejects());
ElectronicInvoiceRejectDocument rejectDoc = (ElectronicInvoiceRejectDocument) load.getRejectDocuments().get(0);
assertNotNull(rejectDoc);
assertEquals(rejectDoc.getInvoiceFileName(), rejectFile);
assertEquals(1, rejectDoc.getInvoiceRejectReasons().size());
File rejectedFileInRejectDir = new File(electronicInvoiceInputFileType.getDirectoryPath() + File.separator + "reject" + File.separator + rejectFile);
assertTrue(rejectedFileInRejectDir.exists());
}
use of org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoad in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method loadElectronicInvoices.
public ElectronicInvoiceLoad loadElectronicInvoices() {
LOG.debug("loadElectronicInvoices() started");
// add a step to check for directory paths
prepareDirectories(getRequiredDirectoryNames());
String rejectDirName = getRejectDirName();
String acceptDirName = getAcceptDirName();
String extractFailureDirName = getExtractFailureDirName();
emailTextErrorList = new StringBuffer();
int failedCnt = 0;
LOG.info("Invoice Base Directory - " + electronicInvoiceInputFileType.getDirectoryPath());
LOG.info("Invoice Accept Directory - " + acceptDirName);
LOG.info("Invoice Reject Directory - " + rejectDirName);
if (StringUtils.isBlank(rejectDirName)) {
throw new RuntimeException("Reject directory name should not be empty");
}
if (StringUtils.isBlank(acceptDirName)) {
throw new RuntimeException("Accept directory name should not be empty");
}
if (StringUtils.isBlank(extractFailureDirName)) {
throw new RuntimeException("ExtractFailure directory name should not be empty");
}
File[] filesToBeProcessed = getFilesToBeProcessed();
ElectronicInvoiceLoad eInvoiceLoad = new ElectronicInvoiceLoad();
if (filesToBeProcessed == null || filesToBeProcessed.length == 0) {
StringBuffer mailText = new StringBuffer();
mailText.append("\n\n");
mailText.append(PurapConstants.ElectronicInvoice.NO_FILES_PROCESSED_EMAIL_MESSAGE);
mailText.append("\n\n");
sendSummary(mailText);
return eInvoiceLoad;
}
try {
FileUtils.forceMkdir(new File(acceptDirName));
FileUtils.forceMkdir(new File(rejectDirName));
FileUtils.forceMkdir(new File(extractFailureDirName));
} catch (IOException e) {
throw new RuntimeException(e);
}
LOG.info(filesToBeProcessed.length + " file(s) available for processing");
StringBuilder emailMsg = new StringBuilder();
for (File xmlFile : filesToBeProcessed) {
LOG.info("Processing " + xmlFile.getName() + "....");
byte[] modifiedXML = addNamespaceDefinition(eInvoiceLoad, xmlFile);
try {
processElectronicInvoice(eInvoiceLoad, xmlFile, modifiedXML);
} catch (Exception e) {
String msg = xmlFile.getName() + "\n";
LOG.error(msg);
// since getMessage() is empty we'll compose the stack trace and nicely format it.
StackTraceElement[] elements = e.getStackTrace();
StringBuffer trace = new StringBuffer();
trace.append(e.getClass().getName());
if (e.getMessage() != null) {
trace.append(": ");
trace.append(e.getMessage());
}
trace.append("\n");
for (int j = 0; j < elements.length; ++j) {
StackTraceElement element = elements[j];
trace.append(" at ");
trace.append(describeStackTraceElement(element));
trace.append("\n");
}
LOG.error(trace);
// KFSUPGRADE-480, KFSUPGRADE-484 : Cu channged email message, the failCnt and emailMsg are not referenced
// in CU's email. So, this is not critical. But may be good to see these logs.
emailMsg.append(msg);
msg += "\n--------------------------------------------------------------------------------------\n" + trace;
logProcessElectronicInvoiceError(msg);
failedCnt++;
// one of the scenario is that save EIRT failed vecause of validation failed. So, no EIRT will
// be created.
boolean moveFiles = BooleanUtils.toBoolean(parameterService.getParameterValueAsString(ElectronicInvoiceStep.class, PurapParameterConstants.ElectronicInvoiceParameters.FILE_MOVE_AFTER_LOAD_IND));
if (moveFiles) {
if (LOG.isInfoEnabled()) {
LOG.info(xmlFile.getName() + " has caused by saving EIRT failure.");
}
boolean success = this.moveFile(xmlFile, getExtractFailureDirName());
if (!success) {
String errorMessage = "File with name '" + xmlFile.getName() + "' could not be moved";
throw new PurError(errorMessage);
}
updateSummaryCounts(EXTRACT_FAILURES);
}
/**
* Clear the error map, so that subsequent EIRT routing isn't prevented since rice
* is throwing a ValidationException if the error map is not empty before routing the doc.
*/
GlobalVariables.getMessageMap().clearErrorMessages();
// Do not execute rest of code below
// continue;
}
}
StringBuffer finalText = buildLoadSummary(eInvoiceLoad);
sendSummary(finalText);
// Need to clear the counts after each run, so the totals don't show cumulative counts with each subsequent run.
clearLoadCounts();
LOG.info("Processing completed");
return eInvoiceLoad;
}
Aggregations