diff --git a/ole-app/ole-db/ole-impex/ole-impex-ls/src/main/resources/schema.xml b/ole-app/ole-db/ole-impex/ole-impex-ls/src/main/resources/schema.xml index 2544ab251d..dc03975ae2 100644 --- a/ole-app/ole-db/ole-impex/ole-impex-ls/src/main/resources/schema.xml +++ b/ole-app/ole-db/ole-impex/ole-impex-ls/src/main/resources/schema.xml @@ -3595,9 +3595,6 @@ - - - diff --git a/ole-app/ole-db/ole-liquibase/ole-liquibase-upgrade/src/main/resources/org/kuali/ole/2.1/db.changelog-20151123.xml b/ole-app/ole-db/ole-liquibase/ole-liquibase-upgrade/src/main/resources/org/kuali/ole/2.1/db.changelog-20151123.xml index 328d65cce2..5238f14665 100644 --- a/ole-app/ole-db/ole-liquibase/ole-liquibase-upgrade/src/main/resources/org/kuali/ole/2.1/db.changelog-20151123.xml +++ b/ole-app/ole-db/ole-liquibase/ole-liquibase-upgrade/src/main/resources/org/kuali/ole/2.1/db.changelog-20151123.xml @@ -826,5 +826,8 @@ ALTER TABLE OLE_PUR_POBA_T MODIFY UPLD_FILE_NM varchar2(120) + + + \ No newline at end of file diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/process/model/BatchProcessTxObject.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/process/model/BatchProcessTxObject.java index c0f912be4c..cd21be0ad7 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/process/model/BatchProcessTxObject.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/process/model/BatchProcessTxObject.java @@ -26,6 +26,7 @@ public class BatchProcessTxObject { private int numberOfFailurRecords; private boolean exceptionCaught; private List batchProcessFailureResponses; + private boolean stopped; public String getFileExtension() { return fileExtension; @@ -142,4 +143,12 @@ public List getBatchProcessFailureResponses() { public void setBatchProcessFailureResponses(List batchProcessFailureResponses) { this.batchProcessFailureResponses = batchProcessFailureResponses; } + + public boolean isStopped() { + return stopped; + } + + public void setStopped(boolean stopped) { + this.stopped = stopped; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BibImportFailureReportProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BibImportFailureReportProcessor.java index 2a07795bf8..3e6dea5f5b 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BibImportFailureReportProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/BibImportFailureReportProcessor.java @@ -17,12 +17,13 @@ */ public class BibImportFailureReportProcessor extends OleNGReportProcessor { + private MarcRecordUtil marcRecordUtil; + @Override public void process(Object object, String directoryToWrite) throws Exception { OleNGBibImportResponse oleNGBibImportResponse = (OleNGBibImportResponse) object; List failureResponses = oleNGBibImportResponse.getFailureResponses(); List marcRecords = new ArrayList<>(); - MarcRecordUtil marcRecordUtil = new MarcRecordUtil(); if(CollectionUtils.isNotEmpty(failureResponses)) { Map recordsMap = oleNGBibImportResponse.getRecordsMap(); if(null != recordsMap && recordsMap.size() > 0) { @@ -40,11 +41,22 @@ public void process(Object object, String directoryToWrite) throws Exception { } } if(CollectionUtils.isNotEmpty(marcRecords)) { - String failedMarcContent = marcRecordUtil.convertMarcRecordListToRawMarcContent(marcRecords); - logMessage(directoryToWrite, "Bib-FailedMarcRecords","mrc", failedMarcContent, true); + String failedMarcContent = getMarcRecordUtil().convertMarcRecordListToRawMarcContent(marcRecords); + writeMarcContent(directoryToWrite, failedMarcContent); } String bibFailureMessage = new ObjectMapper().defaultPrettyPrintingWriter().writeValueAsString(failureResponses); logMessage(directoryToWrite, "Bib-FailureMessages","txt", bibFailureMessage, false); } } + + public void writeMarcContent(String directoryToWrite, String failedMarcContent) throws Exception { + logMessage(directoryToWrite, "Bib-FailedMarcRecords","mrc", failedMarcContent, true); + } + + public MarcRecordUtil getMarcRecordUtil() { + if(null == marcRecordUtil) { + marcRecordUtil = new MarcRecordUtil(); + } + return marcRecordUtil; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/InvoiceImportFailureReportProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/InvoiceImportFailureReportProcessor.java index 02c6e24d9e..8703385464 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/InvoiceImportFailureReportProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/InvoiceImportFailureReportProcessor.java @@ -1,24 +1,68 @@ package org.kuali.ole.oleng.batch.reports.processors; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; import org.codehaus.jackson.map.ObjectMapper; +import org.kuali.ole.constants.OleNGConstants; +import org.kuali.ole.docstore.common.pojo.RecordDetails; import org.kuali.ole.docstore.common.response.InvoiceFailureResponse; import org.kuali.ole.docstore.common.response.OleNGInvoiceImportResponse; +import org.kuali.ole.docstore.common.response.OrderFailureResponse; +import org.kuali.ole.utility.MarcRecordUtil; +import org.marc4j.marc.Record; +import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * Created by angelind on 3/16/16. */ public class InvoiceImportFailureReportProcessor extends OleNGReportProcessor { + private MarcRecordUtil marcRecordUtil; + @Override public void process(Object object, String directoryToWrite) throws Exception { OleNGInvoiceImportResponse oleNGInvoiceImportResponse = (OleNGInvoiceImportResponse) object; List invoiceFailureResponses = oleNGInvoiceImportResponse.getInvoiceFailureResponses(); + List marcRecords = new ArrayList<>(); if(CollectionUtils.isNotEmpty(invoiceFailureResponses)) { + String fileExtension = oleNGInvoiceImportResponse.getFileExtension(); + if (StringUtils.isNotBlank(fileExtension) && fileExtension.equalsIgnoreCase(OleNGConstants.MARC)) { + Map recordsMap = oleNGInvoiceImportResponse.getRecordsMap(); + if(null != recordsMap && recordsMap.size() > 0) { + for(InvoiceFailureResponse failureResponse : invoiceFailureResponses) { + Integer index = failureResponse.getIndex(); + if(null != index) { + RecordDetails recordDetails = recordsMap.get(index); + if (null != recordDetails) { + Record record = recordDetails.getRecord(); + if (null != record) { + marcRecords.add(record); + } + } + } + } + } + if(CollectionUtils.isNotEmpty(marcRecords)) { + String failedMarcContent = getMarcRecordUtil().convertMarcRecordListToRawMarcContent(marcRecords); + writeMarcContent(directoryToWrite, failedMarcContent); + } + } String invoiceFailureMessage = new ObjectMapper().defaultPrettyPrintingWriter().writeValueAsString(invoiceFailureResponses); logMessage(directoryToWrite, "Invoice-FailureMessages", "txt", invoiceFailureMessage, false); } } + + public void writeMarcContent(String directoryToWrite, String failedMarcContent) throws Exception { + logMessage(directoryToWrite, "Invoice-FailedMarcRecords", "mrc", failedMarcContent, true); + } + + public MarcRecordUtil getMarcRecordUtil() { + if(null == marcRecordUtil) { + marcRecordUtil = new MarcRecordUtil(); + } + return marcRecordUtil; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/OrderImportFailureReportProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/OrderImportFailureReportProcessor.java index 65ea93e193..d25ce4881d 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/OrderImportFailureReportProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/batch/reports/processors/OrderImportFailureReportProcessor.java @@ -17,12 +17,13 @@ */ public class OrderImportFailureReportProcessor extends OleNGReportProcessor { + private MarcRecordUtil marcRecordUtil; + @Override public void process(Object object, String directoryToWrite) throws Exception { OleNGOrderImportResponse oleNGOrderImportResponse = (OleNGOrderImportResponse) object; List orderFailureResponses = oleNGOrderImportResponse.getOrderFailureResponses(); List marcRecords = new ArrayList<>(); - MarcRecordUtil marcRecordUtil = new MarcRecordUtil(); if(CollectionUtils.isNotEmpty(orderFailureResponses)) { Map recordsMap = oleNGOrderImportResponse.getRecordsMap(); if(null != recordsMap && recordsMap.size() > 0) { @@ -40,11 +41,22 @@ public void process(Object object, String directoryToWrite) throws Exception { } } if(CollectionUtils.isNotEmpty(marcRecords)) { - String failedMarcContent = marcRecordUtil.convertMarcRecordListToRawMarcContent(marcRecords); - logMessage(directoryToWrite, "Order-FailedMarcRecords", "mrc", failedMarcContent, true); + String failedMarcContent = getMarcRecordUtil().convertMarcRecordListToRawMarcContent(marcRecords); + writeMarcContent(directoryToWrite, failedMarcContent); } String orderFailureMessage = new ObjectMapper().defaultPrettyPrintingWriter().writeValueAsString(orderFailureResponses); logMessage(directoryToWrite, "Order-FailureMessages", "txt", orderFailureMessage, false); } } + + public void writeMarcContent(String directoryToWrite, String failedMarcContent) throws Exception { + logMessage(directoryToWrite, "Order-FailedMarcRecords", "mrc", failedMarcContent, true); + } + + public MarcRecordUtil getMarcRecordUtil() { + if(null == marcRecordUtil) { + marcRecordUtil = new MarcRecordUtil(); + } + return marcRecordUtil; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/SelectDAO.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/SelectDAO.java index baa9c4e056..fbf8a6a2e0 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/SelectDAO.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/SelectDAO.java @@ -74,5 +74,6 @@ public interface SelectDAO { public ItemStatusRecord fetchItemStatusByCode(String itemStatusCode); public VendorCustomerNumber getVendorCustomerNumberByNumber(String vendorCustomerNumber); public OLEDonor getOLEDonorByCode(String donorCode); + public OleCurrencyType getCurrencyType(String currencyType); } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/impl/SelectDAOImpl.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/impl/SelectDAOImpl.java index 0353cf2fca..f612d6ec50 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/impl/SelectDAOImpl.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/dao/impl/SelectDAOImpl.java @@ -2,6 +2,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.math.NumberUtils; +import org.apache.commons.lang3.StringUtils; import org.kuali.ole.OLEConstants; import org.kuali.ole.coa.businessobject.Account; import org.kuali.ole.coa.businessobject.*; @@ -209,7 +210,7 @@ public Organization getOrganizationByChartAndOrgCode(String chartCode, String or @Override public VendorDetail getVendorDetailByVendorNumber(String vendorNumber){ String[] vendorDetail = vendorNumber.split("-"); - if(vendorDetail.length == 2) { + if(vendorDetail.length == 2 && StringUtils.isNotBlank(vendorDetail[0]) && org.apache.commons.lang.StringUtils.isNotBlank(vendorDetail[1])) { String vendorHeaderGeneratedIdentifier = vendorDetail[0]; String vendorDetailAssignedIdentifier = vendorDetail[1]; if (NumberUtils.isDigits(vendorHeaderGeneratedIdentifier) && NumberUtils.isDigits(vendorDetailAssignedIdentifier)) { @@ -406,7 +407,7 @@ public Room getRoom(String buildingCode, String campusCode, String buildingRoomN deliveryMap.put(OLEConstants.OLEBatchProcess.BUILDING_CODE, buildingCode); deliveryMap.put(OLEConstants.OLEBatchProcess.CAMPUS_CODE, campusCode); deliveryMap.put(OLEConstants.BUILDING_ROOM_NUMBER, buildingRoomNumber); - List roomList = (List) KRADServiceLocator.getBusinessObjectService().findMatching(Room.class, deliveryMap); + List roomList = (List) getBusinessObjectService().findMatching(Room.class, deliveryMap); if (CollectionUtils.isNotEmpty(roomList)){ return roomList.get(0); } @@ -485,13 +486,24 @@ public VendorCustomerNumber getVendorCustomerNumberByNumber(String vendorCustome public OLEDonor getOLEDonorByCode(String donorCode) { Map donorCodeMap = new HashMap<>(); donorCodeMap.put(OLEConstants.DONOR_CODE, donorCode); - List donorCodeList = (List) KRADServiceLocator.getBusinessObjectService().findMatching(OLEDonor.class, donorCodeMap); + List donorCodeList = (List) getBusinessObjectService().findMatching(OLEDonor.class, donorCodeMap); if (CollectionUtils.isNotEmpty(donorCodeList)){ return donorCodeList.get(0); } return null; } + @Override + public OleCurrencyType getCurrencyType(String currencyType) { + Map donorCodeMap = new HashMap<>(); + donorCodeMap.put(OLEConstants.CURRENCY_TYPE, currencyType); + List oleCurrencyTypes = (List) getBusinessObjectService().findMatching(OleCurrencyType.class, donorCodeMap); + if (CollectionUtils.isNotEmpty(oleCurrencyTypes)){ + return oleCurrencyTypes.get(0); + } + return null; + } + public KeyValuesService getKeyValuesService() { if(null == keyValuesService){ keyValuesService = SpringContext.getBean(KeyValuesService.class); diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateNeitherReqNorPOServiceHandler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateNeitherReqNorPOServiceHandler.java index 584b799d8b..920a83d0d6 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateNeitherReqNorPOServiceHandler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateNeitherReqNorPOServiceHandler.java @@ -1,6 +1,8 @@ package org.kuali.ole.oleng.handler; import org.kuali.ole.Exchange; +import org.kuali.ole.oleng.service.OleNGMemorizeService; +import org.kuali.ole.oleng.service.impl.OleNGMemorizeServiceImpl; import org.kuali.ole.pojo.OleOrderRecord; import java.util.List; @@ -10,7 +12,20 @@ */ public class CreateNeitherReqNorPOServiceHandler implements CreateReqAndPOBaseServiceHandler { + private OleNGMemorizeService oleNGMemorizeService; + public Integer processOrder(List oleOrderRecords, Exchange exchange) throws Exception { return null; } + + public OleNGMemorizeService getOleNGMemorizeService() { + if(null == oleNGMemorizeService) { + oleNGMemorizeService = new OleNGMemorizeServiceImpl(); + } + return oleNGMemorizeService; + } + + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService) { + this.oleNGMemorizeService = oleNGMemorizeService; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOBaseServiceHandler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOBaseServiceHandler.java index dbbb1de611..0bced30850 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOBaseServiceHandler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOBaseServiceHandler.java @@ -1,6 +1,7 @@ package org.kuali.ole.oleng.handler; import org.kuali.ole.Exchange; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.pojo.OleOrderRecord; import java.util.List; @@ -10,4 +11,6 @@ */ public interface CreateReqAndPOBaseServiceHandler { public Integer processOrder(List oleOrderRecords, Exchange exchange) throws Exception; + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService); + public OleNGMemorizeService getOleNGMemorizeService(); } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOServiceHandler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOServiceHandler.java index 3099dbc7c9..aa28b47c60 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOServiceHandler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqAndPOServiceHandler.java @@ -21,7 +21,9 @@ import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemStatusRecord; import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemTypeRecord; import org.kuali.ole.oleng.batch.profile.model.BatchProcessProfile; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.oleng.service.OleNGRequisitionService; +import org.kuali.ole.oleng.service.impl.OleNGMemorizeServiceImpl; import org.kuali.ole.pojo.OleOrderRecord; import org.kuali.ole.select.businessobject.OleRequisitionItem; import org.kuali.ole.select.document.OleRequisitionDocument; @@ -47,25 +49,29 @@ public class CreateReqAndPOServiceHandler extends BatchUtil implements CreateReqAndPOBaseServiceHandler { private OleNGRequisitionService oleNGRequisitionService; private DataCarrierService dataCarrierService; + private OleNGMemorizeService oleNGMemorizeService; public Integer processOrder(List oleOrderRecords, Exchange exchange) throws Exception { GlobalVariables.setUserSession(new UserSession("ole-quickstart")); - OleRequisitionDocument requisitionDocument = getOleNGRequisitionService().createPurchaseOrderDocument(oleOrderRecords,exchange); + OleNGRequisitionService oleNGRequisitionService = getOleNGRequisitionService(); + oleNGRequisitionService.setOleNGMemorizeService(getOleNGMemorizeService()); + OleRequisitionDocument requisitionDocument = oleNGRequisitionService.createPurchaseOrderDocument(oleOrderRecords, exchange); List items = requisitionDocument.getItems(); - if(CollectionUtils.isNotEmpty(items)) { - for (Iterator iterator = items.iterator(); iterator.hasNext(); ) { - OleRequisitionItem oleRequisitionItem = (OleRequisitionItem) iterator.next(); - String itemTypeCode = oleRequisitionItem.getItemTypeCode(); - try { - if(StringUtils.isNotBlank(itemTypeCode) && itemTypeCode.equalsIgnoreCase(OLEConstants.ITEM)) { - String bibUUID = oleRequisitionItem.getBibUUID(); - BibRecord bibRecord = getBusinessObjectService().findBySinglePrimaryKey(BibRecord.class, DocumentUniqueIDPrefix.getDocumentId(bibUUID)); - List records = new MarcRecordUtil().convertMarcXmlContentToMarcRecord(bibRecord.getContent()); - String bibProfileName = oleOrderRecords.get(0).getBibImportProfileName(); - BatchBibFileProcessor batchBibFileProcessor = new BatchBibFileProcessor(); - if(StringUtils.isNotBlank(bibProfileName)) { - BatchProcessProfile processProfile = fetchBatchProcessProfile(bibProfileName); - if(oleRequisitionItem.getLinkToOrderOption().equalsIgnoreCase(org.kuali.ole.OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_PRINT)) { + + String bibProfileName = oleOrderRecords.get(0).getBibImportProfileName(); + if (StringUtils.isNotBlank(bibProfileName)) { + BatchProcessProfile processProfile = getOleNGMemorizeService().fetchBatchProcessProfile(bibProfileName,OleNGConstants.BIB_IMPORT); + if (CollectionUtils.isNotEmpty(items)) { + for (Iterator iterator = items.iterator(); iterator.hasNext(); ) { + OleRequisitionItem oleRequisitionItem = (OleRequisitionItem) iterator.next(); + String itemTypeCode = oleRequisitionItem.getItemTypeCode(); + try { + if (StringUtils.isNotBlank(itemTypeCode) && itemTypeCode.equalsIgnoreCase(OLEConstants.ITEM)) { + String bibUUID = oleRequisitionItem.getBibUUID(); + BibRecord bibRecord = getBusinessObjectService().findBySinglePrimaryKey(BibRecord.class, DocumentUniqueIDPrefix.getDocumentId(bibUUID)); + List records = new MarcRecordUtil().convertMarcXmlContentToMarcRecord(bibRecord.getContent()); + BatchBibFileProcessor batchBibFileProcessor = new BatchBibFileProcessor(); + if (oleRequisitionItem.getLinkToOrderOption().equalsIgnoreCase(org.kuali.ole.OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_PRINT)) { List preTransformForHoldings = batchBibFileProcessor.prepareDataMappings(records, processProfile, OleNGConstants.HOLDINGS, OleNGConstants.PRE_MARC_TRANSFORMATION, false); List postTransformForHoldings = batchBibFileProcessor.prepareDataMappings(records, processProfile, @@ -83,9 +89,9 @@ public Integer processOrder(List oleOrderRecords, Exchange excha Holdings dummyHoldingsFromDataMapping = createDummyHoldingsFromDataMapping(dataMappingForHoldings); Item dummyItemFromDataMapping = createDummyItemFromDataMapping(dataMappingForItem); - getDataCarrierService().addData("reqItemId:" + oleRequisitionItem.getItemIdentifier()+":holdings",dummyHoldingsFromDataMapping); - getDataCarrierService().addData("reqItemId:" + oleRequisitionItem.getItemIdentifier()+":item",dummyItemFromDataMapping); - } else if(oleRequisitionItem.getLinkToOrderOption().equalsIgnoreCase(org.kuali.ole.OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_ELECTRONIC)) { + getDataCarrierService().addData("reqItemId:" + oleRequisitionItem.getItemIdentifier() + ":holdings", dummyHoldingsFromDataMapping); + getDataCarrierService().addData("reqItemId:" + oleRequisitionItem.getItemIdentifier() + ":item", dummyItemFromDataMapping); + } else if (oleRequisitionItem.getLinkToOrderOption().equalsIgnoreCase(org.kuali.ole.OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_ELECTRONIC)) { List preTransformForHoldings = batchBibFileProcessor.prepareDataMappings(records, processProfile, OleNGConstants.EHOLDINGS, OleNGConstants.PRE_MARC_TRANSFORMATION, false); List postTransformForHoldings = batchBibFileProcessor.prepareDataMappings(records, processProfile, @@ -94,16 +100,16 @@ public Integer processOrder(List oleOrderRecords, Exchange excha List dataMappingForEHoldings = batchBibFileProcessor.buildOneObjectForList(preTransformForHoldings, postTransformForHoldings); Holdings dummyHoldingsFromDataMapping = createDummyEHoldingsFromDataMapping(dataMappingForEHoldings); - getDataCarrierService().addData("reqItemId:" + oleRequisitionItem.getItemIdentifier()+":holdings",dummyHoldingsFromDataMapping); + getDataCarrierService().addData("reqItemId:" + oleRequisitionItem.getItemIdentifier() + ":holdings", dummyHoldingsFromDataMapping); } } + } catch (JSONException e) { + e.printStackTrace(); + addOrderFaiureResponseToExchange(e, null, exchange); } - } catch (JSONException e) { - e.printStackTrace(); - addOrderFaiureResponseToExchange(e, null, exchange); - } + } } } return requisitionDocument.getPurapDocumentIdentifier(); @@ -120,7 +126,7 @@ public void setOleNGRequisitionService(OleNGRequisitionService oleNGRequisitionS private Holdings createDummyHoldingsFromDataMapping(List dataMappingForHoldings) { JSONObject request = new JSONObject(); try { - if(CollectionUtils.isNotEmpty(dataMappingForHoldings)) { + if (CollectionUtils.isNotEmpty(dataMappingForHoldings)) { request.put(OleNGConstants.DATAMAPPING, dataMappingForHoldings.get(0)); } request.put(OleNGConstants.HOLDINGS_TYPE, PHoldings.PRINT); @@ -139,7 +145,7 @@ private Holdings createDummyHoldingsFromDataMapping(List dataMapping e.printStackTrace(); } - if(null == holdings) { + if (null == holdings) { holdings = new PHoldings(); } OleHoldings oleHoldings = holdings.getContentObject(); @@ -151,7 +157,7 @@ private Holdings createDummyHoldingsFromDataMapping(List dataMapping private Item createDummyItemFromDataMapping(List dataMappingForItem) { JSONObject request = new JSONObject(); try { - if(CollectionUtils.isNotEmpty(dataMappingForItem)) { + if (CollectionUtils.isNotEmpty(dataMappingForItem)) { request.put(OleNGConstants.DATAMAPPING, dataMappingForItem.get(0)); } } catch (JSONException e) { @@ -170,7 +176,7 @@ private Item createDummyItemFromDataMapping(List dataMappingForItem) e.printStackTrace(); } - if(null == item) { + if (null == item) { item = new Item(); } return item; @@ -179,7 +185,7 @@ private Item createDummyItemFromDataMapping(List dataMappingForItem) private Holdings createDummyEHoldingsFromDataMapping(List dataMappingForHoldings) { JSONObject request = new JSONObject(); try { - if(CollectionUtils.isNotEmpty(dataMappingForHoldings)) { + if (CollectionUtils.isNotEmpty(dataMappingForHoldings)) { request.put(OleNGConstants.DATAMAPPING, dataMappingForHoldings.get(0)); } request.put(OleNGConstants.HOLDINGS_TYPE, EHoldings.ELECTRONIC); @@ -198,7 +204,7 @@ private Holdings createDummyEHoldingsFromDataMapping(List dataMappin e.printStackTrace(); } - if(null == eHoldings) { + if (null == eHoldings) { eHoldings = new EHoldings(); } OleHoldings oleHoldings = eHoldings.getContentObject(); @@ -214,29 +220,7 @@ private List getListOfValue(JSONObject itemMappings, String type) { return getListFromJSONArray(jsonArrayFromJsonObject.toString()); } - - - public BatchProcessProfile fetchBatchProcessProfile(String profileName) { - BatchProcessProfile batchProcessProfile = null; - - Map parameterMap = new HashMap(); - parameterMap.put("batchProcessProfileName",profileName); - parameterMap.put("batchProcessType","Bib Import"); - List matching = (List) KRADServiceLocator.getBusinessObjectService().findMatching(BatchProcessProfile.class, parameterMap); - if(CollectionUtils.isNotEmpty(matching)){ - try { - batchProcessProfile = matching.get(0); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setVisibilityChecker(objectMapper.getVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY)); - batchProcessProfile = objectMapper.readValue(IOUtils.toString(batchProcessProfile.getContent()), BatchProcessProfile.class); - } catch (IOException e) { - e.printStackTrace(); - } - } - return batchProcessProfile; - } - - public List getListFromJSONArray(String jsonArrayString){ + public List getListFromJSONArray(String jsonArrayString) { List ops = new ArrayList(); try { ops = new ObjectMapper().readValue(jsonArrayString, new TypeReference>() { @@ -252,7 +236,7 @@ public List getListFromJSONArray(String jsonArrayString){ public JSONArray getJSONArrayFromJsonObject(JSONObject jsonObject, String key) { JSONArray returnValue = null; try { - if(jsonObject.has(key)){ + if (jsonObject.has(key)) { returnValue = jsonObject.getJSONArray(key); } } catch (JSONException e) { @@ -262,17 +246,28 @@ public JSONArray getJSONArrayFromJsonObject(JSONObject jsonObject, String key) { } public DataCarrierService getDataCarrierService() { - if(dataCarrierService == null){ + if (dataCarrierService == null) { dataCarrierService = SpringContext.getBean(DataCarrierService.class); } return dataCarrierService; } + public OleNGMemorizeService getOleNGMemorizeService() { + if (null == oleNGMemorizeService) { + oleNGMemorizeService = new OleNGMemorizeServiceImpl(); + } + return oleNGMemorizeService; + } + + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService) { + this.oleNGMemorizeService = oleNGMemorizeService; + } + public CallNumberTypeRecord fetchCallNumberTypeRecordByName(String callNumberTypeName) { HashMap map = new HashMap(); map.put("name", callNumberTypeName); List matching = (List) getBusinessObjectService().findMatching(CallNumberTypeRecord.class, map); - if(CollectionUtils.isNotEmpty(matching)) { + if (CollectionUtils.isNotEmpty(matching)) { return matching.get(0); } return null; @@ -282,7 +277,7 @@ public ItemTypeRecord fetchItemTypeByName(String itemTypeName) { HashMap map = new HashMap(); map.put("name", itemTypeName); List matching = (List) getBusinessObjectService().findMatching(ItemTypeRecord.class, map); - if(CollectionUtils.isNotEmpty(matching)) { + if (CollectionUtils.isNotEmpty(matching)) { return matching.get(0); } return null; @@ -292,7 +287,7 @@ public ItemStatusRecord fetchItemStatusByName(String itemStatusTypeName) { HashMap map = new HashMap(); map.put("name", itemStatusTypeName); List matching = (List) getBusinessObjectService().findMatching(ItemStatusRecord.class, map); - if(CollectionUtils.isNotEmpty(matching)) { + if (CollectionUtils.isNotEmpty(matching)) { return matching.get(0); } return null; diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqOnlyServiceHandler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqOnlyServiceHandler.java index f07fd7fe0b..3595dc86a8 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqOnlyServiceHandler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/handler/CreateReqOnlyServiceHandler.java @@ -1,7 +1,9 @@ package org.kuali.ole.oleng.handler; import org.kuali.ole.Exchange; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.oleng.service.OleNGRequisitionService; +import org.kuali.ole.oleng.service.impl.OleNGMemorizeServiceImpl; import org.kuali.ole.utility.OleNgUtil; import org.kuali.ole.pojo.OleOrderRecord; import org.kuali.ole.select.document.OleRequisitionDocument; @@ -18,6 +20,7 @@ public class CreateReqOnlyServiceHandler extends OleNgUtil implements CreateReqAndPOBaseServiceHandler { private OleNGRequisitionService oleNGRequisitionService; + private OleNGMemorizeService oleNGMemorizeService; public Integer processOrder(List oleOrderRecords, Exchange exchange) throws Exception { GlobalVariables.setUserSession(new UserSession("ole-quickstart")); @@ -34,4 +37,15 @@ public OleNGRequisitionService getOleNGRequisitionService() { public void setOleNGRequisitionService(OleNGRequisitionService oleNGRequisitionService) { this.oleNGRequisitionService = oleNGRequisitionService; } + + public OleNGMemorizeService getOleNGMemorizeService() { + if(null == oleNGMemorizeService) { + oleNGMemorizeService = new OleNGMemorizeServiceImpl(); + } + return oleNGMemorizeService; + } + + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService) { + this.oleNGMemorizeService = oleNGMemorizeService; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/resolvers/OrderProcessHandler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/resolvers/OrderProcessHandler.java index f57eda3d5e..67ceb25b43 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/resolvers/OrderProcessHandler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/resolvers/OrderProcessHandler.java @@ -6,6 +6,7 @@ import org.kuali.ole.docstore.common.pojo.RecordDetails; import org.kuali.ole.oleng.batch.profile.model.BatchProcessProfile; import org.kuali.ole.oleng.handler.CreateReqAndPOBaseServiceHandler; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.oleng.service.OleNGRequisitionService; import org.kuali.ole.oleng.util.OleNGPOHelperUtil; @@ -23,7 +24,8 @@ public abstract class OrderProcessHandler { public abstract CreateReqAndPOBaseServiceHandler getCreateReqOrPOServiceHandler(); - public Map> processOrder(List recordDetailsList, BatchProcessProfile batchProcessProfile, Exchange exchange) throws Exception { + public Map> processOrder(List recordDetailsList, BatchProcessProfile batchProcessProfile, + OleNGMemorizeService oleNGMemorizeService, Exchange exchange) throws Exception { Map> poIdsMap = new HashMap<>(); OleNGPOHelperUtil oleNGPOHelperUtil = OleNGPOHelperUtil.getInstance(); @@ -34,13 +36,17 @@ public Map> processOrder(List recordDetails requisitionForTitlesOption.equalsIgnoreCase("One Requisition With All Titles")) { multiTitle = true; } + CreateReqAndPOBaseServiceHandler createReqOrPOServiceHandler = getCreateReqOrPOServiceHandler(); + createReqOrPOServiceHandler.setOleNGMemorizeService(oleNGMemorizeService); if(multiTitle) { - Map> poIdMap = oleNGPOHelperUtil.processReqAndPo(recordDetailsList, batchProcessProfile, getCreateReqOrPOServiceHandler(), exchange); + Map> poIdMap = oleNGPOHelperUtil.processReqAndPo(recordDetailsList, batchProcessProfile, + createReqOrPOServiceHandler, exchange); poIdsMap.putAll(poIdMap); } else { for (Iterator iterator = recordDetailsList.iterator(); iterator.hasNext(); ) { RecordDetails recordDetails = iterator.next(); - Map> poIdMap = oleNGPOHelperUtil.processReqAndPo(Collections.singletonList(recordDetails), batchProcessProfile, getCreateReqOrPOServiceHandler(), exchange); + Map> poIdMap = oleNGPOHelperUtil.processReqAndPo(Collections.singletonList(recordDetails), + batchProcessProfile, createReqOrPOServiceHandler, exchange); poIdsMap.putAll(poIdMap); } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java index b7b122a2ac..dab79fed67 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/OleNGBatchJobScheduler.java @@ -123,10 +123,11 @@ public void scheduleOrRescheduleJob(long id, long profileId, String jobType, Str } } - public boolean pauseJob(String jobName, String groupName){ + public boolean pauseJob(String jobId){ boolean paused = false; + String jobName = OleNGConstants.JOB_NAME_PFX + jobId; try { - scheduler.pauseJob(jobName, groupName); + getScheduler().pauseJob(jobName, OleNGConstants.GROUP); paused = true; } catch (SchedulerException e) { e.printStackTrace(); @@ -140,7 +141,7 @@ public boolean unScheduleJob(String jobName, boolean addPrefix){ jobName = OleNGConstants.JOB_NAME_PFX + jobName; } try { - scheduler.deleteJob(jobName, OleNGConstants.GROUP); + getScheduler().deleteJob(jobName, OleNGConstants.GROUP); unscheduled = true; } catch (SchedulerException e) { e.printStackTrace(); @@ -148,10 +149,11 @@ public boolean unScheduleJob(String jobName, boolean addPrefix){ return unscheduled; } - public boolean resumeJob(String jobName, String groupName){ + public boolean resumeJob(String jobId){ boolean unscheduled = false; + String jobName = OleNGConstants.JOB_NAME_PFX + jobId; try { - scheduler.resumeJob(jobName, groupName); + scheduler.resumeJob(jobName, OleNGConstants.GROUP); unscheduled = true; } catch (SchedulerException e) { e.printStackTrace(); diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java index 3d614279f2..148a4b3d31 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/scheduler/job/BatchSchedulerJob.java @@ -39,16 +39,20 @@ public void execute(JobExecutionContext context) long jobId = (Long) jobDataMap.get(OleNGConstants.JOB_ID); String principalName = (String) jobDataMap.get(OleNGConstants.PRINCIPAL_NAME); GlobalVariables.setUserSession(new UserSession(principalName)); - if(null != processor) { + BatchProcessJob batchProcessJobById = getBatchUtil().getBatchProcessJobById(jobId); + if(null != processor && batchProcessJobById != null) { + batchProcessJobById.setJobType(OleNGConstants.ADHOC); + batchProcessJobById.setNextRunTime(null); + batchProcessJobById.setCronExpression(null); + getBusinessObjectService().save(batchProcessJobById); String schedulerUploadLocation = ConfigContext.getCurrentContextConfig().getProperty("schedulerUploadLocation"); File schedulerFileUploadLocation = new File(schedulerUploadLocation, String.valueOf(jobId)); File file = getFileName(schedulerFileUploadLocation); if (null != file) { - File uploadedFileDirecotry = storeUploadedFileToFileSystem(file); + File uploadedFileDirecotry = storeUploadedFileToFileSystem(file, jobId); if(null != uploadedFileDirecotry) { String fileName = file.getName(); String extension = FilenameUtils.getExtension(fileName); - BatchProcessJob batchProcessJobById = getBatchUtil().getBatchProcessJobById(jobId); BatchJobDetails batchJobDetails = getBatchUtil().createBatchJobDetailsEntry(batchProcessJobById, fileName); getBusinessObjectService().save(batchJobDetails); try { @@ -83,10 +87,10 @@ private void processBatch(BatchFileProcessor batchFileProcessor, File uploadDire } } - private File storeUploadedFileToFileSystem(File file){ + private File storeUploadedFileToFileSystem(File file, Long jobId){ String batchUploadLocation = getBatchUploadLocation(); if(StringUtils.isNotBlank(batchUploadLocation)) { - batchUploadLocation = batchUploadLocation + File.separator + OleNGConstants.DATE_FORMAT.format(new Date()); + batchUploadLocation = batchUploadLocation + File.separator + jobId + "_" + OleNGConstants.DATE_FORMAT.format(new Date()); File uploadDirectory = new File(batchUploadLocation); try { FileUtils.moveFileToDirectory(file, uploadDirectory, true); diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGMemorizeService.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGMemorizeService.java new file mode 100644 index 0000000000..e2a8c0ed65 --- /dev/null +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGMemorizeService.java @@ -0,0 +1,47 @@ +package org.kuali.ole.oleng.service; + +import org.kuali.ole.coa.businessobject.Account; +import org.kuali.ole.coa.businessobject.OleFundCode; +import org.kuali.ole.module.purap.businessobject.ItemType; +import org.kuali.ole.module.purap.businessobject.PurchaseOrderType; +import org.kuali.ole.module.purap.document.service.OlePurapService; +import org.kuali.ole.oleng.batch.profile.model.BatchProcessProfile; +import org.kuali.ole.oleng.common.service.OleNgCommonMemorizeService; +import org.kuali.ole.select.bo.OLEDonor; +import org.kuali.ole.select.bo.OleVendorAccountInfo; +import org.kuali.ole.sys.businessobject.Building; +import org.kuali.ole.sys.businessobject.Room; +import org.kuali.ole.utility.LocationUtil; +import org.kuali.ole.vnd.businessobject.*; +import org.kuali.ole.vnd.document.service.VendorService; + +import java.util.List; + +/** + * Created by SheikS on 5/10/2016. + */ +public interface OleNGMemorizeService { + public OleNgCommonMemorizeService getOleNgCommonMemorizeService(); + public VendorService getVendorService(); + public OlePurapService getOlePurapService(); + public LocationUtil getLocationUtil(); + public boolean isValidLocation(String location); + public Room getRoom(String buildingCode, String campusCode, String buildingRoomNumber); + public Building getBuildingDetails(String campusCode, String buildingCode); + public String getParameter(String name); + public List getVendorAlias(String aliasName); + public VendorDetail getVendorDetail(Integer headerGeneratedIdentifier, Integer detailAssignedIdentifier); + public VendorAddress getVendorDefaultAddress(Integer vendorHeaderId, Integer vendorDetailId, String addressType, String campus); + public String getTransmissionMethodCode(String transmissionMethodDescription); + public List getOrderType(String key, String value); + public ItemType getPurapItemType(String type); + public Integer getRequestSourceTypeId(String requestSourceType); + public OLEDonor getDonorCode(String donorCode); + public BatchProcessProfile fetchBatchProcessProfile(String profileName, String type); + + public List getExchangeRate(String currencyTypeId); + public OleCurrencyType getCurrencyType(String currencyTypeId); + public List getVendorAccountInfo(String code); + public List getAccount(String accountNumber); + public List getFundCode(String fundCode); +} diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGRequisitionService.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGRequisitionService.java index ebab6f1342..e6d30e02a1 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGRequisitionService.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OleNGRequisitionService.java @@ -16,4 +16,5 @@ public OleRequisitionDocument populateReqDocWithOrderInformation(OleRequisitionD public OleRequisitionDocument saveRequsitionDocument(OleRequisitionDocument oleRequisitionDocument); public OleRequisitionDocument routeRequisitionDocument(OleRequisitionDocument oleRequisitionDocument) throws Exception; public OleRequisitionDocument createPurchaseOrderDocument(List oleOrderRecords, Exchange exchange) throws Exception; + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService); } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OrderImportService.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OrderImportService.java index 7455e0d9af..a5fa384f26 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OrderImportService.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/OrderImportService.java @@ -11,4 +11,5 @@ public interface OrderImportService { public OleTxRecord processDataMapping(RecordDetails recordDetails, BatchProcessProfile batchProcessProfile, Exchange exchange); + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService); } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java index da19d34aac..dac79dd5dc 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGInvoiceServiceImpl.java @@ -17,6 +17,7 @@ import org.kuali.ole.module.purap.document.validation.event.AttributedCalculateAccountsPayableEvent; import org.kuali.ole.module.purap.service.PurapAccountingService; import org.kuali.ole.oleng.service.OleNGInvoiceService; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.pojo.OleInvoiceRecord; import org.kuali.ole.select.OleSelectConstant; import org.kuali.ole.select.bo.OleVendorAccountInfo; @@ -33,6 +34,7 @@ import org.kuali.ole.sys.service.UniversityDateService; import org.kuali.ole.vnd.businessobject.OleCurrencyType; import org.kuali.ole.vnd.businessobject.OleExchangeRate; +import org.kuali.ole.vnd.businessobject.VendorAddress; import org.kuali.ole.vnd.businessobject.VendorDetail; import org.kuali.rice.core.api.util.type.KualiDecimal; import org.kuali.rice.core.api.util.type.KualiInteger; @@ -46,6 +48,7 @@ import org.kuali.rice.krad.util.GlobalVariables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -64,6 +67,8 @@ public class OleNGInvoiceServiceImpl implements OleNGInvoiceService { private OlePurapService olePurapService; private OleInvoiceService oleInvoiceService; private BatchUtil batchUtil; + @Autowired + private OleNGMemorizeService oleNGMemorizeService; @Override public OleInvoiceDocument createNewInvoiceDocument() throws Exception { @@ -89,7 +94,7 @@ public OleInvoiceDocument populateInvoiceDocWithOrderInformation(OleInvoiceDocum oleInvoiceDocument.setInvoiceNumber(oleInvoiceRecord.getInvoiceNumber()); String vendorNumber = oleInvoiceRecord.getVendorNumber(); - getInvoiceService().populateVendorDetail(vendorNumber, oleInvoiceDocument); + populateVendorDetail(vendorNumber, oleInvoiceDocument); oleInvoiceDocument.setVendorCustomerNumber(oleInvoiceRecord.getBillToCustomerID()); if(!StringUtils.isBlank(oleInvoiceRecord.getCurrencyTypeId())){ @@ -275,18 +280,19 @@ private OleInvoiceDocument initiateInvoiceDocument(OleInvoiceDocument invoiceDoc private void setDocumentForeignDetails(OleInvoiceDocument invoiceDocument, OleInvoiceRecord invoiceRecord){ - OleCurrencyType oleCurrencyType = getBusinessObjectService().findBySinglePrimaryKey(OleCurrencyType.class,invoiceRecord.getCurrencyTypeId()); - invoiceDocument.setInvoiceCurrencyType(oleCurrencyType.getCurrencyTypeId().toString()); - if(!oleCurrencyType.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){ - Map documentNumberMap = new HashMap(); - documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, invoiceRecord.getCurrencyTypeId()); - List exchangeRateList = (List) getBusinessObjectService().findMatchingOrderBy( - OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); - Iterator iterator = exchangeRateList.iterator(); - if (iterator.hasNext()) { - invoiceDocument.setForeignVendorInvoiceAmount(new BigDecimal(0.00)); - invoiceDocument.setInvoiceCurrencyTypeId(new Long(invoiceRecord.getCurrencyTypeId())); - invoiceDocument.setInvoiceCurrencyExchangeRate(invoiceRecord.getInvoiceCurrencyExchangeRate()); + OleCurrencyType oleCurrencyType = getOleNGMemorizeService().getCurrencyType(invoiceRecord.getCurrencyTypeId()); + if (null != oleCurrencyType) { + invoiceDocument.setInvoiceCurrencyType(oleCurrencyType.getCurrencyTypeId().toString()); + if(!oleCurrencyType.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){ + List exchangeRateList = getOleNGMemorizeService().getExchangeRate(invoiceRecord.getCurrencyTypeId()); + if (CollectionUtils.isNotEmpty(exchangeRateList)) { + Iterator iterator = exchangeRateList.iterator(); + if (iterator.hasNext()) { + invoiceDocument.setForeignVendorInvoiceAmount(new BigDecimal(0.00)); + invoiceDocument.setInvoiceCurrencyTypeId(new Long(invoiceRecord.getCurrencyTypeId())); + invoiceDocument.setInvoiceCurrencyExchangeRate(invoiceRecord.getInvoiceCurrencyExchangeRate()); + } + } } } } @@ -417,10 +423,13 @@ public OleInvoiceItem invoiceItemForUnlink(OleInvoiceRecord invoiceRecord, Integ } oleInvoiceItem.setSourceAccountingLines(accountingLine); - SimpleDateFormat dateFromRawFile = new SimpleDateFormat(org.kuali.ole.OLEConstants.DATE_FORMAT); try { - oleInvoiceItem.setSubscriptionFromDate(invoiceRecord.getSubscriptionPeriodFrom() != null ? new java.sql.Date(dateFromRawFile.parse(invoiceRecord.getSubscriptionPeriodFrom()).getTime()) : null); - oleInvoiceItem.setSubscriptionToDate(invoiceRecord.getSubscriptionPeriodTo() != null ? new java.sql.Date(dateFromRawFile.parse(invoiceRecord.getSubscriptionPeriodTo()).getTime()) : null); + oleInvoiceItem.setSubscriptionFromDate(invoiceRecord.getSubscriptionPeriodFrom() != null ? new java.sql.Date(OleNGConstants.DATE_FORMAT_WITHOUT_TIME.parse(invoiceRecord.getSubscriptionPeriodFrom()).getTime()) : null); + } catch (ParseException e) { + e.printStackTrace(); + } + try { + oleInvoiceItem.setSubscriptionToDate(invoiceRecord.getSubscriptionPeriodTo() != null ? new java.sql.Date(OleNGConstants.DATE_FORMAT_WITHOUT_TIME.parse(invoiceRecord.getSubscriptionPeriodTo()).getTime()) : null); } catch (ParseException e) { e.printStackTrace(); } @@ -436,9 +445,10 @@ private InvoiceAccount createInvoiceAccountFromVendorAccountInfo(OleInvoiceRecor invoiceAccount.setAccountLinePercent(new BigDecimal("100")); // TODO: Need to get from edifact. invoiceAccount.setPurapItem(oleInvoiceItem); invoiceAccount.setItemIdentifier(oleInvoiceItem.getItemIdentifier()); + String chartOfAccount = populateChartOfAccount(oleVendorAccountInfo.getAccountNumber()); invoiceAccount.setChartOfAccountsCode( - populateChartOfAccount(oleVendorAccountInfo.getAccountNumber()) != null ? - populateChartOfAccount(oleVendorAccountInfo.getAccountNumber()) : invoiceRecord.getItemChartCode()); // TODO: Need to get chart of Account based on account number and object code. + chartOfAccount != null ? + chartOfAccount : invoiceRecord.getItemChartCode()); // TODO: Need to get chart of Account based on account number and object code. return invoiceAccount; } @@ -457,10 +467,13 @@ private OleInvoiceItem createNewInvoiceItem(OleInvoiceRecord invoiceRecord) { oleInvoiceItem.setItemSalesTaxAmount(new KualiDecimal(invoiceRecord.getLineItemTaxAmount())); oleInvoiceItem.addToExtendedPrice(oleInvoiceItem.getItemSalesTaxAmount()); } - SimpleDateFormat dateFromRawFile = new SimpleDateFormat(org.kuali.ole.OLEConstants.DATE_FORMAT); try { - oleInvoiceItem.setSubscriptionFromDate(invoiceRecord.getSubscriptionPeriodFrom()!= null ? new java.sql.Date(dateFromRawFile.parse(invoiceRecord.getSubscriptionPeriodFrom()).getTime()):null); - oleInvoiceItem.setSubscriptionToDate(invoiceRecord.getSubscriptionPeriodTo()!= null ? new java.sql.Date(dateFromRawFile.parse(invoiceRecord.getSubscriptionPeriodTo()).getTime()):null); + oleInvoiceItem.setSubscriptionFromDate(invoiceRecord.getSubscriptionPeriodFrom()!= null ? new java.sql.Date(OleNGConstants.DATE_FORMAT_WITHOUT_TIME.parse(invoiceRecord.getSubscriptionPeriodFrom()).getTime()):null); + } catch (ParseException e) { + e.printStackTrace(); + } + try { + oleInvoiceItem.setSubscriptionToDate(invoiceRecord.getSubscriptionPeriodTo()!= null ? new java.sql.Date(OleNGConstants.DATE_FORMAT_WITHOUT_TIME.parse(invoiceRecord.getSubscriptionPeriodTo()).getTime()):null); } catch (ParseException e) { e.printStackTrace(); } @@ -477,24 +490,18 @@ private OleInvoiceItem createNewInvoiceItem(OleInvoiceRecord invoiceRecord) { private OleVendorAccountInfo populateBFN(String code) { - Map matchBFN = new HashMap(); - matchBFN.put("vendorRefNumber", code); - List oleVendorAccountInfo = (List) getBusinessObjectService().findMatching(OleVendorAccountInfo.class, matchBFN); - return oleVendorAccountInfo != null && oleVendorAccountInfo.size() > 0 ? oleVendorAccountInfo.get(0) : null; + List oleVendorAccountInfo = getOleNGMemorizeService().getVendorAccountInfo(code); + return CollectionUtils.isNotEmpty(oleVendorAccountInfo) ? oleVendorAccountInfo.get(0) : null; } private String populateChartOfAccount(String accountNumber) { - Map matchChartCode = new HashMap(); - matchChartCode.put("accountNumber", accountNumber); - List accountList = (List) getBusinessObjectService().findMatching(Account.class, matchChartCode); - return accountList != null && accountList.size() > 0 ? accountList.get(0).getChartOfAccountsCode() : null; + List accountList = getOleNGMemorizeService().getAccount(accountNumber); + return CollectionUtils.isNotEmpty(accountList)? accountList.get(0).getChartOfAccountsCode() : null; } private List getAccountingLinesFromFundCode(OleInvoiceRecord invoiceRecord, OleInvoiceItem oleInvoiceItem) { List accountingLine = new ArrayList(); - Map fundCodeMap = new HashMap<>(); - fundCodeMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, invoiceRecord.getFundCode()); - List fundCodeList = (List) getBusinessObjectService().findMatching(OleFundCode.class, fundCodeMap); + List fundCodeList = getOleNGMemorizeService().getFundCode(invoiceRecord.getFundCode()); if (CollectionUtils.isNotEmpty(fundCodeList)) { OleFundCode oleFundCode = fundCodeList.get(0); List fundCodeAccountingLineList = oleFundCode.getOleFundCodeAccountingLineList(); @@ -563,6 +570,56 @@ public void updatePrice(OleInvoiceDocument oleInvoiceDocument) { } } + public OleInvoiceDocument populateVendorDetail(String vendorNumber, OleInvoiceDocument oleInvoiceDocument) { + String[] vendorIds = vendorNumber != null ? vendorNumber.split("-") : new String[0]; + VendorDetail vendorDetail = getOleNGMemorizeService().getVendorDetail(Integer.valueOf(vendorIds[0]),Integer.valueOf(vendorIds[1])); + if (vendorDetail != null) { + oleInvoiceDocument.setVendorDetail(vendorDetail); + oleInvoiceDocument.setVendorName(vendorDetail.getVendorName()); + oleInvoiceDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier()); + oleInvoiceDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier()); + oleInvoiceDocument.setVendorNumber(vendorDetail.getVendorNumber()); + oleInvoiceDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier()); + oleInvoiceDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier()); + oleInvoiceDocument.setVendorFaxNumber(vendorDetail.getDefaultFaxNumber()); + //oleInvoiceDocument. + if (vendorDetail.getPaymentMethodId() != null) { + oleInvoiceDocument.setPaymentMethodIdentifier(vendorDetail.getPaymentMethodId().toString()); + oleInvoiceDocument.setPaymentMethodId(vendorDetail.getPaymentMethodId()); + } + + if (vendorDetail.getVendorPaymentTerms() != null) { + oleInvoiceDocument.setVendorPaymentTerms(vendorDetail.getVendorPaymentTerms()); + oleInvoiceDocument.setVendorPaymentTermsCode(vendorDetail.getVendorPaymentTerms().getVendorPaymentTermsCode()); + + } + if (vendorDetail.getVendorShippingTitle() != null) { + oleInvoiceDocument.setVendorShippingTitleCode(vendorDetail.getVendorShippingTitle().getVendorShippingTitleCode()); + } + if (vendorDetail.getVendorShippingPaymentTerms() != null) { + oleInvoiceDocument.setVendorShippingPaymentTerms(vendorDetail.getVendorShippingPaymentTerms()); + } + + for (VendorAddress vendorAddress : vendorDetail.getVendorAddresses()) { + if (vendorAddress.isVendorDefaultAddressIndicator()) { + oleInvoiceDocument.setVendorCityName(vendorAddress.getVendorCityName()); + oleInvoiceDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address()); + oleInvoiceDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address()); + oleInvoiceDocument.setVendorAttentionName(vendorAddress.getVendorAttentionName()); + oleInvoiceDocument.setVendorPostalCode(vendorAddress.getVendorZipCode()); + oleInvoiceDocument.setVendorStateCode(vendorAddress.getVendorStateCode()); + oleInvoiceDocument.setVendorAttentionName(vendorAddress.getVendorAttentionName()); + oleInvoiceDocument.setVendorAddressInternationalProvinceName(vendorAddress.getVendorAddressInternationalProvinceName()); + oleInvoiceDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode()); + oleInvoiceDocument.setVendorCountry(vendorAddress.getVendorCountry()); + //oleInvoiceDocument.setNoteLine1Text(vendorAddress.getNoteLine2Text + } + } + } + + return oleInvoiceDocument; + } + static class InvoiceItemDetail { private String subscriptionPeriod; private Integer poNumber; @@ -653,4 +710,14 @@ public void setBatchUtil(BatchUtil batchUtil) { this.batchUtil = batchUtil; } + public OleNGMemorizeService getOleNGMemorizeService() { + if(null == oleNGMemorizeService) { + oleNGMemorizeService = new OleNGMemorizeServiceImpl(); + } + return oleNGMemorizeService; + } + + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService) { + this.oleNGMemorizeService = oleNGMemorizeService; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGMemorizeServiceImpl.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGMemorizeServiceImpl.java new file mode 100644 index 0000000000..2a5090633e --- /dev/null +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGMemorizeServiceImpl.java @@ -0,0 +1,230 @@ +package org.kuali.ole.oleng.service.impl; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.annotate.JsonAutoDetect; +import org.codehaus.jackson.map.ObjectMapper; +import org.kuali.ole.OLEConstants; +import org.kuali.ole.cache.Memoize; +import org.kuali.ole.coa.businessobject.Account; +import org.kuali.ole.coa.businessobject.OleFundCode; +import org.kuali.ole.docstore.common.util.BusinessObjectServiceHelperUtil; +import org.kuali.ole.module.purap.businessobject.ItemType; +import org.kuali.ole.module.purap.businessobject.PurchaseOrderTransmissionMethod; +import org.kuali.ole.module.purap.businessobject.PurchaseOrderType; +import org.kuali.ole.module.purap.document.service.OlePurapService; +import org.kuali.ole.oleng.batch.profile.model.BatchProcessProfile; +import org.kuali.ole.oleng.common.service.OleNgCommonMemorizeService; +import org.kuali.ole.oleng.common.service.impl.OleNgCommonMemorizeServiceImpl; +import org.kuali.ole.oleng.service.OleNGMemorizeService; +import org.kuali.ole.select.OleSelectConstant; +import org.kuali.ole.select.bo.OLEDonor; +import org.kuali.ole.select.bo.OleVendorAccountInfo; +import org.kuali.ole.select.businessobject.OleRequestSourceType; +import org.kuali.ole.select.document.service.OleDocstoreHelperService; +import org.kuali.ole.sys.businessobject.Building; +import org.kuali.ole.sys.businessobject.Room; +import org.kuali.ole.sys.context.SpringContext; +import org.kuali.ole.utility.LocationUtil; +import org.kuali.ole.vnd.businessobject.*; +import org.kuali.ole.vnd.document.service.VendorService; +import org.kuali.rice.krad.service.KRADServiceLocator; +import org.kuali.rice.krad.service.KRADServiceLocatorWeb; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by SheikS on 5/10/2016. + */ +@Component +public class OleNGMemorizeServiceImpl extends BusinessObjectServiceHelperUtil + implements OleNGMemorizeService { + + @Autowired + private OleNgCommonMemorizeService oleNgCommonMemorizeService; + + private LocationUtil locationUtil; + private OleDocstoreHelperService oleDocstoreHelperService; + private VendorService vendorService; + private OlePurapService olePurapService; + + @Override + public OleNgCommonMemorizeService getOleNgCommonMemorizeService() { + if(null == oleNgCommonMemorizeService) { + oleNgCommonMemorizeService = new OleNgCommonMemorizeServiceImpl(); + } + return oleNgCommonMemorizeService; + } + + @Memoize + public boolean isValidLocation(String location) { + return getOleDocstoreHelperService().isValidLocation(location); + } + + @Memoize + public Room getRoom(String buildingCode, String campusCode, String buildingRoomNumber) { + Map deliveryMap = new HashMap<>(); + deliveryMap.put(OLEConstants.OLEBatchProcess.BUILDING_CODE, buildingCode); + deliveryMap.put(OLEConstants.OLEBatchProcess.CAMPUS_CODE, campusCode); + deliveryMap.put(OLEConstants.BUILDING_ROOM_NUMBER, buildingRoomNumber); + return getBusinessObjectService().findByPrimaryKey(Room.class, deliveryMap); + } + + @Memoize + public Building getBuildingDetails(String campusCode, String buildingCode) { + return getVendorService().getBuildingDetails(campusCode, buildingCode); + } + + @Memoize + public String getParameter(String name) { + return getOlePurapService().getParameter(name); + } + + @Memoize + public List getVendorAlias(String aliasName) { + Map vendorAliasMap = new HashMap<>(); + vendorAliasMap.put(OLEConstants.OLEBatchProcess.VENDOR_ALIAS_NAME, aliasName); + return (List) KRADServiceLocatorWeb.getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true); + } + + @Memoize + public VendorDetail getVendorDetail(Integer headerGeneratedIdentifier, Integer detailAssignedIdentifier) { + Map vendorDetailMap = new HashMap(); + vendorDetailMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_HEADER_IDENTIFIER, headerGeneratedIdentifier); + vendorDetailMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_DETAIL_IDENTIFIER, detailAssignedIdentifier); + return getBusinessObjectService().findByPrimaryKey(VendorDetail.class, vendorDetailMap); + } + + @Memoize + public VendorAddress getVendorDefaultAddress(Integer vendorHeaderId, Integer vendorDetailId, String addressType, String campus) { + return getVendorService().getVendorDefaultAddress(vendorHeaderId, vendorDetailId, addressType, campus); + } + @Memoize + public String getTransmissionMethodCode(String transmissionMethodDescription){ + Map transmissionCodeMap = new HashMap<>(); + transmissionCodeMap.put(OLEConstants.OLEBatchProcess.PO_TRANSMISSION_METHOD_DESC, transmissionMethodDescription); + List transmissionMethodList = (List) getBusinessObjectService().findMatching(PurchaseOrderTransmissionMethod.class, transmissionCodeMap); + if (CollectionUtils.isNotEmpty(transmissionMethodList)) { + return transmissionMethodList.get(0).getPurchaseOrderTransmissionMethodCode(); + } + return null; + } + + @Memoize + public List getOrderType(String key, String value) { + Map purchaseOrderTypeMap = new HashMap(); + purchaseOrderTypeMap.put(key, value); + return (List) getBusinessObjectService().findMatching(PurchaseOrderType.class, purchaseOrderTypeMap); + } + + @Memoize + public ItemType getPurapItemType(String type) { + return getBusinessObjectService().findBySinglePrimaryKey(org.kuali.ole.module.purap.businessobject.ItemType.class, type); + } + + @Memoize + public Integer getRequestSourceTypeId(String requestSourceType) { + Map requestSourceMap = new HashMap<>(); + requestSourceMap.put(OLEConstants.OLEBatchProcess.REQUEST_SRC,requestSourceType); + List requestSourceList = (List) getBusinessObjectService().findMatching(OleRequestSourceType.class, requestSourceMap); + if(requestSourceList != null && requestSourceList.size() > 0){ + return requestSourceList.get(0).getRequestSourceTypeId(); + } + return null; + } + + public OLEDonor getDonorCode(String donorCode) { + return getOleNgCommonMemorizeService().getDonorCode(donorCode); + } + + @Memoize + public BatchProcessProfile fetchBatchProcessProfile(String profileName, String type) { + BatchProcessProfile batchProcessProfile = null; + Map parameterMap = new HashMap(); + parameterMap.put("batchProcessProfileName", profileName); + List matching = (List) KRADServiceLocator.getBusinessObjectService().findMatching(BatchProcessProfile.class, parameterMap); + if (CollectionUtils.isNotEmpty(matching)) { + try { + batchProcessProfile = matching.get(0); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setVisibilityChecker(objectMapper.getVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY)); + batchProcessProfile = objectMapper.readValue(IOUtils.toString(batchProcessProfile.getContent()), BatchProcessProfile.class); + } catch (IOException e) { + e.printStackTrace(); + } + } + return batchProcessProfile; + } + + @Memoize + public List getExchangeRate(String currencyTypeId) { + Map documentNumberMap = new HashMap(); + documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, currencyTypeId); + return (List) getBusinessObjectService().findMatchingOrderBy( + OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); + } + + @Memoize + public OleCurrencyType getCurrencyType(String currencyTypeId) { + return getBusinessObjectService().findBySinglePrimaryKey(OleCurrencyType.class,currencyTypeId); + } + + @Memoize + public List getVendorAccountInfo(String code) { + Map matchBFN = new HashMap(); + matchBFN.put("vendorRefNumber", code); + return (List) getBusinessObjectService().findMatching(OleVendorAccountInfo.class, matchBFN); + } + + @Memoize + public List getAccount(String accountNumber) { + Map matchChartCode = new HashMap(); + matchChartCode.put("accountNumber", accountNumber); + return (List) getBusinessObjectService().findMatching(Account.class, matchChartCode); + } + + @Memoize + public List getFundCode(String fundCode) { + Map fundCodeMap = new HashMap<>(); + fundCodeMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, fundCode); + return (List) getBusinessObjectService().findMatching(OleFundCode.class, fundCodeMap); + } + + @Override + public LocationUtil getLocationUtil() { + if(null == locationUtil){ + locationUtil = new LocationUtil(); + locationUtil.setOleNgCommonMemorizeService(oleNgCommonMemorizeService); + } + return locationUtil; + } + + + public OleDocstoreHelperService getOleDocstoreHelperService() { + if(null == oleDocstoreHelperService) { + oleDocstoreHelperService = SpringContext.getBean(OleDocstoreHelperService.class); + } + return oleDocstoreHelperService; + } + + public VendorService getVendorService() { + if (vendorService == null) { + vendorService = SpringContext.getBean(VendorService.class); + } + return vendorService; + } + + + public OlePurapService getOlePurapService() { + if (olePurapService == null) { + olePurapService = SpringContext.getBean(OlePurapService.class); + } + return olePurapService; + } + +} diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGRequisitionServiceImpl.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGRequisitionServiceImpl.java index 64c4cab894..5028760d97 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGRequisitionServiceImpl.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OleNGRequisitionServiceImpl.java @@ -7,7 +7,6 @@ import org.kuali.ole.coa.businessobject.OleFundCode; import org.kuali.ole.coa.businessobject.OleFundCodeAccountingLine; import org.kuali.ole.deliver.service.ParameterValueResolver; -import org.kuali.ole.docstore.common.client.DocstoreClientLocator; import org.kuali.ole.docstore.common.util.BusinessObjectServiceHelperUtil; import org.kuali.ole.module.purap.PurapConstants; import org.kuali.ole.module.purap.businessobject.PurApAccountingLine; @@ -15,23 +14,26 @@ import org.kuali.ole.module.purap.businessobject.RequisitionAccount; import org.kuali.ole.module.purap.businessobject.RequisitionItem; import org.kuali.ole.module.purap.document.RequisitionDocument; -import org.kuali.ole.module.purap.document.service.OlePurapService; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.oleng.service.OleNGRequisitionService; import org.kuali.ole.pojo.OleBibRecord; import org.kuali.ole.pojo.OleOrderRecord; import org.kuali.ole.pojo.OleTxRecord; import org.kuali.ole.select.OleSelectNotificationConstant; -import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService; import org.kuali.ole.select.bo.OLEDonor; import org.kuali.ole.select.bo.OLELinkPurapDonor; -import org.kuali.ole.select.businessobject.OleRequestSourceType; import org.kuali.ole.select.businessobject.OleRequisitionItem; import org.kuali.ole.select.document.OleRequisitionDocument; -import org.kuali.ole.select.service.impl.OleReqPOCreateDocumentServiceImpl; import org.kuali.ole.spring.batch.BatchUtil; +import org.kuali.ole.sys.businessobject.Building; +import org.kuali.ole.sys.businessobject.Room; import org.kuali.ole.sys.context.SpringContext; import org.kuali.ole.sys.document.validation.event.DocumentSystemSaveEvent; -import org.kuali.rice.core.api.config.property.ConfigurationService; +import org.kuali.ole.vnd.VendorConstants; +import org.kuali.ole.vnd.businessobject.VendorAddress; +import org.kuali.ole.vnd.businessobject.VendorAlias; +import org.kuali.ole.vnd.businessobject.VendorContract; +import org.kuali.ole.vnd.businessobject.VendorDetail; import org.kuali.rice.core.api.util.type.KualiDecimal; import org.kuali.rice.core.api.util.type.KualiInteger; import org.kuali.rice.kew.framework.postprocessor.IDocumentEvent; @@ -42,10 +44,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Created by SheikS on 12/17/2015. @@ -55,14 +54,9 @@ public class OleNGRequisitionServiceImpl extends BusinessObjectServiceHelperUtil private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleNGRequisitionServiceImpl.class); - private OlePurapService olePurapService; - private OleReqPOCreateDocumentServiceImpl oleReqPOCreateDocumentService; - protected RequisitionCreateDocumentService requisitionCreateDocumentService; - private DocstoreClientLocator docstoreClientLocator; - private ConfigurationService kualiConfigurationService; - protected DocumentService documentService; private BatchUtil batchUtil; + private OleNGMemorizeService oleNGMemorizeService; @Override public OleRequisitionDocument createPurchaseOrderDocument(List oleOrderRecords, Exchange exchange) throws Exception { @@ -162,7 +156,7 @@ protected RequisitionItem createRequisitionItem(OleOrderRecord oleOrderRecord, i item.setItemStatus(oleTxRecord.getItemStatus()); item.setOleOrderRecord(oleOrderRecord); item.setItemLineNumber(itemLineNumber); - item.setItemUnitOfMeasureCode(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.UOM)); + item.setItemUnitOfMeasureCode(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.UOM)); item.setItemQuantity(new KualiDecimal(oleTxRecord.getQuantity())); if (oleTxRecord.getItemNoOfParts() != null) { item.setItemNoOfParts(new KualiInteger(oleTxRecord.getItemNoOfParts())); @@ -185,7 +179,7 @@ protected RequisitionItem createRequisitionItem(OleOrderRecord oleOrderRecord, i item.setFormatTypeId(Integer.parseInt(oleTxRecord.getFormatTypeId())); } if(oleTxRecord.getRequestSourceType() != null){ - item.setRequestSourceTypeId(getRequestSourceTypeId(oleTxRecord.getRequestSourceType())); + item.setRequestSourceTypeId(getOleNGMemorizeService().getRequestSourceTypeId(oleTxRecord.getRequestSourceType())); } setDonors(item, oleTxRecord); @@ -277,17 +271,17 @@ protected RequisitionDocument setDocumentValues(OleRequisitionDocument requisiti requisitionDocument.setOrganizationCode(oleOrderRecord.getOleTxRecord().getOrgCode()); requisitionDocument.setDocumentFundingSourceCode(oleOrderRecord.getOleTxRecord().getFundingSource()); requisitionDocument.setUseTaxIndicator(true); - getOleReqPOCreateDocumentService().setDeliveryDetails(requisitionDocument, oleOrderRecord); + setDeliveryDetails(requisitionDocument, oleOrderRecord); requisitionDocument.setDeliveryCampusCode(oleOrderRecord.getOleTxRecord().getDeliveryCampusCode()); - getOleReqPOCreateDocumentService().setVendorDetails(requisitionDocument, oleOrderRecord); + setVendorDetails(requisitionDocument, oleOrderRecord); requisitionDocument.getDocumentHeader().setDocumentDescription(getDocumentDescription(requisitionDocument, oleOrderRecord)); - requisitionDocument.setPurchaseOrderTransmissionMethodCode(oleOrderRecord.getOleTxRecord().getMethodOfPOTransmission());//FAX + requisitionDocument.setPurchaseOrderTransmissionMethodCode(getOleNGMemorizeService().getTransmissionMethodCode(oleOrderRecord.getOleTxRecord().getMethodOfPOTransmission()));//FAX requisitionDocument.setPurchaseOrderCostSourceCode(oleOrderRecord.getOleTxRecord().getCostSource());//CON - requisitionDocument.setRequestorPersonName(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_NAME)); - requisitionDocument.setRequestorPersonPhoneNumber(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_PHONE_NUMBER)); - requisitionDocument.setRequestorPersonEmailAddress(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_EMAIL_ADDRESS)); - requisitionDocument.setOrganizationAutomaticPurchaseOrderLimit(new KualiDecimal(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.VENDOR_CONTRACT_DEFAULT_APO_LIMIT))); - requisitionDocument.setPurchaseOrderAutomaticIndicator(Boolean.parseBoolean(getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.PURCHASE_ORDER_AUTOMATIC_INDICATIOR))); + requisitionDocument.setRequestorPersonName(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_NAME)); + requisitionDocument.setRequestorPersonPhoneNumber(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_PHONE_NUMBER)); + requisitionDocument.setRequestorPersonEmailAddress(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.REQUESTOR_PERSON_EMAIL_ADDRESS)); + requisitionDocument.setOrganizationAutomaticPurchaseOrderLimit(new KualiDecimal(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.VENDOR_CONTRACT_DEFAULT_APO_LIMIT))); + requisitionDocument.setPurchaseOrderAutomaticIndicator(Boolean.parseBoolean(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.PURCHASE_ORDER_AUTOMATIC_INDICATIOR))); requisitionDocument.setReceivingDocumentRequiredIndicator(oleOrderRecord.getOleTxRecord().isReceivingRequired()); requisitionDocument.setPaymentRequestPositiveApprovalIndicator(oleOrderRecord.getOleTxRecord().isPayReqPositiveApprovalReq()); requisitionDocument.setRequisitionSourceCode(oleOrderRecord.getOleTxRecord().getRequisitionSource()); @@ -297,28 +291,32 @@ protected RequisitionDocument setDocumentValues(OleRequisitionDocument requisiti } private void setOrderType(OleRequisitionDocument requisitionDocument, OleTxRecord oleTxRecord) { - Map purchaseOrderTypeMap = new HashMap(); + String key; + String value; if (StringUtils.isNotBlank(oleTxRecord.getOrderType())) { - purchaseOrderTypeMap.put(OLEConstants.PO_TYPE, oleTxRecord.getOrderType()); + key = OLEConstants.PO_TYPE; + value = oleTxRecord.getOrderType(); } else { - purchaseOrderTypeMap.put("purchaseOrderTypeId", OLEConstants.DEFAULT_ORDER_TYPE_VALUE); + key = "purchaseOrderTypeId"; + value = OLEConstants.DEFAULT_ORDER_TYPE_VALUE; } - List purchaseOrderTypeDocumentList = (List) getBusinessObjectService().findMatching(PurchaseOrderType.class, purchaseOrderTypeMap); - if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) { + List purchaseOrderTypeDocumentList = getOleNGMemorizeService().getOrderType(key,value); + if (CollectionUtils.isNotEmpty(purchaseOrderTypeDocumentList)) { requisitionDocument.setPurchaseOrderTypeId(purchaseOrderTypeDocumentList.get(0).getPurchaseOrderTypeId()); requisitionDocument.setOrderType(purchaseOrderTypeDocumentList.get(0)); } } public String getDocumentDescription(OleRequisitionDocument requisitionDocument, OleOrderRecord oleOrderRecord) { - String description = getOlePurapService().getParameter(org.kuali.ole.sys.OLEConstants.ORDER_IMPORT_REQ_DESC); + String description = getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.ORDER_IMPORT_REQ_DESC); Map descMap = new HashMap<>(); - if (requisitionDocument.getVendorDetail().getVendorAliases() != null && requisitionDocument.getVendorDetail().getVendorAliases().size() > 0 && requisitionDocument.getVendorDetail().getVendorAliases().get(0).getVendorAliasName() != null) { + if (requisitionDocument.getVendorDetail().getVendorAliases() != null && requisitionDocument.getVendorDetail().getVendorAliases().size() > 0 && + requisitionDocument.getVendorDetail().getVendorAliases().get(0).getVendorAliasName() != null) { descMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_NAME, requisitionDocument.getVendorDetail().getVendorAliases().get(0).getVendorAliasName()); } descMap.put(org.kuali.ole.sys.OLEConstants.ORDER_TYP, oleOrderRecord.getOleTxRecord().getOrderType()); descMap.put(org.kuali.ole.sys.OLEConstants.VND_ITM_ID, oleOrderRecord.getOleTxRecord().getVendorItemIdentifier() != null && !oleOrderRecord.getOleTxRecord().getVendorItemIdentifier().isEmpty() ? oleOrderRecord.getOleTxRecord().getVendorItemIdentifier() + "_" : ""); - description = getOlePurapService().setDocumentDescription(description, descMap); + description = getOleNGMemorizeService().getOlePurapService().setDocumentDescription(description, descMap); if (!description.equals("") && description != null) { description = description.substring(0, description.lastIndexOf("_")); } @@ -331,19 +329,8 @@ public String getDocumentDescription(OleRequisitionDocument requisitionDocument, return description; } - - private Integer getRequestSourceTypeId(String requestSourceType){ - Map requestSourceMap = new HashMap<>(); - requestSourceMap.put(OLEConstants.OLEBatchProcess.REQUEST_SRC,requestSourceType); - List requestSourceList = (List) getBusinessObjectService().findMatching(OleRequestSourceType.class, requestSourceMap); - if(requestSourceList != null && requestSourceList.size() > 0){ - return requestSourceList.get(0).getRequestSourceTypeId(); - } - return null; - } - private void setItemType(OleRequisitionItem item) { - org.kuali.ole.module.purap.businessobject.ItemType itemType = getBusinessObjectService().findBySinglePrimaryKey(org.kuali.ole.module.purap.businessobject.ItemType.class, "ITEM"); + org.kuali.ole.module.purap.businessobject.ItemType itemType = getOleNGMemorizeService().getPurapItemType("ITEM"); item.setItemType(itemType); } @@ -352,9 +339,7 @@ private void setDonors(OleRequisitionItem item, OleTxRecord oleTxRecord) { if (CollectionUtils.isNotEmpty(oleDonors)) { List oleLinkPurapDonorList = new ArrayList<>(); for (String donor : oleDonors) { - Map map = new HashMap(); - map.put(OLEConstants.DONOR_CODE, donor); - OLEDonor oleDonor = getBusinessObjectService().findByPrimaryKey(OLEDonor.class, map); + OLEDonor oleDonor = getOleNGMemorizeService().getDonorCode(donor); if (oleDonor != null) { OLELinkPurapDonor oleLinkPurapDonor = new OLELinkPurapDonor(); oleLinkPurapDonor.setDonorCode(donor); @@ -366,52 +351,91 @@ private void setDonors(OleRequisitionItem item, OleTxRecord oleTxRecord) { } } + public void setDeliveryDetails(OleRequisitionDocument requisitionDocument, OleOrderRecord oleOrderRecord) { + if (LOG.isDebugEnabled()) + LOG.debug("bibInfoBean.getDeliveryBuildingCode----------->" + oleOrderRecord.getOleTxRecord().getBuildingCode()); + + if (oleOrderRecord.getOleTxRecord().getDeliveryCampusCode() != null && oleOrderRecord.getOleTxRecord().getBuildingCode() != null && oleOrderRecord.getOleTxRecord().getDeliveryBuildingRoomNumber() != null) { + Room room = getOleNGMemorizeService().getRoom(oleOrderRecord.getOleTxRecord().getBuildingCode(), + oleOrderRecord.getOleTxRecord().getDeliveryCampusCode(), + oleOrderRecord.getOleTxRecord().getDeliveryBuildingRoomNumber()); + Building building = getOleNGMemorizeService().getBuildingDetails(oleOrderRecord.getOleTxRecord().getDeliveryCampusCode(), oleOrderRecord.getOleTxRecord().getBuildingCode()); + if (building != null && room != null) { + requisitionDocument.setDeliveryBuildingCode(building.getBuildingCode()); + requisitionDocument.setDeliveryCampusCode(building.getCampusCode()); + requisitionDocument.setDeliveryBuildingLine1Address(building.getBuildingStreetAddress()); + requisitionDocument.setDeliveryBuildingName(building.getBuildingName()); + requisitionDocument.setDeliveryCityName(building.getBuildingAddressCityName()); + requisitionDocument.setDeliveryStateCode(building.getBuildingAddressStateCode()); + requisitionDocument.setDeliveryPostalCode(building.getBuildingAddressZipCode()); + requisitionDocument.setDeliveryCountryCode(building.getBuildingAddressCountryCode()); + requisitionDocument.setDeliveryBuildingRoomNumber(room.getBuildingRoomNumber()); + requisitionDocument.setDeliveryToName(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.DELIVERY_TO_NAME)); + requisitionDocument.setBillingCountryCode(building.getBuildingCode()); + requisitionDocument.setBillingLine1Address(building.getBuildingStreetAddress()); + requisitionDocument.setBillingName(building.getBuildingName()); + requisitionDocument.setBillingCityName(building.getBuildingAddressCityName()); + requisitionDocument.setBillingStateCode(building.getBuildingAddressStateCode()); + requisitionDocument.setBillingPostalCode(building.getBuildingAddressZipCode()); + requisitionDocument.setBillingCountryCode(building.getBuildingAddressCountryCode()); + requisitionDocument.setBillingPhoneNumber(getOleNGMemorizeService().getParameter(org.kuali.ole.sys.OLEConstants.BILL_PHN_NBR)); - public OleReqPOCreateDocumentServiceImpl getOleReqPOCreateDocumentService() { - if (null == oleReqPOCreateDocumentService) { - oleReqPOCreateDocumentService = (OleReqPOCreateDocumentServiceImpl) SpringContext.getService("oleReqPOCreateDocumentService"); + } } - return oleReqPOCreateDocumentService; } - public OlePurapService getOlePurapService() { - if (olePurapService == null) { - olePurapService = SpringContext.getBean(OlePurapService.class); + public void setVendorDetails(OleRequisitionDocument requisitionDocument, OleOrderRecord oleOrderRecord) { + VendorDetail vendorDetail = null; + if (StringUtils.isNotBlank(oleOrderRecord.getOleTxRecord().getVendorNumber())) { + vendorDetail = getOleNGMemorizeService().getVendorService().getVendorDetail(oleOrderRecord.getOleTxRecord().getVendorNumber()); + }else if (StringUtils.isNotBlank(oleOrderRecord.getOleTxRecord().getVendorAliasName())){ + List vendorAliasList = getOleNGMemorizeService().getVendorAlias(oleOrderRecord.getOleTxRecord().getVendorAliasName()); + if (CollectionUtils.isNotEmpty(vendorAliasList)){ + vendorDetail = getOleNGMemorizeService().getVendorDetail(vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier(), vendorAliasList.get(0).getVendorDetailAssignedIdentifier()); + } } - return olePurapService; - } + if (vendorDetail!=null){ + requisitionDocument.setVendorCustomerNumber(oleOrderRecord.getOleTxRecord().getVendorInfoCustomer()); + requisitionDocument.setVendorNumber(oleOrderRecord.getOleTxRecord().getVendorNumber()); + requisitionDocument.setVendorNumber(vendorDetail.getVendorNumber()); + requisitionDocument.setVendorName(vendorDetail.getVendorName()); + requisitionDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier()); + requisitionDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier()); + requisitionDocument.setVendorDetail(vendorDetail); + String deliveryCampus = oleOrderRecord.getOleTxRecord().getDeliveryCampusCode(); + Integer headerId = null; + Integer detailId = null; + int dashInd = vendorDetail.getVendorNumber().indexOf('-'); + // make sure there's at least one char before and after '-' + if (dashInd > 0 && dashInd < vendorDetail.getVendorNumber().length() - 1) { + headerId = new Integer(vendorDetail.getVendorNumber().substring(0, dashInd)); + detailId = new Integer(vendorDetail.getVendorNumber().substring(dashInd + 1)); + } + VendorAddress vendorAddress = getOleNGMemorizeService().getVendorDefaultAddress(headerId, detailId, VendorConstants.AddressTypes.PURCHASE_ORDER, deliveryCampus); + setVendorAddress(vendorAddress, requisitionDocument); - public RequisitionCreateDocumentService getRequisitionCreateDocumentService() { - if (requisitionCreateDocumentService == null) { - requisitionCreateDocumentService = SpringContext.getBean(RequisitionCreateDocumentService.class); + List vendorContracts = vendorDetail.getVendorContracts(); + for (Iterator vendorContract = vendorContracts.iterator(); vendorContract.hasNext(); ) { + requisitionDocument.setVendorContractGeneratedIdentifier((vendorContract.next()).getVendorContractGeneratedIdentifier()); + } } - return requisitionCreateDocumentService; - } - public void setRequisitionCreateDocumentService(RequisitionCreateDocumentService requisitionCreateDocumentService) { - if (null == requisitionCreateDocumentService) { - requisitionCreateDocumentService = SpringContext.getBean(RequisitionCreateDocumentService.class); - } - this.requisitionCreateDocumentService = requisitionCreateDocumentService; } - - public DocstoreClientLocator getDocstoreClientLocator() { - - if (docstoreClientLocator == null) { - docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class); - + public void setVendorAddress(VendorAddress vendorAddress, RequisitionDocument requisitionDocument) { + + if (vendorAddress != null) { + requisitionDocument.setVendorAddressGeneratedIdentifier(vendorAddress.getVendorAddressGeneratedIdentifier()); + requisitionDocument.setVendorAddressInternationalProvinceName(vendorAddress.getVendorAddressInternationalProvinceName()); + requisitionDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address()); + requisitionDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address()); + requisitionDocument.setVendorCityName(vendorAddress.getVendorCityName()); + requisitionDocument.setVendorStateCode(vendorAddress.getVendorStateCode()); + requisitionDocument.setVendorPostalCode(vendorAddress.getVendorZipCode()); + requisitionDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode()); } - return docstoreClientLocator; - } - public ConfigurationService getConfigurationService() { - if (kualiConfigurationService == null) { - kualiConfigurationService = SpringContext.getBean(ConfigurationService.class); - } - return kualiConfigurationService; } - public DocumentService getDocumentService() { if(null == documentService) { documentService = (DocumentService) SpringContext.getService("documentService"); @@ -425,4 +449,15 @@ public BatchUtil getBatchUtil() { } return batchUtil; } + + public OleNGMemorizeService getOleNGMemorizeService() { + if(null == oleNGMemorizeService) { + oleNGMemorizeService = new OleNGMemorizeServiceImpl(); + } + return oleNGMemorizeService; + } + + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService) { + this.oleNGMemorizeService = oleNGMemorizeService; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OrderImportServiceImpl.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OrderImportServiceImpl.java index 21f7acaf7a..60016d36a3 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OrderImportServiceImpl.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/service/impl/OrderImportServiceImpl.java @@ -16,6 +16,7 @@ import org.kuali.ole.oleng.batch.profile.model.BatchProcessProfile; import org.kuali.ole.oleng.batch.profile.model.BatchProfileDataMapping; import org.kuali.ole.oleng.resolvers.orderimport.*; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.oleng.service.OrderImportService; import org.kuali.ole.pojo.OleTxRecord; import org.kuali.ole.select.document.service.OleDocstoreHelperService; @@ -39,8 +40,8 @@ public class OrderImportServiceImpl implements OrderImportService { private MarcRecordUtil marcRecordUtil; private BusinessObjectService businessObjectService; private BatchUtil batchUtil; - private LocationUtil locationUtil; private OleDocstoreHelperService oleDocstoreHelperService; + private OleNGMemorizeService oleNGMemorizeService; @Override public OleTxRecord processDataMapping(RecordDetails recordDetails, BatchProcessProfile batchProcessProfile, Exchange exchange) { @@ -154,13 +155,14 @@ private void overlayCopyNumber(OleTxRecord oleTxRecord, JSONObject dataMapping) private void overlayLocation(OleTxRecord oleTxRecord, JSONObject dataMapping, Exchange exchange) { StringBuilder locationName = new StringBuilder(); - Map locationMap = getLocationUtil().buildLocationMap(dataMapping, exchange); + LocationUtil locationUtil = getOleNGMemorizeService().getLocationUtil(); + Map locationMap = locationUtil.buildLocationMap(dataMapping, exchange); for (Iterator iterator = locationMap.keySet().iterator(); iterator.hasNext(); ) { String key = iterator.next(); String locationCode = locationMap.get(key); - getLocationUtil().appendLocationToStringBuilder(locationName, locationCode); + locationUtil.appendLocationToStringBuilder(locationName, locationCode); } - boolean validLocation = getOleDocstoreHelperService().isValidLocation(locationName.toString()); + boolean validLocation = getOleNGMemorizeService().isValidLocation(locationName.toString()); if(validLocation) { oleTxRecord.setDefaultLocation(locationName.toString()); } @@ -169,7 +171,7 @@ private void overlayLocation(OleTxRecord oleTxRecord, JSONObject dataMapping, Ex ParameterValueResolver instance = ParameterValueResolver.getInstance(); String defaultLocation = instance.getParameter(OLEConstants.APPL_ID_OLE, OLEConstants.SELECT_NMSPC, OLEConstants.SELECT_CMPNT, org.kuali.ole.sys.OLEConstants.ITEM_LOCATION_FIRM_FIXD); - validLocation = getOleDocstoreHelperService().isValidLocation(defaultLocation); + validLocation = getOleNGMemorizeService().isValidLocation(defaultLocation); if(validLocation) { oleTxRecord.setDefaultLocation(defaultLocation); } @@ -293,17 +295,6 @@ public void setBatchUtil(BatchUtil batchUtil) { this.batchUtil = batchUtil; } - public LocationUtil getLocationUtil() { - if(null == locationUtil) { - locationUtil = new LocationUtil(); - } - return locationUtil; - } - - public void setLocationUtil(LocationUtil locationUtil) { - this.locationUtil = locationUtil; - } - public OleDocstoreHelperService getOleDocstoreHelperService() { if(null == oleDocstoreHelperService) { oleDocstoreHelperService = SpringContext.getBean(OleDocstoreHelperService.class); @@ -314,4 +305,15 @@ public OleDocstoreHelperService getOleDocstoreHelperService() { public void setOleDocstoreHelperService(OleDocstoreHelperService oleDocstoreHelperService) { this.oleDocstoreHelperService = oleDocstoreHelperService; } + + public OleNGMemorizeService getOleNGMemorizeService() { + if(null == oleNGMemorizeService) { + oleNGMemorizeService = new OleNGMemorizeServiceImpl(); + } + return oleNGMemorizeService; + } + + public void setOleNGMemorizeService(OleNGMemorizeService oleNGMemorizeService) { + this.oleNGMemorizeService = oleNGMemorizeService; + } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/BatchDateTimeUtil.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/BatchDateTimeUtil.java new file mode 100644 index 0000000000..d56e6dc46b --- /dev/null +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/BatchDateTimeUtil.java @@ -0,0 +1,22 @@ +package org.kuali.ole.oleng.util; + +import org.kuali.rice.core.api.CoreApiServiceLocator; +import org.kuali.rice.core.impl.datetime.DateTimeServiceImpl; + +import java.text.ParseException; +import java.util.Date; + +/** + * Created by SheikS on 3/1/2016. + */ +public class BatchDateTimeUtil extends DateTimeServiceImpl { + + @Override + public Date convertToDate(String dateString) throws ParseException { + String[] strings = new String[3]; + strings[0] = "yyyyMMdd"; + strings[1] = "yyyyMM"; + strings[2] = "dd.MMM.yyyy"; + return parseAgainstFormatArray(dateString, strings); + } +} diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceRecordBuilderUtil.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceRecordBuilderUtil.java index 3863aec782..f5e1c90ce8 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceRecordBuilderUtil.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceRecordBuilderUtil.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.kuali.ole.OLEConstants; +import org.kuali.ole.constants.OleNGConstants; import org.kuali.ole.docstore.common.util.BusinessObjectServiceHelperUtil; import org.kuali.ole.pojo.OleInvoiceRecord; import org.kuali.ole.pojo.edi.*; @@ -17,7 +18,6 @@ import java.text.NumberFormat; import java.text.ParseException; import java.text.ParsePosition; -import java.text.SimpleDateFormat; import java.util.*; /** @@ -28,6 +28,7 @@ public class OleNGInvoiceRecordBuilderUtil extends BusinessObjectServiceHelperUt private static OleNGInvoiceRecordBuilderUtil oleNGInvoiceRecordBuilderUtil = null; private LookupService lookupService; + private BatchDateTimeUtil batchDateTimeUtil; public static OleNGInvoiceRecordBuilderUtil getInstance() { if (null == oleNGInvoiceRecordBuilderUtil) { @@ -540,51 +541,90 @@ private List getItemNote(LineItemOrder lineItemOrder) { } private String getSubscriptionDateFrom(LineItemOrder lineItemOrder) { - if (CollectionUtils.isNotEmpty(lineItemOrder.getDateTimeDetail())) { - DateTimeDetail dateTimeDetail = lineItemOrder.getDateTimeDetail().get(0); - if (CollectionUtils.isNotEmpty(dateTimeDetail.getDateTimeInformationList())) { - DateTimeInformation dateTimeInformation = dateTimeDetail.getDateTimeInformationList().get(0); - if (dateTimeInformation.getPeriod().length() == 8) { - return dateTimeInformation.getPeriod(); - } else { - return dateTimeInformation.getPeriod() + 01; + String subScriptionDate = getSubScriptionDateFromDateTimeDetails(lineItemOrder.getDateTimeDetail(), 0); + if(StringUtils.isBlank(subScriptionDate)) { + List itemDescriptionList = lineItemOrder.getItemDescriptionList(); + subScriptionDate = getSubScriptionDateFromDescription(itemDescriptionList, "085"); + } + if(StringUtils.isNotBlank(subScriptionDate)) { + try { + Date date = getBatchDateTimeUtil().convertToDate(subScriptionDate); + if(subScriptionDate.length() == 6) { + date = processDate(date, "from"); } + return OleNGConstants.DATE_FORMAT_WITHOUT_TIME.format(date); + } catch (ParseException e) { + e.printStackTrace(); } } return null; } - private int getLastDayOfMonth(String date) { - SimpleDateFormat dateFromRawFile = new SimpleDateFormat(org.kuali.ole.OLEConstants.DATE_FORMAT); - Date dt = null; - try { - dt = dateFromRawFile.parse(date); - } catch (ParseException e) { - LOG.error("Unable to parse Subscription End Date"); + private String getSubScriptionDateFromDateTimeDetails(List dateTimeDetails, int index) { + if(CollectionUtils.isNotEmpty(dateTimeDetails)) { + DateTimeDetail dateTimeDetail = dateTimeDetails.get(index); + if (null != dateTimeDetail) { + List dateTimeInformationList = dateTimeDetail.getDateTimeInformationList(); + if(CollectionUtils.isNotEmpty(dateTimeInformationList)) { + DateTimeInformation dateTimeInformation = dateTimeInformationList.get(0); + if(null != dateTimeInformation) { + return getDateString(dateTimeInformation.getPeriod()); + } + } + } + } + return null; + } + + private String getSubScriptionDateFromDescription(List itemDescriptionList, String code) { + if(CollectionUtils.isNotEmpty(itemDescriptionList)) { + for (Iterator iterator = itemDescriptionList.iterator(); iterator.hasNext(); ) { + ItemDescription itemDescription = iterator.next(); + String itemCharacteristicCode = itemDescription.getItemCharacteristicCode(); + if(StringUtils.equals(itemCharacteristicCode, code)) { + return getDateString(itemDescription.getData()); + } + } } + return null; + } + private Date processDate(Date date, String type) { Calendar calendar = Calendar.getInstance(); - calendar.setTime(dt); - calendar.add(Calendar.MONTH, 1); - calendar.set(Calendar.DAY_OF_MONTH, 1); - calendar.add(Calendar.DATE, -1); - Date lastDayOfMonth = calendar.getTime(); - int day = lastDayOfMonth.getDate(); - return day; + calendar.setTime(date); + if(StringUtils.equals(type, "from")) { + calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); + } else if(StringUtils.equals(type, "to")) { + calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); + } + return calendar.getTime(); } private String getSubscriptionDateTo(LineItemOrder lineItemOrder) { - if (CollectionUtils.isNotEmpty(lineItemOrder.getDateTimeDetail())) { - DateTimeDetail dateTimeDetail = lineItemOrder.getDateTimeDetail().get(1); - if (CollectionUtils.isNotEmpty(dateTimeDetail.getDateTimeInformationList())) { - DateTimeInformation dateTimeInformation = dateTimeDetail.getDateTimeInformationList().get(0); - if (dateTimeInformation.getPeriod().length() == 8) { - return dateTimeInformation.getPeriod(); - } else { - String subscriptionDate = dateTimeInformation.getPeriod() + "01"; - int day = getLastDayOfMonth(subscriptionDate); - return dateTimeInformation.getPeriod() + day; + String subScriptionDate = getSubScriptionDateFromDateTimeDetails(lineItemOrder.getDateTimeDetail(), 1); + if(StringUtils.isBlank(subScriptionDate)) { + List itemDescriptionList = lineItemOrder.getItemDescriptionList(); + subScriptionDate = getSubScriptionDateFromDescription(itemDescriptionList, "086"); + } + if(StringUtils.isNotBlank(subScriptionDate)) { + try { + Date date = getBatchDateTimeUtil().convertToDate(subScriptionDate); + if(subScriptionDate.length() == 6) { + date = processDate(date, "to"); } + return OleNGConstants.DATE_FORMAT_WITHOUT_TIME.format(date); + } catch (ParseException e) { + e.printStackTrace(); + } + } + return null; + } + + private String getDateString(String data) { + if(StringUtils.isNotBlank(data)) { + String[] split = data.split(" "); + if(null != split && split.length > 0) { + return split[0].replaceAll(":::",""); } } return null; @@ -629,4 +669,15 @@ private String getSubscriptionPeriod(LineItemOrder lineItemOrder) { } return subscriptionPeriod.toString(); } + + public BatchDateTimeUtil getBatchDateTimeUtil() { + if(null == batchDateTimeUtil) { + batchDateTimeUtil = new BatchDateTimeUtil(); + } + return batchDateTimeUtil; + } + + public void setBatchDateTimeUtil(BatchDateTimeUtil batchDateTimeUtil) { + this.batchDateTimeUtil = batchDateTimeUtil; + } } \ No newline at end of file diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java index 8d7b7dcf82..fdde058e9b 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGInvoiceValidationUtil.java @@ -3,9 +3,16 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.kuali.ole.Exchange; +import org.kuali.ole.coa.businessobject.Account; +import org.kuali.ole.coa.businessobject.ObjectCode; +import org.kuali.ole.coa.businessobject.OleFundCode; +import org.kuali.ole.oleng.dao.SelectDAO; +import org.kuali.ole.oleng.dao.impl.SelectDAOImpl; import org.kuali.ole.oleng.exception.ValidationException; import org.kuali.ole.pojo.OleInvoiceRecord; import org.kuali.ole.spring.batch.BatchUtil; +import org.kuali.ole.vnd.businessobject.OleCurrencyType; +import org.kuali.ole.vnd.businessobject.VendorDetail; /** * Created by SheikS on 3/31/2016. @@ -14,6 +21,8 @@ public class OleNGInvoiceValidationUtil { private BatchUtil batchUtil; + private SelectDAO selectDAO; + public boolean validateOleInvoiceRecord(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { boolean valid = true; valid = validateVendorNumber(oleInvoiceRecord, exchange, recordIndex) && valid; @@ -23,31 +32,45 @@ public boolean validateOleInvoiceRecord(OleInvoiceRecord oleInvoiceRecord, Excha valid = validateItemDescription(oleInvoiceRecord, exchange, recordIndex) && valid; valid = validateQuantity(oleInvoiceRecord, exchange, recordIndex) && valid; + validateAccountNumber(oleInvoiceRecord, exchange, recordIndex); + validateObjectCode(oleInvoiceRecord, exchange, recordIndex); + validateFundCode(oleInvoiceRecord, exchange, recordIndex); + validateCurrencyType(oleInvoiceRecord, exchange, recordIndex); + return valid; } private boolean validateInvoiceNumber(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { String invoiceNumber = oleInvoiceRecord.getInvoiceNumber(); - if (StringUtils.isBlank(invoiceNumber) || !NumberUtils.isDigits(invoiceNumber)){ - getBatchUtil().addOrderFaiureResponseToExchange( - new ValidationException("Invoice number cannot be blank or null and it should be round number"), recordIndex, exchange); + if (StringUtils.isBlank(invoiceNumber)){ + getBatchUtil().addInvoiceFaiureResponseToExchange( + new ValidationException("Invoice number cannot be blank or null"), recordIndex, exchange); return false; } return true; } private boolean validateVendorNumber(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { - if (StringUtils.isBlank(oleInvoiceRecord.getVendorNumber())){ - getBatchUtil().addOrderFaiureResponseToExchange( + String vendorNumber = oleInvoiceRecord.getVendorNumber(); + if (StringUtils.isBlank(vendorNumber)){ + getBatchUtil().addInvoiceFaiureResponseToExchange( new ValidationException("Vendor number cannot be blank or null"), recordIndex, exchange); return false; + } else { + VendorDetail vendorDetail = getSelectDAO().getVendorDetailByVendorNumber(vendorNumber); + if (null == vendorDetail) { + getBatchUtil().addInvoiceFaiureResponseToExchange( + new ValidationException("Invalid Vendor Number : " + vendorNumber), recordIndex, exchange); + oleInvoiceRecord.setVendorNumber(null); + return false; + } } return true; } private boolean validateInvoiceDate(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { if (StringUtils.isBlank(oleInvoiceRecord.getInvoiceDate())){ - getBatchUtil().addOrderFaiureResponseToExchange( + getBatchUtil().addInvoiceFaiureResponseToExchange( new ValidationException("Invoice date cannot be blank or null"), recordIndex, exchange); return false; } @@ -57,7 +80,7 @@ private boolean validateInvoiceDate(OleInvoiceRecord oleInvoiceRecord, Exchange private boolean validateInvoicePrice(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { String listPrice = oleInvoiceRecord.getListPrice(); if (null == listPrice || !NumberUtils.isNumber(listPrice)){ - getBatchUtil().addOrderFaiureResponseToExchange( + getBatchUtil().addInvoiceFaiureResponseToExchange( new ValidationException("List Price cannot be blank or null and it should be numeric"), recordIndex, exchange); return false; } @@ -66,7 +89,7 @@ private boolean validateInvoicePrice(OleInvoiceRecord oleInvoiceRecord, Exchange private boolean validateItemDescription(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { if (StringUtils.isBlank(oleInvoiceRecord.getItemDescription())){ - getBatchUtil().addOrderFaiureResponseToExchange( + getBatchUtil().addInvoiceFaiureResponseToExchange( new ValidationException("Item description cannot be blank or null"), recordIndex, exchange); return false; } @@ -76,13 +99,81 @@ private boolean validateItemDescription(OleInvoiceRecord oleInvoiceRecord, Excha private boolean validateQuantity(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { String quantity = oleInvoiceRecord.getQuantity(); if (null == quantity || !NumberUtils.isDigits(quantity)){ - getBatchUtil().addOrderFaiureResponseToExchange( + getBatchUtil().addInvoiceFaiureResponseToExchange( new ValidationException("Quantity cannot be blank or null and it should be round number"), recordIndex, exchange); return false; } return true; } + + private boolean validateAccountNumber(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { + String accountNumber = oleInvoiceRecord.getAccountNumber(); + if (StringUtils.isNotBlank(accountNumber)) { + Account account = getSelectDAO().getAccountByAccountNumber(accountNumber); + if (null == account) { + getBatchUtil().addInvoiceFaiureResponseToExchange( + new ValidationException("Invalid Account Number : " + accountNumber), recordIndex, exchange); + oleInvoiceRecord.setAccountNumber(null); + } else { + return true; + } + } + return false; + } + + private boolean validateFundCode(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { + String fundCode = oleInvoiceRecord.getFundCode(); + if (StringUtils.isNotBlank(fundCode)) { + OleFundCode oleFundCode = getSelectDAO().getOleFundCodeByCode(fundCode); + if (null == oleFundCode) { + getBatchUtil().addInvoiceFaiureResponseToExchange( + new ValidationException("Invalid Fund Code : " + fundCode), recordIndex, exchange); + oleInvoiceRecord.setFundCode(null); + } else { + return true; + } + } + return false; + } + + private boolean validateObjectCode(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { + String financialObjectCode = oleInvoiceRecord.getObjectCode(); + if (StringUtils.isNotBlank(financialObjectCode)) { + ObjectCode objectCode = getSelectDAO().getObjectCodeByCode(financialObjectCode); + if (null == objectCode) { + getBatchUtil().addInvoiceFaiureResponseToExchange( + new ValidationException("Invalid Object Code : " + financialObjectCode), recordIndex, exchange); + oleInvoiceRecord.setObjectCode(null); + } else { + return true; + } + } + return false; + } + + private boolean validateCurrencyType(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) { + String currencyType = oleInvoiceRecord.getCurrencyType(); + if (StringUtils.isNotBlank(currencyType)) { + OleCurrencyType oleCurrencyType = getSelectDAO().getCurrencyType(currencyType); + if (null == oleCurrencyType) { + getBatchUtil().addInvoiceFaiureResponseToExchange( + new ValidationException("Invalid Currency Type : " + currencyType), recordIndex, exchange); + oleInvoiceRecord.setObjectCode(null); + } else { + return true; + } + } + return false; + } + + public SelectDAO getSelectDAO() { + if (null == selectDAO) { + selectDAO = new SelectDAOImpl(); + } + return selectDAO; + } + public BatchUtil getBatchUtil() { if(null == batchUtil) { batchUtil = new BatchUtil(); diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGPOHelperUtil.java b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGPOHelperUtil.java index 37b509bd42..e5c3266570 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGPOHelperUtil.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/oleng/util/OleNGPOHelperUtil.java @@ -48,10 +48,13 @@ public static OleNGPOHelperUtil getInstance() { } public Map> processReqAndPo(List recordDetailsList, BatchProcessProfile batchProcessProfile, - CreateReqAndPOBaseServiceHandler createReqAndPOServiceHandler, Exchange exchange) { + CreateReqAndPOBaseServiceHandler createReqAndPOServiceHandler, + Exchange exchange) { Map> poIdsMap = new HashMap<>(); List oleOrderRecords = new ArrayList<>(); Integer purapId = null; + OrderImportService oleOrderImportService = getOleOrderImportService(); + oleOrderImportService.setOleNGMemorizeService(createReqAndPOServiceHandler.getOleNGMemorizeService()); for (Iterator iterator = recordDetailsList.iterator(); iterator.hasNext(); ) { RecordDetails recordDetails = iterator.next(); Integer recordIndex = recordDetails.getIndex(); 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 20ff2b707a..7223794ffd 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 @@ -42,6 +42,7 @@ public class BatchUtil extends OleNgUtil { private OleDsNgRestClient oleDsNgRestClient; SolrRequestReponseHandler solrRequestReponseHandler; private MarcRecordUtil marcRecordUtil; + public static Map BATCH_JOB_EXECUTION_DETAILS_MAP = new HashMap<>(); private MarcXMLConverter marcXMLConverter; public OleDsNgRestClient getOleDsNgRestClient() { @@ -465,6 +466,26 @@ public BatchProcessJob getBatchProcessJobById(Long jobId) { return getBusinessObjectService().findByPrimaryKey(BatchProcessJob.class, map); } + public BatchJobDetails getJobDetailsById(Long jobDetailsId) { + return getBusinessObjectService().findBySinglePrimaryKey(BatchJobDetails.class, jobDetailsId); + } + + public void deleteJobDetailsById(Long jobDetailsId) { + Map map = new HashedMap(); + map.put(OleNGConstants.JOB_DETAIL_ID, jobDetailsId); + getBusinessObjectService().deleteMatching(BatchJobDetails.class, map); + } + + public boolean isJobRunning(BatchJobDetails batchJobDetails) { + boolean running = false; + BatchJobDetails runningDetials = BATCH_JOB_EXECUTION_DETAILS_MAP.get(batchJobDetails.getJobId() + "_" + batchJobDetails.getJobDetailId()); + if(null != runningDetials) { + running = true; + } + return running; + + } + public int getBatchChunkSize() { String parameterValue = ParameterValueResolver.getInstance().getParameter(OLEConstants .APPL_ID_OLE, OLEConstants.DESC_NMSPC, OLEConstants.DESCRIBE_COMPONENT, OleNGConstants.CHUNK_SIZE_FOR_BATCH_PROCESSING); @@ -474,4 +495,4 @@ public int getBatchChunkSize() { return 1000; } -} \ No newline at end of file +} diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchFileProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchFileProcessor.java index c87111a281..8a35cdf200 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchFileProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchFileProcessor.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.IOException; +import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; @@ -59,6 +60,7 @@ public JSONObject processBatch(File inputFileDirectoryPath, String fileType, Str BatchProcessProfile batchProcessProfile = new BatchProcessProfile(); String responseData = ""; try { + BATCH_JOB_EXECUTION_DETAILS_MAP.put(batchJobDetails.getJobId() + "_" + batchJobDetails.getJobDetailId(), batchJobDetails); batchProcessProfile = fetchBatchProcessProfile(profileId); BatchProcessTxObject batchProcessTxObject = new BatchProcessTxObject(); batchProcessTxObject.setBatchProcessProfile(batchProcessProfile); @@ -77,13 +79,16 @@ public JSONObject processBatch(File inputFileDirectoryPath, String fileType, Str OleNgBatchResponse oleNgBatchResponse = processRecords(new HashMap(), batchProcessTxObject, batchProcessProfile); int noOfFailureRecord = oleNgBatchResponse.getNoOfFailureRecord(); batchJobDetails.setTotalFailureRecords(String.valueOf(noOfFailureRecord)); - updateBatchJobDetails(batchJobDetails,OleNGConstants.COMPLETED); - responseData = oleNgBatchResponse.getResponse(); - response.put(OleNGConstants.STATUS, true); OleStopWatch oleStopWatch = batchProcessTxObject.getOleStopWatch(); oleStopWatch.end(); String totalTimeTaken = String.valueOf(oleStopWatch.getTotalTime()) + "ms"; + batchJobDetails.setEndTime(new Timestamp(System.currentTimeMillis())); + batchJobDetails.setTimeSpent(totalTimeTaken); + updateBatchJobDetails(batchJobDetails,OleNGConstants.COMPLETED); + responseData = oleNgBatchResponse.getResponse(); + response.put(OleNGConstants.STATUS, true); writeBatchRunningStatusToFile(batchProcessTxObject.getIncomingFileDirectoryPath(), OleNGConstants.COMPLETED, totalTimeTaken); + BATCH_JOB_EXECUTION_DETAILS_MAP.remove(batchJobDetails.getJobId() + "_" + batchJobDetails.getJobDetailId()); } } catch (Exception e) { updateBatchJobDetails(batchJobDetails,OleNGConstants.FAILED); @@ -97,6 +102,7 @@ public JSONObject processBatch(File inputFileDirectoryPath, String fileType, Str batchProcessFailureResponse.setDirectoryName(reportDirectoryName); BatchBibFailureReportLogHandler batchBibFailureReportLogHandler = BatchBibFailureReportLogHandler.getInstance(); batchBibFailureReportLogHandler.logMessage(Collections.singletonList(batchProcessFailureResponse),reportDirectoryName); + BATCH_JOB_EXECUTION_DETAILS_MAP.remove(batchJobDetails.getJobId() + "_" + batchJobDetails.getJobDetailId()); throw e; } return response; diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchInvoiceImportProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchInvoiceImportProcessor.java index 5e6395227d..0bf3694063 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchInvoiceImportProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchInvoiceImportProcessor.java @@ -132,12 +132,15 @@ public OleNgBatchResponse processRecords(Map recordsMap, List invoiceFailureResponseList = (List) exchange.get(OleNGConstants.FAILURE_RESPONSE); oleNGInvoiceImportResponse.setInvoiceFailureResponses(invoiceFailureResponseList); + oleNGInvoiceImportResponse.setRecordsMap(recordsMap); oleNgBatchResponse.setNoOfFailureRecord(getFailureRecordsCount(invoiceFailureResponseList)); try { String successResponse = getObjectMapper().defaultPrettyPrintingWriter().writeValueAsString(oleNGInvoiceImportResponse); oleNGInvoiceImportResponse = mergeResponse(oleNGInvoiceImportResponse, exchange); + oleNGInvoiceImportResponse.setFileExtension(fileType); InvoiceImportLoghandler invoiceImportLoghandler = InvoiceImportLoghandler.getInstance(); invoiceImportLoghandler.logMessage(oleNGInvoiceImportResponse, reportDirectoryName); + clearMarcRecordObjects(oleNGInvoiceImportResponse); exchange.add(OleNGConstants.INVOICE_RESPONSE, oleNGInvoiceImportResponse); exchange.remove(OleNGConstants.FAILURE_RESPONSE); oleNgBatchResponse.setResponse(successResponse); @@ -205,77 +208,82 @@ private Map> prepareInvoiceRecordsForEdifact(Batc ArrayList datamappingTypes = new ArrayList<>(); datamappingTypes.add(OleNGConstants.CONSTANT); - for (Iterator iterator = invOrders.iterator(); iterator.hasNext(); ) { - INVOrder invOrder = iterator.next(); - List lineItemOrders = invOrder.getLineItemOrder(); - if (CollectionUtils.isNotEmpty(lineItemOrders)) { - for(int index = 0; index < lineItemOrders.size() ; index++) { - LineItemOrder lineItemOrder = lineItemOrders.get(index); - totalNoOfRecords++; - OleInvoiceRecord oleInvoiceRecord = null; - try { - oleInvoiceRecord = getOleNGInvoiceRecordBuilderUtil().build(lineItemOrder, invOrder); - oleInvoiceRecord = prepareInvoiceOrderRercordFromProfile(null, batchProcessProfile, oleInvoiceRecord, datamappingTypes); - String[] vendorIds = oleInvoiceRecord.getVendorNumber() != null ? oleInvoiceRecord.getVendorNumber().split("-") : new String[0]; - Map dbCriteria = new HashMap(); - List olePurchaseOrderItems = new ArrayList<>(); - if (StringUtils.isNotBlank(oleInvoiceRecord.getVendorItemIdentifier())) { - dbCriteria.put("vendorItemPoNumber", oleInvoiceRecord.getVendorItemIdentifier()); - dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); - dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); - oleInvoiceRecord.setMatchPointType(OleNGConstants.BatchProcess.VENDOR_ITEM_IDENTIFIER); - olePurchaseOrderItems = getPurchaseOrderItemsByCriteria(dbCriteria); - } + if (CollectionUtils.isNotEmpty(invOrders)) { + for (Iterator iterator = invOrders.iterator(); iterator.hasNext(); ) { + INVOrder invOrder = iterator.next(); + List lineItemOrders = invOrder.getLineItemOrder(); + if (CollectionUtils.isNotEmpty(lineItemOrders)) { + for(int index = 0; index < lineItemOrders.size() ; index++) { + LineItemOrder lineItemOrder = lineItemOrders.get(index); + totalNoOfRecords++; + OleInvoiceRecord oleInvoiceRecord = null; + try { + oleInvoiceRecord = getOleNGInvoiceRecordBuilderUtil().build(lineItemOrder, invOrder); + oleInvoiceRecord = prepareInvoiceOrderRercordFromProfile(null, batchProcessProfile, oleInvoiceRecord, datamappingTypes); + String[] vendorIds = oleInvoiceRecord.getVendorNumber() != null ? oleInvoiceRecord.getVendorNumber().split("-") : new String[0]; + List olePurchaseOrderItems = new ArrayList<>(); + if (oleInvoiceRecord.getVendorNumber() != null && vendorIds != null && vendorIds.length == 2 && StringUtils.isNotBlank(vendorIds[0]) && StringUtils.isNotBlank(vendorIds[1])) { + Map dbCriteria = new HashMap(); + olePurchaseOrderItems = new ArrayList<>(); + if (StringUtils.isNotBlank(oleInvoiceRecord.getVendorItemIdentifier())) { + dbCriteria.put("vendorItemPoNumber", oleInvoiceRecord.getVendorItemIdentifier()); + dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); + dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); + oleInvoiceRecord.setMatchPointType(OleNGConstants.BatchProcess.VENDOR_ITEM_IDENTIFIER); + olePurchaseOrderItems = getPurchaseOrderItemsByCriteria(dbCriteria); + } - if (CollectionUtils.isEmpty(olePurchaseOrderItems) && null != oleInvoiceRecord.getPurchaseOrderNumber() - &&oleInvoiceRecord.getPurchaseOrderNumber() != 0) { - dbCriteria.clear(); - oleInvoiceRecord.setMatchPointType(OleNGConstants.BatchProcess.PO_NUMBER); - dbCriteria.put("purchaseOrder.purapDocumentIdentifier", oleInvoiceRecord.getPurchaseOrderNumber()); - dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); - dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); - olePurchaseOrderItems = getPurchaseOrderItemsByCriteria(dbCriteria); - } + if (CollectionUtils.isEmpty(olePurchaseOrderItems) && null != oleInvoiceRecord.getPurchaseOrderNumber() + &&oleInvoiceRecord.getPurchaseOrderNumber() != 0) { + dbCriteria.clear(); + oleInvoiceRecord.setMatchPointType(OleNGConstants.BatchProcess.PO_NUMBER); + dbCriteria.put("purchaseOrder.purapDocumentIdentifier", oleInvoiceRecord.getPurchaseOrderNumber()); + dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); + dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); + olePurchaseOrderItems = getPurchaseOrderItemsByCriteria(dbCriteria); + } - else if (CollectionUtils.isEmpty(olePurchaseOrderItems) && - (StringUtils.isNotBlank(oleInvoiceRecord.getISSN()) || StringUtils.isNotBlank(oleInvoiceRecord.getISBN()))) { - List values = new ArrayList<>(); - values.add(oleInvoiceRecord.getISSN()); - values.add(oleInvoiceRecord.getISBN()); - Set itemTitleIds = getItemTitleId(values); - if(CollectionUtils.isNotEmpty(itemTitleIds)) { - for (Iterator stringIterator = itemTitleIds.iterator(); stringIterator.hasNext(); ) { - String itemTitleId = stringIterator.next(); - if(StringUtils.isNotBlank(itemTitleId)) { - dbCriteria.clear(); - dbCriteria.put("itemTitleId", itemTitleId); - dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); - dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); - olePurchaseOrderItems.addAll(getPurchaseOrderItemsByCriteria(dbCriteria)); + else if (CollectionUtils.isEmpty(olePurchaseOrderItems) && + (StringUtils.isNotBlank(oleInvoiceRecord.getISSN()) || StringUtils.isNotBlank(oleInvoiceRecord.getISBN()))) { + List values = new ArrayList<>(); + values.add(oleInvoiceRecord.getISSN()); + values.add(oleInvoiceRecord.getISBN()); + Set itemTitleIds = getItemTitleId(values); + if(CollectionUtils.isNotEmpty(itemTitleIds)) { + for (Iterator stringIterator = itemTitleIds.iterator(); stringIterator.hasNext(); ) { + String itemTitleId = stringIterator.next(); + if(StringUtils.isNotBlank(itemTitleId)) { + dbCriteria.clear(); + dbCriteria.put("itemTitleId", itemTitleId); + dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); + dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); + olePurchaseOrderItems.addAll(getPurchaseOrderItemsByCriteria(dbCriteria)); + } + } + } + + Set poDocumentNumbers = new HashSet<>(); + if(CollectionUtils.isNotEmpty(olePurchaseOrderItems)) { + for (Iterator iterator1 = olePurchaseOrderItems.iterator(); iterator1.hasNext(); ) { + OlePurchaseOrderItem olePurchaseOrderItem = iterator1.next(); + String documentNumber = olePurchaseOrderItem.getPurchaseOrder().getDocumentNumber(); + poDocumentNumbers.add(documentNumber); + } } - } - } - Set poDocumentNumbers = new HashSet<>(); - if(CollectionUtils.isNotEmpty(olePurchaseOrderItems)) { - for (Iterator iterator1 = olePurchaseOrderItems.iterator(); iterator1.hasNext(); ) { - OlePurchaseOrderItem olePurchaseOrderItem = iterator1.next(); - String documentNumber = olePurchaseOrderItem.getPurchaseOrder().getDocumentNumber(); - poDocumentNumbers.add(documentNumber); + if(poDocumentNumbers.size() > 1) { + olePurchaseOrderItems.clear(); + } } } + oleInvoiceRecord.setRecordIndex(totalNoOfRecords); + setLinkedOrUnlinked(oleInvoiceRecord, olePurchaseOrderItems, matchedDetails); - if(poDocumentNumbers.size() > 1) { - olePurchaseOrderItems.clear(); - } + addInvoiceRecordToMap(oleInvoiceRecordMap, oleInvoiceRecord, exchange); + } catch (Exception e) { + e.printStackTrace(); + addInvoiceFaiureResponseToExchange(e, totalNoOfRecords, exchange); } - oleInvoiceRecord.setRecordIndex(totalNoOfRecords); - setLinkedOrUnlinked(oleInvoiceRecord, olePurchaseOrderItems, matchedDetails); - - addInvoiceRecordToMap(oleInvoiceRecordMap, oleInvoiceRecord, exchange); - } catch (Exception e) { - e.printStackTrace(); - addInvoiceFaiureResponseToExchange(e, totalNoOfRecords, exchange); } } } @@ -366,27 +374,29 @@ private List processMatchpoint(Record record, BatchProcess if(StringUtils.isNotBlank(oleInvoiceRecord.getVendorNumber())) { String[] vendorIds = oleInvoiceRecord.getVendorNumber() != null ? oleInvoiceRecord.getVendorNumber().split("-") : new String[0]; - for (Iterator iterator = criteriaMapForMatchPoint.keySet().iterator(); iterator.hasNext(); ) { - String key = iterator.next(); - Map dbCriteria = new HashMap(); - dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); - dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); - String dbCriteriaKey = ""; - if (key.equalsIgnoreCase(OleNGConstants.BatchProcess.VENDOR_ITEM_IDENTIFIER)) { - dbCriteriaKey = "vendorItemPoNumber"; - } else if (key.equalsIgnoreCase(OleNGConstants.BatchProcess.PO_NUMBER)) { - dbCriteriaKey = "purchaseOrder.purapDocumentIdentifier"; - } + if (vendorIds != null && vendorIds.length == 2 && StringUtils.isNotBlank(vendorIds[0]) && StringUtils.isNotBlank(vendorIds[1])) { + for (Iterator iterator = criteriaMapForMatchPoint.keySet().iterator(); iterator.hasNext(); ) { + String key = iterator.next(); + Map dbCriteria = new HashMap(); + dbCriteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier", vendorIds.length > 0 ? vendorIds[0] : ""); + dbCriteria.put("purchaseOrder.vendorDetailAssignedIdentifier", vendorIds.length > 1 ? vendorIds[1] : ""); + String dbCriteriaKey = ""; + if (key.equalsIgnoreCase(OleNGConstants.BatchProcess.VENDOR_ITEM_IDENTIFIER)) { + dbCriteriaKey = "vendorItemPoNumber"; + } else if (key.equalsIgnoreCase(OleNGConstants.BatchProcess.PO_NUMBER)) { + dbCriteriaKey = "purchaseOrder.purapDocumentIdentifier"; + } - List values = criteriaMapForMatchPoint.get(key); - for (Iterator matchPointIterator = values.iterator(); matchPointIterator.hasNext(); ) { - String value = matchPointIterator.next(); - if (StringUtils.isNotBlank(value)) { - dbCriteria.put(dbCriteriaKey, value); - List matching = getPurchaseOrderItemsByCriteria(dbCriteria); - if (CollectionUtils.isNotEmpty(matching)) { - oleInvoiceRecord.setMatchPointType(key); - return matching; + List values = criteriaMapForMatchPoint.get(key); + for (Iterator matchPointIterator = values.iterator(); matchPointIterator.hasNext(); ) { + String value = matchPointIterator.next(); + if (StringUtils.isNotBlank(value)) { + dbCriteria.put(dbCriteriaKey, value); + List matching = getPurchaseOrderItemsByCriteria(dbCriteria); + if (CollectionUtils.isNotEmpty(matching)) { + oleInvoiceRecord.setMatchPointType(key); + return matching; + } } } } @@ -575,7 +585,7 @@ public void setOleNGInvoiceValidationUtil(OleNGInvoiceValidationUtil oleNGInvoic } private OleNGInvoiceImportResponse mergeResponse(OleNGInvoiceImportResponse newOleNGInvoiceImportResponse, org.kuali.ole.Exchange exchange) { - OleNGInvoiceImportResponse oldResponseObject = (OleNGInvoiceImportResponse) exchange.get(OleNGConstants.ORDER_RESPONSE); + OleNGInvoiceImportResponse oldResponseObject = (OleNGInvoiceImportResponse) exchange.get(OleNGConstants.INVOICE_RESPONSE); if(null == oldResponseObject) { return newOleNGInvoiceImportResponse; } @@ -586,6 +596,8 @@ private OleNGInvoiceImportResponse mergeBibImportResponse(OleNGInvoiceImportResp oldOleNGInvoiceImportResponse.getInvoiceResponses().addAll(newOleNGInvoiceImportResponse.getInvoiceResponses()); oldOleNGInvoiceImportResponse.getInvoiceFailureResponses().addAll(newOleNGInvoiceImportResponse.getInvoiceFailureResponses()); + oldOleNGInvoiceImportResponse.setRecordsMap(newOleNGInvoiceImportResponse.getRecordsMap()); + oldOleNGInvoiceImportResponse.setMatchedCount(oldOleNGInvoiceImportResponse.getMatchedCount() + newOleNGInvoiceImportResponse.getMatchedCount()); oldOleNGInvoiceImportResponse.setUnmatchedCount(oldOleNGInvoiceImportResponse.getUnmatchedCount() + newOleNGInvoiceImportResponse.getUnmatchedCount()); oldOleNGInvoiceImportResponse.setMultiMatchedCount(oldOleNGInvoiceImportResponse.getMultiMatchedCount() + newOleNGInvoiceImportResponse.getMultiMatchedCount()); @@ -593,6 +605,10 @@ private OleNGInvoiceImportResponse mergeBibImportResponse(OleNGInvoiceImportResp return oldOleNGInvoiceImportResponse; } + private void clearMarcRecordObjects(OleNGInvoiceImportResponse oleNGInvoiceImportResponse) { + oleNGInvoiceImportResponse.getRecordsMap().clear(); + } + class MatchedDetails { private int matchedCount; private int unmatchedCount; diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchOrderImportProcessor.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchOrderImportProcessor.java index f591a38919..2685da63e4 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchOrderImportProcessor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/BatchOrderImportProcessor.java @@ -25,6 +25,7 @@ import org.kuali.ole.oleng.resolvers.CreateRequisitionAndPurchaseOrderHander; import org.kuali.ole.oleng.resolvers.CreateRequisitionOnlyHander; import org.kuali.ole.oleng.resolvers.OrderProcessHandler; +import org.kuali.ole.oleng.service.OleNGMemorizeService; import org.kuali.ole.oleng.service.OleNGRequisitionService; import org.kuali.ole.utility.BibUtil; import org.kuali.rice.core.api.config.property.ConfigContext; @@ -46,10 +47,12 @@ public class BatchOrderImportProcessor extends BatchFileProcessor { @Autowired private DescribeDAO describeDAO; - @Autowired OleNGRequisitionService oleNGRequisitionService; + @Autowired + OleNGMemorizeService oleNGMemorizeService; + @Autowired private BatchBibFileProcessor batchBibFileProcessor; private List orderProcessHandlers; @@ -157,7 +160,7 @@ public OleNgBatchResponse processRecords(Map recordsMap, orderDatasToReport = unmatchedOrderDatas; } if (recordsToProcess.size() > 0) { - poIdsMap.putAll(orderProcessHandler.processOrder(recordsToProcess, batchProcessProfile, exchange)); + poIdsMap.putAll(orderProcessHandler.processOrder(recordsToProcess, batchProcessProfile,oleNGMemorizeService, exchange)); prepareResponse(batchProfileAddOrOverlay.getAddOperation(), orderDatasToReport, oleNGOrderImportResponse, poIdsMap); } break; diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/MarcStreamingProcesssor.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/MarcStreamingProcesssor.java index e29fbc63b7..6a0ffc87e4 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/MarcStreamingProcesssor.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/MarcStreamingProcesssor.java @@ -8,6 +8,7 @@ import org.kuali.ole.docstore.common.pojo.RecordDetails; import org.kuali.ole.docstore.common.response.BatchProcessFailureResponse; import org.kuali.ole.docstore.common.response.OleNgBatchResponse; +import org.kuali.ole.oleng.batch.process.model.BatchJobDetails; import org.kuali.ole.oleng.batch.process.model.BatchProcessTxObject; import org.kuali.ole.oleng.batch.profile.model.BatchProcessProfile; import org.kuali.ole.spring.batch.BatchUtil; @@ -43,33 +44,41 @@ public MarcStreamingProcesssor(BatchProcessTxObject batchProcessTxObject, UserSe @Override public void process(Exchange exchange) throws Exception { BatchProcessProfile batchProcessProfile = batchProcessTxObject.getBatchProcessProfile(); - try { - logger.info("MarcStreamingProcesssor --> process() for batch : " + batchCount); - GlobalVariables.setUserSession(userSession); - batchCount++; - StringBuilder stringBuilder = new StringBuilder(); + BatchJobDetails batchJobDetails = batchProcessTxObject.getBatchJobDetails(); + if(null != batchJobDetails) { + boolean jobRunning = getBatchUtil().isJobRunning(batchJobDetails); + if(jobRunning) { + try { + logger.info("MarcStreamingProcesssor --> process() for batch : " + batchCount); + GlobalVariables.setUserSession(userSession); + batchCount++; + StringBuilder stringBuilder = new StringBuilder(); - if (exchange.getIn().getBody() instanceof List) { - for (String content : (List) exchange.getIn().getBody()) { - stringBuilder.append(content); - stringBuilder.append(OleNGConstants.MARC_SPLIT); + if (exchange.getIn().getBody() instanceof List) { + for (String content : (List) exchange.getIn().getBody()) { + stringBuilder.append(content); + stringBuilder.append(OleNGConstants.MARC_SPLIT); + } + } + Map recordDetailsMap = getRecordDetailsMap(stringBuilder.toString()); + batchProcessTxObject.setTotalNumberOfRecords(batchProcessTxObject.getTotalNumberOfRecords() + recordDetailsMap.size()); + OleNgBatchResponse oleNgBatchResponse = batchProcessTxObject.getBatchFileProcessor().processRecords(recordDetailsMap, batchProcessTxObject, + batchProcessProfile); + batchProcessTxObject.setNumberOfFailurRecords(batchProcessTxObject.getNumberOfFailurRecords() + oleNgBatchResponse.getNoOfFailureRecord()); + } catch (Exception e) { + e.printStackTrace(); + exchange.setException(e); + batchProcessTxObject.setExceptionCaught(true); + BatchProcessFailureResponse batchProcessFailureResponse = new BatchProcessFailureResponse(); + batchProcessFailureResponse.setBatchProcessProfileName(batchProcessProfile.getBatchProcessProfileName()); + batchProcessFailureResponse.setFailureReason(e.toString()); + batchProcessFailureResponse.setDetailedMessage(getBatchUtil().getDetailedMessage(e)); + batchProcessTxObject.getBatchProcessFailureResponses().add(batchProcessFailureResponse); + throw e; } + } else { + batchProcessTxObject.setStopped(true); } - Map recordDetailsMap = getRecordDetailsMap(stringBuilder.toString()); - batchProcessTxObject.setTotalNumberOfRecords(batchProcessTxObject.getTotalNumberOfRecords() + recordDetailsMap.size()); - OleNgBatchResponse oleNgBatchResponse = batchProcessTxObject.getBatchFileProcessor().processRecords(recordDetailsMap, batchProcessTxObject, - batchProcessProfile); - batchProcessTxObject.setNumberOfFailurRecords(batchProcessTxObject.getNumberOfFailurRecords() + oleNgBatchResponse.getNoOfFailureRecord()); - } catch (Exception e) { - e.printStackTrace(); - exchange.setException(e); - batchProcessTxObject.setExceptionCaught(true); - BatchProcessFailureResponse batchProcessFailureResponse = new BatchProcessFailureResponse(); - batchProcessFailureResponse.setBatchProcessProfileName(batchProcessProfile.getBatchProcessProfileName()); - batchProcessFailureResponse.setFailureReason(e.toString()); - batchProcessFailureResponse.setDetailedMessage(getBatchUtil().getDetailedMessage(e)); - batchProcessTxObject.getBatchProcessFailureResponses().add(batchProcessFailureResponse); - throw e; } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/OleNGBatchCamelSplitter.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/OleNGBatchCamelSplitter.java index bbf389db9d..b5ec2b7750 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/OleNGBatchCamelSplitter.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/processor/OleNGBatchCamelSplitter.java @@ -42,26 +42,32 @@ protected void doCustomProcessAfterSplit(Exchange exchange) { if(null != batchProcessTxObject) { BatchJobDetails batchJobDetails = batchProcessTxObject.getBatchJobDetails(); if(null != batchJobDetails) { - batchProcessTxObject.getOleStopWatch().end(); - String timeSpent = String.valueOf(batchProcessTxObject.getOleStopWatch().getTotalTime()) + "ms"; - batchJobDetails.setTimeSpent(timeSpent); - batchJobDetails.setEndTime(new Timestamp(System.currentTimeMillis())); - batchJobDetails.setTotalRecords(String.valueOf(batchProcessTxObject.getTotalNumberOfRecords())); - batchJobDetails.setTotalFailureRecords(String.valueOf(batchProcessTxObject.getNumberOfFailurRecords())); - if(batchProcessTxObject.isExceptionCaught()) { - batchJobDetails.setStatus(OleNGConstants.FAILED); - try { - BatchBibFailureReportLogHandler batchBibFailureReportLogHandler = BatchBibFailureReportLogHandler.getInstance(); - batchBibFailureReportLogHandler.logMessage(batchProcessTxObject.getBatchProcessFailureResponses(),batchProcessTxObject.getReportDirectoryName()); - } catch (Exception e) { - e.printStackTrace(); + try { + batchProcessTxObject.getOleStopWatch().end(); + String timeSpent = String.valueOf(batchProcessTxObject.getOleStopWatch().getTotalTime()) + "ms"; + batchJobDetails.setTimeSpent(timeSpent); + batchJobDetails.setEndTime(new Timestamp(System.currentTimeMillis())); + batchJobDetails.setTotalRecords(String.valueOf(batchProcessTxObject.getTotalNumberOfRecords())); + batchJobDetails.setTotalFailureRecords(String.valueOf(batchProcessTxObject.getNumberOfFailurRecords())); + if(batchProcessTxObject.isExceptionCaught()) { + batchJobDetails.setStatus(OleNGConstants.FAILED); + try { + BatchBibFailureReportLogHandler batchBibFailureReportLogHandler = BatchBibFailureReportLogHandler.getInstance(); + batchBibFailureReportLogHandler.logMessage(batchProcessTxObject.getBatchProcessFailureResponses(),batchProcessTxObject.getReportDirectoryName()); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + batchJobDetails.setStatus(OleNGConstants.COMPLETED); } - } else { - batchJobDetails.setStatus(OleNGConstants.COMPLETED); - } - getBatchUtil().writeBatchRunningStatusToFile(batchProcessTxObject.getIncomingFileDirectoryPath(), batchJobDetails.getStatus(), timeSpent); - if(batchJobDetails.getJobId() != 0 && batchJobDetails.getJobDetailId() != 0) { - KRADServiceLocator.getBusinessObjectService().save(batchJobDetails); + getBatchUtil().writeBatchRunningStatusToFile(batchProcessTxObject.getIncomingFileDirectoryPath(), batchJobDetails.getStatus(), timeSpent); + if(!batchProcessTxObject.isStopped() && batchJobDetails.getJobId() != 0 && batchJobDetails.getJobDetailId() != 0) { + KRADServiceLocator.getBusinessObjectService().save(batchJobDetails); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + getBatchUtil().BATCH_JOB_EXECUTION_DETAILS_MAP.remove(batchJobDetails.getJobId() + "_" + batchJobDetails.getJobDetailId()); } } } diff --git a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/rest/controller/BatchRestController.java b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/rest/controller/BatchRestController.java index f042482274..874f9d0e26 100644 --- a/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/rest/controller/BatchRestController.java +++ b/ole-app/olefs/src/main/java/org/kuali/ole/spring/batch/rest/controller/BatchRestController.java @@ -64,7 +64,7 @@ public class BatchRestController extends OleNgControllerBase { public String UploadFile(@RequestParam("file") MultipartFile file, @RequestParam("profileName") String profileName, @RequestParam("batchType") String batchType, HttpServletRequest request) throws Exception { if (null != file && StringUtils.isNotBlank(profileName) && StringUtils.isNotBlank(batchType)) { - File uploadedDirectory = storeUploadedFileToFileSystem(file); + File uploadedDirectory = storeUploadedFileToFileSystem(file, null); if(null != uploadedDirectory) { String originalFilename = file.getOriginalFilename(); String extension = FilenameUtils.getExtension(originalFilename); @@ -149,8 +149,8 @@ public String quickLaunchJob(@RequestParam("jobId") String jobId, @RequestParam( BatchJobDetails batchJobDetails = null; try { BatchProcessJob matchedBatchJob = getBatchUtil().getBatchProcessJobById(Long.valueOf(jobId)); - if (null != file) { - File uploadedDirectory = storeUploadedFileToFileSystem(file); + if (null != file && null != matchedBatchJob) { + File uploadedDirectory = storeUploadedFileToFileSystem(file, matchedBatchJob.getJobId()); if(null != uploadedDirectory) { String originalFilename = file.getOriginalFilename(); batchJobDetails = getBatchUtil().createBatchJobDetailsEntry(matchedBatchJob, originalFilename); @@ -170,10 +170,14 @@ public String quickLaunchJob(@RequestParam("jobId") String jobId, @RequestParam( return ""; } - private File storeUploadedFileToFileSystem(MultipartFile file) throws IOException { + private File storeUploadedFileToFileSystem(MultipartFile file, Long jobId) throws IOException { String batchUploadLocation = getBatchUploadLocation(); if(StringUtils.isNotBlank(batchUploadLocation)) { - batchUploadLocation = batchUploadLocation + File.separator + OleNGConstants.DATE_FORMAT.format(new Date()); + if (null != jobId && jobId != 0 ) { + batchUploadLocation = batchUploadLocation + File.separator + jobId + "_" + OleNGConstants.DATE_FORMAT.format(new Date()); + } else { + batchUploadLocation = batchUploadLocation + File.separator+ OleNGConstants.DATE_FORMAT.format(new Date()); + } File uploadDirectory = new File(batchUploadLocation); if (!uploadDirectory.exists() || !uploadDirectory.isDirectory()) { uploadDirectory.mkdirs(); @@ -236,6 +240,57 @@ public String scheduleJob(@RequestParam("jobId") String jobId, @RequestParam("fi return jsonObject.toString(); } + @RequestMapping(method = RequestMethod.GET, value = "/job/pauseJob", produces = {MediaType. APPLICATION_JSON + OleNGConstants.CHARSET_UTF_8}) + @ResponseBody + public String pauseJob(@RequestParam("jobId") long jobId) { + JSONObject jsonObject = new JSONObject(); + try { + BatchProcessJob matchedBatchJob = getBatchUtil().getBatchProcessJobById(jobId); + if (null != matchedBatchJob) { + oleNGBatchJobScheduler.pauseJob(String.valueOf(jobId)); + matchedBatchJob.setJobType(OleNGConstants.PAUSED); + getBusinessObjectService().save(matchedBatchJob); + jsonObject.put(OleNGConstants.JOB_ID, matchedBatchJob.getJobId()); + jsonObject.put(OleNGConstants.JOB_TYPE, matchedBatchJob.getJobType()); + jsonObject.put(OleNGConstants.CRON_EXPRESSION, matchedBatchJob.getCronExpression()); + jsonObject.put(OleNGConstants.NEXT_RUN_TIME, matchedBatchJob.getNextRunTime()); + } + } catch (Exception e) { + e.printStackTrace(); + } + return jsonObject.toString(); + } + + @RequestMapping(method = RequestMethod.GET, value = "/job/resumeJob", produces = {MediaType. APPLICATION_JSON + OleNGConstants.CHARSET_UTF_8}) + @ResponseBody + public String resumeJob(@RequestParam("jobId") long jobId) { + JSONObject jsonObject = new JSONObject(); + try { + BatchProcessJob matchedBatchJob = getBatchUtil().getBatchProcessJobById(jobId); + if (null != matchedBatchJob) { + CronExpression cron = new CronExpression(matchedBatchJob.getCronExpression()); + Date date = cron.getNextValidTimeAfter(new Date()); + if (date != null) { + matchedBatchJob.setNextRunTime(new Timestamp(date.getTime())); + oleNGBatchJobScheduler.resumeJob(String.valueOf(jobId)); + matchedBatchJob.setJobType(OleNGConstants.SCHEDULED); + } else { + matchedBatchJob.setNextRunTime(null); + matchedBatchJob.setCronExpression(null); + matchedBatchJob.setJobType(OleNGConstants.ADHOC); + } + getBusinessObjectService().save(matchedBatchJob); + jsonObject.put(OleNGConstants.JOB_ID, matchedBatchJob.getJobId()); + jsonObject.put(OleNGConstants.JOB_TYPE, matchedBatchJob.getJobType()); + jsonObject.put(OleNGConstants.CRON_EXPRESSION, matchedBatchJob.getCronExpression()); + jsonObject.put(OleNGConstants.NEXT_RUN_TIME, matchedBatchJob.getNextRunTime()); + } + } catch (Exception e) { + e.printStackTrace(); + } + return jsonObject.toString(); + } + @RequestMapping(method = RequestMethod.GET, value = "/job/unShedule", produces = {MediaType. APPLICATION_JSON + OleNGConstants.CHARSET_UTF_8}) @ResponseBody public String unShedule(@RequestParam("jobId") long jobId) { @@ -246,10 +301,12 @@ public String unShedule(@RequestParam("jobId") long jobId) { oleNGBatchJobScheduler.unScheduleJob(String.valueOf(jobId), true); matchedBatchJob.setJobType(OleNGConstants.ADHOC); matchedBatchJob.setCronExpression(null); + matchedBatchJob.setNextRunTime(null); getBusinessObjectService().save(matchedBatchJob); jsonObject.put(OleNGConstants.JOB_ID, matchedBatchJob.getJobId()); jsonObject.put(OleNGConstants.JOB_TYPE, matchedBatchJob.getJobType()); jsonObject.put(OleNGConstants.CRON_EXPRESSION, matchedBatchJob.getCronExpression()); + jsonObject.put(OleNGConstants.NEXT_RUN_TIME, matchedBatchJob.getNextRunTime()); } } catch (Exception e) { e.printStackTrace(); @@ -448,6 +505,41 @@ public String getBatchStatus(@RequestParam("filePathName") String filePathName) return response.toString(); } + @RequestMapping(method = RequestMethod.GET, value = "job/deleteJobExecution", produces = {MediaType. APPLICATION_JSON + OleNGConstants.CHARSET_UTF_8}) + @ResponseBody + public String deleteJobExecution(@RequestParam("jobDetailsId") String jobDetailsId) { + JSONObject response = new JSONObject(); + try { + getBatchUtil().deleteJobDetailsById(Long.valueOf(jobDetailsId)); + String reportDirectory = ConfigContext.getCurrentContextConfig().getProperty("report.directory"); + File file = new File(reportDirectory, jobDetailsId); + if(file.exists() && file.isDirectory()) { + FileUtils.deleteDirectory(file); + } + } catch (Exception e) { + e.printStackTrace(); + } + return response.toString(); + } + + @RequestMapping(method = RequestMethod.GET, value = "job/stopJobExecution", produces = {MediaType. APPLICATION_JSON + OleNGConstants.CHARSET_UTF_8}) + @ResponseBody + public String stopJobExecution(@RequestParam("jobDetailsId") String jobDetailsId) { + JSONObject response = new JSONObject(); + try { + BatchJobDetails batchJobDetails = getBatchUtil().getJobDetailsById(Long.valueOf(jobDetailsId)); + if(null != batchJobDetails) { + getBatchUtil().BATCH_JOB_EXECUTION_DETAILS_MAP.remove(batchJobDetails.getJobId() + "_" + batchJobDetails.getJobDetailId()); + batchJobDetails.setStatus(OleNGConstants.STOPPED); + getBusinessObjectService().save(batchJobDetails); + response.put(OleNGConstants.STATUS, batchJobDetails.getStatus()); + } + } catch (Exception e) { + e.printStackTrace(); + } + return response.toString(); + } + public BatchProcessJob convertJsonToProcessJob(String processJsonString) throws JSONException, IOException { getObjectMapper().setVisibilityChecker(getObjectMapper().getVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY)); BatchProcessJob batchProcessJob = getObjectMapper().readValue(processJsonString, BatchProcessJob.class); @@ -491,19 +583,6 @@ private File getDirectoryPath(long jobId) { return schedulerFileUploadLocation; } - - private String getJobDirectoryName(String profileType) { - String jobDirectoryName = null; - if (StringUtils.equalsIgnoreCase("Bib Import", profileType)) { - jobDirectoryName = "batchBibImport"; - } else if (StringUtils.equalsIgnoreCase("Invoice Import", profileType)) { - jobDirectoryName = "batchInvoice"; - } else if (StringUtils.equalsIgnoreCase("Order Record Import", profileType)) { - jobDirectoryName = "batchOrderRecord"; - } - return jobDirectoryName; - } - public BatchExcelReportUtil getBatchExcelReportUtil() { if(null == batchExcelReportUtil) { batchExcelReportUtil = new BatchExcelReportUtil(); diff --git a/ole-app/olefs/src/main/resources/org/kuali/ole/describe/ojb-describe.xml b/ole-app/olefs/src/main/resources/org/kuali/ole/describe/ojb-describe.xml index 8dc28ea3ad..d5af1fe137 100644 --- a/ole-app/olefs/src/main/resources/org/kuali/ole/describe/ojb-describe.xml +++ b/ole-app/olefs/src/main/resources/org/kuali/ole/describe/ojb-describe.xml @@ -553,7 +553,7 @@ + auto-retrieve="true" auto-update="object" auto-delete="none" proxy="false" orderby="jobId" sort="DESC"> diff --git a/ole-app/olefs/src/main/resources/org/kuali/ole/olefs-config-defaults.xml b/ole-app/olefs/src/main/resources/org/kuali/ole/olefs-config-defaults.xml index 1846688a8c..b8c07c9721 100644 --- a/ole-app/olefs/src/main/resources/org/kuali/ole/olefs-config-defaults.xml +++ b/ole-app/olefs/src/main/resources/org/kuali/ole/olefs-config-defaults.xml @@ -498,7 +498,8 @@ ${project.home}/reports - ${project.home}/batchUploadLocation + ${project.home}/batch/batchUploadLocation + ${project.home}/batch/schedulerUploadLocation 10001 diff --git a/ole-app/olefs/src/main/webapp/WEB-INF/rest-servlet.xml b/ole-app/olefs/src/main/webapp/WEB-INF/rest-servlet.xml index 88defcfa6a..2a172d3969 100644 --- a/ole-app/olefs/src/main/webapp/WEB-INF/rest-servlet.xml +++ b/ole-app/olefs/src/main/webapp/WEB-INF/rest-servlet.xml @@ -3,12 +3,17 @@ xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" + xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc - http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> + http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd + http://www.springframework.org/schema/aop + http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ole-app/olefs/src/main/webapp/batchScheduling/controllers/batchProcessJobsController.js b/ole-app/olefs/src/main/webapp/batchScheduling/controllers/batchProcessJobsController.js index a0058db436..84c8c87945 100644 --- a/ole-app/olefs/src/main/webapp/batchScheduling/controllers/batchProcessJobsController.js +++ b/ole-app/olefs/src/main/webapp/batchScheduling/controllers/batchProcessJobsController.js @@ -282,6 +282,33 @@ batchProcessJobsApp.controller('batchProcessJobsController', ['$scope', '$http', var batchProcessJob = $scope.batchProcessJobs[index]; batchProcessJob["jobType"] = data["jobType"]; batchProcessJob["cronExpression"] = data["cronExpression"]; + batchProcessJob["nextRunTime"] = data["nextRunTime"]; + $scope.batchProcessJobs[index] = batchProcessJob; + $scope.message = "Job Unscheduled"; + }); + }; + + $scope.pauseJob = function(index,jobId) { + var jobIdToPause = Number(jobId); + doGetRequest($scope, $http, OLENG_CONSTANTS.PAUSE_JOB, {"jobId": jobIdToPause}, function(response) { + var data = response.data; + var batchProcessJob = $scope.batchProcessJobs[index]; + batchProcessJob["jobType"] = data["jobType"]; + batchProcessJob["cronExpression"] = data["cronExpression"]; + batchProcessJob["nextRunTime"] = data["nextRunTime"]; + $scope.batchProcessJobs[index] = batchProcessJob; + $scope.message = "Job Unscheduled"; + }); + }; + + $scope.resumeJob = function(index,jobId) { + var jobIdToResume = Number(jobId); + doGetRequest($scope, $http, OLENG_CONSTANTS.RESUME_JOB, {"jobId": jobIdToResume}, function(response) { + var data = response.data; + var batchProcessJob = $scope.batchProcessJobs[index]; + batchProcessJob["jobType"] = data["jobType"]; + batchProcessJob["cronExpression"] = data["cronExpression"]; + batchProcessJob["nextRunTime"] = data["nextRunTime"]; $scope.batchProcessJobs[index] = batchProcessJob; $scope.message = "Job Unscheduled"; }); @@ -404,4 +431,23 @@ batchProcessJobsApp.controller('batchProcessJobsController', ['$scope', '$http', return false; }; + + + $scope.deleteJobDetails = function(index, jobExecutionId) { + var jobDetailsId = Number(jobExecutionId); + doGetRequest($scope, $http, OLENG_CONSTANTS.DELETE_JOB_EXECUTION, {"jobDetailsId": jobDetailsId}, function(response) { + $scope.batchJobs.splice(index, 1); + }); + }; + + $scope.stopJobExecution = function(index, jobExecutionId) { + var jobDetailsId = Number(jobExecutionId); + doGetRequest($scope, $http, OLENG_CONSTANTS.STOP_JOB_EXECUTION, {"jobDetailsId": jobDetailsId}, function(response) { + var data = response.data; + var batchJob = $scope.batchJobs[index]; + batchJob["status"] = data["status"]; + $scope.batchJobs[index] = batchJob; + }); + }; + }]); \ No newline at end of file diff --git a/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobExecutions.html b/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobExecutions.html index 96c1331ccf..6c005ff426 100644 --- a/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobExecutions.html +++ b/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobExecutions.html @@ -40,22 +40,12 @@ - - - - diff --git a/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobs.html b/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobs.html index 55059369e6..98b7d4c384 100644 --- a/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobs.html +++ b/ole-app/olefs/src/main/webapp/batchScheduling/views/batchJobs.html @@ -12,6 +12,7 @@ Created On Next Run Time Cron Expression + Job Status Execution Count Last Execution Status Actions @@ -27,6 +28,7 @@ + @@ -37,10 +39,18 @@ name="processSchedule_{{$index}}" ng-click="schedulePopUp($index, batchProcessJob.jobId)" ng-show="batchProcessJob.jobType === 'Adhoc'">Schedule + +