use of org.kuali.kfs.krad.exception.ValidationException 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;
}
use of org.kuali.kfs.krad.exception.ValidationException in project cu-kfs by CU-CommunityApps.
the class CuPurchaseOrderServiceImplTest method testPerformPurchaseOrderFirstTransmitViaPrinting.
public void testPerformPurchaseOrderFirstTransmitViaPrinting() throws Exception {
PurchaseOrderDocument po = PurchaseOrderFixture.PO_NON_B2B_OPEN.createPurchaseOrderdDocument(documentService);
try {
purchaseOrderService.performPurchaseOrderFirstTransmitViaPrinting(po);
assertTrue(po.getPurchaseOrderFirstTransmissionTimestamp() != null);
assertTrue(po.getPurchaseOrderLastTransmitTimestamp() != null);
} catch (ValidationException e) {
LOG.warn("Caught ValidationException while trying to retransmit PO with doc id " + po.getDocumentNumber());
}
}
Aggregations