Skip to content

Commit

Permalink
Added the memorize concept for invoice import process to improve the…
Browse files Browse the repository at this point in the history
… performance
  • Loading branch information
sheiksalahudeen committed May 12, 2016
1 parent 912d43d commit abb6e91
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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.VendorAddress;
import org.kuali.ole.vnd.businessobject.VendorAlias;
import org.kuali.ole.vnd.businessobject.VendorDetail;
import org.kuali.ole.vnd.businessobject.*;
import org.kuali.ole.vnd.document.service.VendorService;

import java.util.List;
Expand All @@ -37,4 +38,10 @@ public interface OleNGMemorizeService {
public Integer getRequestSourceTypeId(String requestSourceType);
public OLEDonor getDonorCode(String donorCode);
public BatchProcessProfile fetchBatchProcessProfile(String profileName, String type);

public List<OleExchangeRate> getExchangeRate(String currencyTypeId);
public OleCurrencyType getCurrencyType(String currencyTypeId);
public List<OleVendorAccountInfo> getVendorAccountInfo(String code);
public List<Account> getAccount(String accountNumber);
public List<OleFundCode> getFundCode(String fundCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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())){
Expand Down Expand Up @@ -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<OleExchangeRate> 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<OleExchangeRate> 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());
}
}
}
}
}
Expand Down Expand Up @@ -439,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;
}

Expand Down Expand Up @@ -483,24 +490,18 @@ private OleInvoiceItem createNewInvoiceItem(OleInvoiceRecord invoiceRecord) {


private OleVendorAccountInfo populateBFN(String code) {
Map matchBFN = new HashMap();
matchBFN.put("vendorRefNumber", code);
List<OleVendorAccountInfo> oleVendorAccountInfo = (List<OleVendorAccountInfo>) getBusinessObjectService().findMatching(OleVendorAccountInfo.class, matchBFN);
return oleVendorAccountInfo != null && oleVendorAccountInfo.size() > 0 ? oleVendorAccountInfo.get(0) : null;
List<OleVendorAccountInfo> 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<Account> accountList = (List<Account>) getBusinessObjectService().findMatching(Account.class, matchChartCode);
return accountList != null && accountList.size() > 0 ? accountList.get(0).getChartOfAccountsCode() : null;
List<Account> 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<OleFundCode> fundCodeList = (List) getBusinessObjectService().findMatching(OleFundCode.class, fundCodeMap);
List<OleFundCode> fundCodeList = getOleNGMemorizeService().getFundCode(invoiceRecord.getFundCode());
if (CollectionUtils.isNotEmpty(fundCodeList)) {
OleFundCode oleFundCode = fundCodeList.get(0);
List<OleFundCodeAccountingLine> fundCodeAccountingLineList = oleFundCode.getOleFundCodeAccountingLineList();
Expand Down Expand Up @@ -569,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;
Expand Down Expand Up @@ -659,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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;
Expand All @@ -15,16 +17,16 @@
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.VendorAddress;
import org.kuali.ole.vnd.businessobject.VendorAlias;
import org.kuali.ole.vnd.businessobject.VendorDetail;
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;
Expand Down Expand Up @@ -159,6 +161,40 @@ public BatchProcessProfile fetchBatchProcessProfile(String profileName, String t
return batchProcessProfile;
}

@Memoize
public List<OleExchangeRate> 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<OleVendorAccountInfo> getVendorAccountInfo(String code) {
Map matchBFN = new HashMap();
matchBFN.put("vendorRefNumber", code);
return (List<OleVendorAccountInfo>) getBusinessObjectService().findMatching(OleVendorAccountInfo.class, matchBFN);
}

@Memoize
public List<Account> getAccount(String accountNumber) {
Map matchChartCode = new HashMap();
matchChartCode.put("accountNumber", accountNumber);
return (List<Account>) getBusinessObjectService().findMatching(Account.class, matchChartCode);
}

@Memoize
public List<OleFundCode> 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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public boolean validateOleInvoiceRecord(OleInvoiceRecord oleInvoiceRecord, Excha

private boolean validateInvoiceNumber(OleInvoiceRecord oleInvoiceRecord, Exchange exchange, Integer recordIndex) {
String invoiceNumber = oleInvoiceRecord.getInvoiceNumber();
if (StringUtils.isBlank(invoiceNumber) || !NumberUtils.isDigits(invoiceNumber)){
if (StringUtils.isBlank(invoiceNumber)){
getBatchUtil().addInvoiceFaiureResponseToExchange(
new ValidationException("Invoice number cannot be blank or null and it should be round number"), recordIndex, exchange);
new ValidationException("Invoice number cannot be blank or null"), recordIndex, exchange);
return false;
}
return true;
Expand Down

0 comments on commit abb6e91

Please sign in to comment.