From cbf827803d65409df6c9b968b1225cc425276dc1 Mon Sep 17 00:00:00 2001 From: sheiksalahudeen Date: Tue, 27 Sep 2016 11:50:01 -0400 Subject: [PATCH 1/2] Handled Exception while doing batch export. --- .../ole/oleng/dao/export/ExportCallable.java | 3 +- .../kuali/ole/oleng/dao/export/ExportDao.java | 5 +-- .../ole/oleng/handler/BatchExportHandler.java | 41 +++++++++++-------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportCallable.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportCallable.java index 887f54f953..1790e483d3 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportCallable.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportCallable.java @@ -111,7 +111,8 @@ public Object doInTransaction(TransactionStatus status) { } }); } catch (Exception ex) { - throw ex; + ex.printStackTrace(); + batchExportHandler.addBatchExportFailureResponseToExchange(ex, null, batchProcessTxObject.getExchangeObjectForBatchExport()); } finally { this.transactionManager = null; diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportDao.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportDao.java index 0a3f0e89e3..c6e0625c0a 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportDao.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/export/ExportDao.java @@ -149,10 +149,9 @@ private void prepareBatchExportResponse(List futures, BatchExportHandler batchProcessTxObject.getBatchJobDetails().setTotalRecordsProcessed(String.valueOf(originalResponse.getNoOfSuccessRecords() + originalResponse.getNoOfFailureRecords())); batchExportHandler.updateBatchJob(batchProcessTxObject.getBatchJobDetails()); } - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { + } catch (Exception e) { e.printStackTrace(); + batchExportHandler.addBatchExportFailureResponseToExchange(e, null, batchProcessTxObject.getExchangeObjectForBatchExport()); } } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/BatchExportHandler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/BatchExportHandler.java index 82836c421c..edf987baf0 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/BatchExportHandler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/BatchExportHandler.java @@ -20,25 +20,30 @@ public class BatchExportHandler extends BatchExportUtil { private ExportDao exportDao = (ExportDao) SpringContext.getBean("exportDao"); public void processExport(BatchProcessTxObject batchProcessTxObject, OleNGBatchExportResponse oleNGBatchExportResponse) { - String exportScope = batchProcessTxObject.getBatchProcessProfile().getExportScope(); - if (StringUtils.isNotBlank(exportScope)) { - switch (exportScope) { - case OleNGConstants.FULL_EXPORT: - processFullExport(batchProcessTxObject, oleNGBatchExportResponse); - break; - case OleNGConstants.FULL_EXCEPT_STAFF_ONLY: - processFullExceptStaffOnly(batchProcessTxObject, oleNGBatchExportResponse); - break; - case OleNGConstants.INCREMENTAL: - processIncremental(batchProcessTxObject, oleNGBatchExportResponse); - break; - case OleNGConstants.INCREMENTAL_EXCEPT_STAFF_ONLY: - processIncrementalExceptStaffOnly(batchProcessTxObject, oleNGBatchExportResponse); - break; - case OleNGConstants.FILTER: - processFilterExport(batchProcessTxObject, oleNGBatchExportResponse); - break; + try { + String exportScope = batchProcessTxObject.getBatchProcessProfile().getExportScope(); + if (StringUtils.isNotBlank(exportScope)) { + switch (exportScope) { + case OleNGConstants.FULL_EXPORT: + processFullExport(batchProcessTxObject, oleNGBatchExportResponse); + break; + case OleNGConstants.FULL_EXCEPT_STAFF_ONLY: + processFullExceptStaffOnly(batchProcessTxObject, oleNGBatchExportResponse); + break; + case OleNGConstants.INCREMENTAL: + processIncremental(batchProcessTxObject, oleNGBatchExportResponse); + break; + case OleNGConstants.INCREMENTAL_EXCEPT_STAFF_ONLY: + processIncrementalExceptStaffOnly(batchProcessTxObject, oleNGBatchExportResponse); + break; + case OleNGConstants.FILTER: + processFilterExport(batchProcessTxObject, oleNGBatchExportResponse); + break; + } } + } catch (Exception e) { + e.printStackTrace(); + addBatchExportFailureResponseToExchange(e, null, batchProcessTxObject.getExchangeObjectForBatchExport()); } } From c5f1668a74ea0154061361bf4aafd5322e7cd145 Mon Sep 17 00:00:00 2001 From: sheiksalahudeen Date: Tue, 27 Sep 2016 12:27:05 -0400 Subject: [PATCH 2/2] Handled Exception while doing batch export. --- .../processors/BatchExportFailureReportProcessor.java | 4 ++-- .../main/java/org/kuali/ole/spring/batch/BatchUtil.java | 3 --- .../spring/batch/processor/BatchExportFileProcessor.java | 7 +++++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BatchExportFailureReportProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BatchExportFailureReportProcessor.java index fdcbf41857..f1470d2eae 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BatchExportFailureReportProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BatchExportFailureReportProcessor.java @@ -14,8 +14,8 @@ public class BatchExportFailureReportProcessor extends OleNGReportProcessor { @Override public void process(Object object, String directoryToWrite) throws Exception { - OleNGBatchExportResponse oleNGBatchDeleteResponse = (OleNGBatchExportResponse) object; - List exportFailureResponses = oleNGBatchDeleteResponse.getExportFailureResponses(); + OleNGBatchExportResponse oleNGBatchExportResponse = (OleNGBatchExportResponse) object; + List exportFailureResponses = oleNGBatchExportResponse.getExportFailureResponses(); if (CollectionUtils.isNotEmpty(exportFailureResponses)) { String exportFailureMessages = new ObjectMapper().defaultPrettyPrintingWriter().writeValueAsString(exportFailureResponses); logMessage(directoryToWrite, "BatchExport-FailureMessages", "txt", exportFailureMessages, false); diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/BatchUtil.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/BatchUtil.java index ec6a026306..ec8fd4fda4 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/BatchUtil.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/BatchUtil.java @@ -393,9 +393,6 @@ public String getSourceMatchPoint(BatchProfileMatchPoint batchProfileMatchPoint) } - - - public void addBatchExportFailureResponseToExchange(Exception exception, String bibId, Exchange exchange) { String message = exception.toString(); List exportFailureResponses = (List) exchange.get(OleNGConstants.FAILURE_RESPONSE); diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchExportFileProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchExportFileProcessor.java index 06934fdeeb..51d1f5423f 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchExportFileProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchExportFileProcessor.java @@ -1,10 +1,12 @@ package org.kuali.ole.spring.batch.processor; +import org.apache.commons.collections.CollectionUtils; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.kuali.ole.constants.OleNGConstants; import org.kuali.ole.docstore.common.pojo.RecordDetails; import org.kuali.ole.docstore.common.response.BatchProcessFailureResponse; +import org.kuali.ole.docstore.common.response.ExportFailureResponse; import org.kuali.ole.docstore.common.response.OleNGBatchExportResponse; import org.kuali.ole.docstore.common.response.OleNgBatchResponse; import org.kuali.ole.oleng.batch.process.model.BatchJobDetails; @@ -18,6 +20,7 @@ import java.io.File; import java.sql.Timestamp; +import java.util.List; import java.util.Map; /** @@ -40,6 +43,10 @@ public JSONObject processBatch(File inputFileDirectoryPath, String fileType, Str batchProcessProfile = fetchBatchProcessProfile(profileId); batchProcessTxObject = buildBatchProcessTxObject(inputFileDirectoryPath, fileType, batchProcessProfile, reportDirectoryName, batchJobDetails); batchExportHandler.processExport(batchProcessTxObject, oleNGBatchExportResponse); + List exportFailureResponses = (List) batchProcessTxObject.getExchangeObjectForBatchExport().get(OleNGConstants.FAILURE_RESPONSE); + if(CollectionUtils.isNotEmpty(exportFailureResponses)) { + oleNGBatchExportResponse.setExportFailureResponses(exportFailureResponses); + } generateBatchReport(inputFileDirectoryPath, batchJobDetails, oleNGBatchExportResponse); jsonResponse.put(OleNGConstants.STATUS, true); } catch (Exception e) {