package com.gpc.tams.sync.customer.databuilder; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Component; import com.gpc.tams.model.customer.domain.Address; import com.gpc.tams.model.customer.domain.BlanketPOs; import com.gpc.tams.model.customer.domain.Certifications; import com.gpc.tams.model.customer.domain.CommunicationDirs; import com.gpc.tams.model.customer.domain.Contacts; import com.gpc.tams.model.customer.domain.CustomerAR; import com.gpc.tams.model.customer.domain.CustomerDetails; import com.gpc.tams.model.customer.domain.CustomerDomainFeedDetails; import com.gpc.tams.model.customer.domain.Delivery; import com.gpc.tams.model.customer.domain.StatementAddress; import com.gpc.tams.model.customer.domain.Tax; import com.gpc.tams.repository.communication.CommunicationDirectory; import com.gpc.tams.repository.customer.Customer; import com.gpc.tams.repository.customer.CustomerAr; import com.gpc.tams.repository.customer.CustomerBlanketPo; import com.gpc.tams.repository.customer.CustomerContact; import com.gpc.tams.repository.customer.CustomerDelivery; import com.gpc.tams.repository.customer.CustomerStatementAddress; import com.gpc.tams.repository.employeemanagement.Employee; import com.gpc.tams.repository.inventory.CustomerCertification; import com.gpc.tams.sync.customer.Previous; import com.gpc.tams.sync.customer.constants.CustomerChangeQueueAction; import com.gpc.tams.sync.customer.constants.CustomerDomainTable; import com.gpc.tams.util.DateUtil2; @Component public class CustomerDomainDataBuilder extends AbstractCustomerDomainDataBuilder { public CustomerDomainFeedDetails buildCustomerDomainPayloadData(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerDomainPayloadData - "; context.logDebug(methodSpec); final CustomerDomainFeedDetails customerDomainData = new CustomerDomainFeedDetails(); if(isCustomerTableRecordDeleted()) { customerDomainData.setPrevious(buildCustomerTableDeletedRecordDetails(customerData)); } else { buildCustomerDomainData(customerDomainData, customerData); customerDomainData.setCustomer(buildCustomerDetails(customerData)); customerDomainData.setStatementAddress(buildCustomerStatementAddressDetails(customerData)); customerDomainData.setContacts(buildCustomerContactDetails(customerData)); customerDomainData.setCertifications(buildCustomerCertificationDetails(customerData)); customerDomainData.setCommunicationDirs(buildCommunicationDirectoryDetails(customerData)); customerDomainData.setBlanketPOs(buildCustomerBlanketPODetails(customerData)); customerDomainData.setCustomerAr(buildCustomerARDetails(customerData)); customerDomainData.setDelivery(buildCustomerDeliveryDetails(customerData)); context.logDebug(methodSpec + "Customer Domain Data = " + customerDomainData); } return customerDomainData; } private CustomerDetails buildCustomerDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerDetails - "; context.logDebug(methodSpec); final CustomerDetails customer = new CustomerDetails(); customer.setOperation(getCustomerChangeQueueActionCode(CustomerDomainTable.CUSTOMER)); customer.setCustomerNumber(customerData.getId() == -1 ? null : customerData.getCustomerNumber()); customer.setPriorityPlus(isFlagChecked(customerData.getPriorityPlus())); customer.setIbsAccount(isFlagChecked(customerData.isIbsAccount())); customer.setAlternateCoreCustomerId(customerData.getAlternateCoreCustomerId()); customer.setCustomerTypeCd(customerData.getRefCustomerTypeCode()); customer.setAlphaKey(customerData.getAlphaKey()); customer.setActiveAccount(isFlagChecked(customerData.isActiveAccount())); customer.setAccountEstablishDate( DateUtil2.getEpochValue(customerData.getAccountEstablishDate())); customer.setName(customerData.getName()); customer.setEmail(customerData.getEmail()); customer.setInvoiceEmailAddress(customerData.getInvoiceEmailAddress()); customer.setPhone(customerData.getPhone()); customer.setExtension(customerData.getExtension()); customer.setFaxNumber(customerData.getFaxNumber()); customer.setWebAddress(customerData.getWebAddress()); customer.setCheckForMiscChgExemptions( isFlagChecked(customerData.isCheckForMiscChangeExemptions())); customer.setExtraInvCopies(customerData.getExtraInvoiceCopies()); customer.setMinAmtForPo(Integer.valueOf(customerData.getMinAmountForPO())); customer.setCustomerNoteId(customerData.getCustomerNoteId()); customer.setAllowOnlyCoreSales(customerData.getAllowOnlyCoreSales()); customer.setAllowSpecialOrders(isFlagChecked(customerData.isAllowSpecialOrders())); customer.setAuthorizedBuyersOnly(isFlagChecked(customerData.isAuthorizedBuyersOnly())); customer.setBillingTypeCd(customerData.getRefBillingTypeCode()); customer.setLanguageCd(customerData.getRefLanguageCode()); customer.setPrintBalanceOnInv(isFlagChecked(customerData.isPrintBalanceOnInvoice())); customer.setPrintCatalogNotesOnInvoice( isFlagChecked(customerData.isPrintCatalogNotesOnInvoice())); customer.setPrintMsdsForCustomer(isFlagChecked(customerData.isPrintMsdsForCustomer())); customer.setTransmitJsaSales(customerData.getTransmitJsaSales()); customer.setTransmitNationalSales(customerData.getTransmitNationalSales()); customer.setCustomerTypicallyPresentDuringInvoicing( isFlagChecked(customerData.isCustomerTypicallyPresentDuringInvoicing())); customer.setUsualPriceMarkupPercent( Integer.valueOf(customerData.getUsualPriceMarkupPercent())); customer.setUsualPriceSheetCd(customerData.getUsualRefPriceSheetCode()); customer.setCppFlag(isFlagChecked(customerData.getCppFlag())); customer.setSalesmanEmployeeId(customerData.getSalesmanEmployeeId()); customer.setAllowEmployeeEraseCore(isFlagChecked(customerData.isAllowEmployeeEraseCore())); customer.setAllowBackorders(isFlagChecked(customerData.isAllowBackorders())); customer.setMonthlySalesPotential(customerData.getMonthlySalesPotential()); customer.setDirectShipmentEligible(isFlagChecked(customerData.isDirectShipmentEligible())); customer.setDnsCustomer(customerData.getDnsCustomer()); final Address address = new Address(); address.setAddress1(customerData.getAddress1()); address.setAddress2(customerData.getAddress2()); address.setAddress3(customerData.getAddress3()); address.setAddress4(customerData.getAddress4()); address.setCity(customerData.getCity()); address.setStateCd(customerData.getStateCode()); address.setCountryCd(customerData.getCountryCode()); address.setPostalCode(customerData.getPostalCode()); customer.setAddress(address); // Tax final Tax tax = new Tax(); tax.setDefaultTaxTableId(customerData.getDefaultTaxTableId()); tax.setDeliveredTaxTableId(customerData.getDeliveredTaxTableId()); tax.setPrimaryTaxIdentifier(customerData.getPrimaryTaxNumber()); tax.setSecondaryTaxIdentifier(customerData.getSecondaryTaxNumber()); tax.setTaxExemptNumberPrimary(customerData.getTaxExemptNumPrimary()); tax.setTaxExemptNumberSecondary(customerData.getTaxExemptNumSecondary()); tax.setTaxExemptPrimaryExpDate( DateUtil2.getEpochValue(customerData.getTaxExemptPrimaryExpirationDate())); tax.setTaxExemptSecondaryExpDate( DateUtil2.getEpochValue(customerData.getTaxExemptSecondaryExpirationDate())); tax.setTaxStatusPrimaryOptionCd(customerData.getTaxStatusPrimaryRefOptionCode()); tax.setTaxStatusSecondaryOptionCd(customerData.getTaxStatusSecondaryRefOptionCode()); customer.setTax(tax); context.logDebug(methodSpec + "Customer = " + customer); return customer; } private CustomerAR buildCustomerARDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerARDetails - "; context.logDebug(methodSpec); final CustomerAr customerArDetails = customerData.getCustomerAr(); CustomerAR customerAR = null; if (customerArDetails != null) { customerAR = new CustomerAR(); customerAR.setOperation(getCustomerChangeQueueActionCode(CustomerDomainTable.CUSTOMER_AR)); customerAR.setCustomerId(customerData.getId()); customerAR.setArTermsId(customerArDetails.getArTermsId()); customerAR.setLoc(Integer.valueOf(customerArDetails.getLocation())); customerAR.setStatementTypeId(customerArDetails.getRefStatementTypeId()); customerAR.setStatementCustomerId(customerArDetails.getStatementCustomerId()); customerAR.setExtraStatementCopies(customerArDetails.getExtraStatementCopies()); customerAR.setCombinedStatement(isFlagChecked(customerArDetails.isCombinedStatement())); customerAR.setCreditLimit(customerArDetails.getCreditLimit()); customerAR.setStoreResponsibility(customerArDetails.getStoreResponsibility()); customerAR.setAgeCustomer(isFlagChecked(customerArDetails.isAgeCustomer())); customerAR.setBadDebtAcct(isFlagChecked(customerArDetails.isBadDebtAccount())); customerAR.setAcctSummaryDays(customerArDetails.getAccountSummaryDays()); customerAR.setInvoiceCopyDays(customerArDetails.getInvoiceCopyDays()); customerAR.setReturnedCheckCount(customerArDetails.getReturnedCheckCount()); customerAR.setAcceptCheckIfPriorBadCheck( isFlagChecked(customerArDetails.isAcceptCheckIfPriorBadCheck())); if (customerArDetails.getRefStatementFormatId() != null) { customerAR.setStatementFormatId( customerArDetails.getRefStatementFormatId().intValue()); } customerAR.setStatementEmailAddress(customerArDetails.getStatementEmailAddress()); customerAR.setNumberOfTimesCod(customerArDetails.getNumberOfTimesCod()); customerAR.setLastCodDate(DateUtil2.getEpochValue(customerArDetails.getLastCodDate())); } if (doesDeletedRecordExists(CustomerDomainTable.CUSTOMER_AR)) { customerAR = buildCustomerARDeletedRecordDetails(); } context.logDebug(methodSpec + "Customer AR = " + customerAR); return customerAR; } private CustomerAR buildCustomerARDeletedRecordDetails() { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerARDeletedRecordDetails - "; context.logDebug(methodSpec); final String deletedCustomerARRecordData = customerChangeQueueDeletedValue; CustomerAR customerAR = null; if (deletedCustomerARRecordData != null && deletedCustomerARRecordData.trim().length() > 0) { final String[] deletedRecordData = deletedCustomerARRecordData.split("\\|", -1); if (deletedRecordData.length == 19) { customerAR = new CustomerAR(); customerAR.setOperation(CustomerChangeQueueAction.DELETE); final String customerId = deletedRecordData[0]; customerAR.setCustomerId(convertToInt(customerId)); final String arTermsId = deletedRecordData[1]; customerAR.setArTermsId(convertToInt(arTermsId)); final String refStatementTypeId = deletedRecordData[2]; customerAR.setStatementTypeId(convertToInt(refStatementTypeId)); final String statementCustomerId = deletedRecordData[3]; if (StringUtils.isNotEmpty(statementCustomerId)) { customerAR.setStatementCustomerId(Integer.valueOf(statementCustomerId)); } final String location = deletedRecordData[4]; customerAR.setLoc(convertToInt(location)); final String extraStatementCopies = deletedRecordData[5]; customerAR.setExtraStatementCopies(convertToInt(extraStatementCopies)); final String combinedStatement = deletedRecordData[6]; customerAR.setCombinedStatement(combinedStatement); final String creditLimit = deletedRecordData[7]; customerAR.setCreditLimit(convertToInt(creditLimit)); final String storeResponsiblity = deletedRecordData[8]; customerAR.setStoreResponsibility(convertToInt(storeResponsiblity)); final String ageCustomer = deletedRecordData[9]; customerAR.setAgeCustomer(ageCustomer); final String badDebtAccount = deletedRecordData[10]; customerAR.setBadDebtAcct(badDebtAccount); final String acctSummaryDays = deletedRecordData[11]; customerAR.setAcctSummaryDays(convertToInt(acctSummaryDays)); final String invoiceCopyDays = deletedRecordData[12]; customerAR.setInvoiceCopyDays(convertToInt(invoiceCopyDays)); final String returnedCheckCount = deletedRecordData[13]; customerAR.setReturnedCheckCount(convertToInt(returnedCheckCount)); final String acceptCheckIfPriorBadCheck = deletedRecordData[14]; customerAR.setAcceptCheckIfPriorBadCheck(acceptCheckIfPriorBadCheck); final String refStatementFormatId = deletedRecordData[15]; customerAR.setStatementFormatId(convertToInt(refStatementFormatId)); final String statementEmailAddress = deletedRecordData[16]; customerAR.setStatementEmailAddress(statementEmailAddress); final String lastCODDate = deletedRecordData[17]; customerAR.setLastCodDate( DateUtil2.convertStringToEpoch(lastCODDate, YYYY_MM_DD_PATTERN)); final String numOfTimesCOD = deletedRecordData[18]; customerAR.setNumberOfTimesCod(convertToInt(numOfTimesCOD)); } } return customerAR; } private BlanketPOs[] buildCustomerBlanketPODetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerBlanketPODetails - "; context.logDebug(methodSpec); final List customerBlanketPoDetails = customerData .getCustomerBlankedPODetails(); BlanketPOs blanketPOs = null; List blanketPODetails = new ArrayList(); if (customerBlanketPoDetails != null && customerBlanketPoDetails.size() > 0) { for (CustomerBlanketPo customerBlanketPo : customerBlanketPoDetails) { blanketPOs = new BlanketPOs(); if(customerBlanketPo.getId() != null) { blanketPOs.setOperation(getOperationCode(CustomerDomainTable.CUSTOMER_BLANKET_PO, customerBlanketPo.getId().intValue())); } blanketPOs.setBlanketPOId(customerBlanketPo.getId()); blanketPOs.setCustomerId(customerData.getId()); blanketPOs.setBlanketPONumber(customerBlanketPo.getBlanketPoNum()); blanketPOs.setBeginDate(DateUtil2.getEpochValue(customerBlanketPo.getBeginDate())); blanketPOs.setEndDate(DateUtil2.getEpochValue(customerBlanketPo.getEndDate())); blanketPOs.setMaximumAmountAllowed(customerBlanketPo.getMaxAmountAllowed()); blanketPOs.setLastModifiedDateTime( DateUtil2.getEpochValue(customerBlanketPo.getLastModifiedDate())); blanketPOs.setModifiedByEmployeeName(customerBlanketPo.getModifiedByEmployeeName()); blanketPOs.setModifiedByEmployeeNumber( customerBlanketPo.getModifiedByEmployeeNumber()); blanketPODetails.add(blanketPOs); } } if (doesDeletedRecordExists(CustomerDomainTable.CUSTOMER_BLANKET_PO)) { buildCustomerBlanketPODeletedRecordDetails(blanketPODetails); } context.logDebug(methodSpec + "Customer BlanketPOs = " + blanketPODetails); return blanketPODetails.toArray(new BlanketPOs[blanketPODetails.size()]); } private void buildCustomerBlanketPODeletedRecordDetails(final List blanketPODetails) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerBlanketPODeletedRecordDetails - "; context.logDebug(methodSpec); final String deletedBlanketPORecord = customerChangeQueueDeletedValue; BlanketPOs blanketPOs = null; if(deletedBlanketPORecord != null && deletedBlanketPORecord.trim().length() > 0) { String[] customerBlanketPORecordData = deletedBlanketPORecord.split("\\|", -1); if (customerBlanketPORecordData != null && customerBlanketPORecordData.length == 8) { blanketPOs = new BlanketPOs(); blanketPOs.setOperation(CustomerChangeQueueAction.DELETE); final String customerId = customerBlanketPORecordData[0]; blanketPOs.setCustomerId(convertToInt(customerId)); final String blanketPOId = customerBlanketPORecordData[1]; blanketPOs.setBlanketPOId(convertToInt(blanketPOId)); final String blanketPONumber = customerBlanketPORecordData[2]; blanketPOs.setBlanketPONumber(blanketPONumber); final String beginDate = customerBlanketPORecordData[3]; blanketPOs.setBeginDate(DateUtil2.convertStringToEpoch(beginDate, YYYY_MM_DD_PATTERN)); final String endDate = customerBlanketPORecordData[4]; blanketPOs.setEndDate(DateUtil2.convertStringToEpoch(endDate, YYYY_MM_DD_PATTERN)); final String maximumAmountAllowed = customerBlanketPORecordData[5]; blanketPOs.setMaximumAmountAllowed(new BigDecimal(maximumAmountAllowed)); final String lastModifiedDate = customerBlanketPORecordData[6]; blanketPOs.setLastModifiedDateTime(DateUtil2.convertStringToEpoch(lastModifiedDate, YYYY_MM_DD_HH_MM_SS_PATTERN)); final String modifiedByEmployeeId = customerBlanketPORecordData[7]; final Employee employee = findEmployeeByEmployeeId(convertToInt(modifiedByEmployeeId)); if (employee != null) { blanketPOs.setModifiedByEmployeeName( employee.getFirstName() + " " + employee.getLastName()); blanketPOs.setModifiedByEmployeeNumber(employee.getEmployeeNumber()); } } } if(blanketPOs != null) { blanketPODetails.add(blanketPOs); } } private StatementAddress buildCustomerStatementAddressDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildStatementAddressDetails - "; context.logDebug(methodSpec); StatementAddress statementAddress = null; final CustomerStatementAddress customerStatementAddress = customerData .getCustomerStatementAddress(); if (customerStatementAddress != null) { statementAddress = new StatementAddress(); statementAddress.setOperation(getCustomerChangeQueueActionCode(CustomerDomainTable.CUSTOMER_STATEMENT_ADDRESS)); statementAddress.setCustomerId(customerData.getId()); statementAddress.setName(customerStatementAddress.getName()); final Address address = new Address(); address.setAddress1(customerStatementAddress.getAddress1()); address.setAddress2(customerStatementAddress.getAddress2()); address.setAddress3(customerStatementAddress.getAddress3()); address.setAddress4(customerStatementAddress.getAddress4()); address.setCity(customerStatementAddress.getCity()); address.setStateCd(customerStatementAddress.getRefStateCode()); address.setCountryCd(customerStatementAddress.getRefCountryCode()); address.setPostalCode(customerStatementAddress.getPostalCode()); statementAddress.setAddress(address); } if (doesDeletedRecordExists(CustomerDomainTable.CUSTOMER_STATEMENT_ADDRESS)) { statementAddress = buildCustomerStatementAddressDeletedRecordDetails(); } context.logDebug(methodSpec + "Customer Statement Address = " + statementAddress); return statementAddress; } private StatementAddress buildCustomerStatementAddressDeletedRecordDetails() { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerStatementAddressDeletedRecordDetails - "; context.logDebug(methodSpec); final String deletedStatementAddressRecord = customerChangeQueueDeletedValue; StatementAddress statementAddress = null; if(deletedStatementAddressRecord != null && deletedStatementAddressRecord.trim().length() > 0) { final String[] deletedRecordData = deletedStatementAddressRecord.split("\\|", -1); if (deletedRecordData != null && deletedRecordData.length == 10) { statementAddress = new StatementAddress(); statementAddress.setOperation(CustomerChangeQueueAction.DELETE); final String customerId = deletedRecordData[0]; statementAddress.setCustomerId(convertToInt(customerId)); final String name = deletedRecordData[1]; statementAddress.setName(name); final Address address = new Address(); final String addressLine1 = deletedRecordData[2]; address.setAddress1(addressLine1); final String addressLine2 = deletedRecordData[3]; address.setAddress2(addressLine2); final String addressLine3 = deletedRecordData[4]; address.setAddress3(addressLine3); final String addressLine4 = deletedRecordData[5]; address.setAddress4(addressLine4); final String city = deletedRecordData[6]; address.setCity(city); final String refStateCd = deletedRecordData[7]; address.setStateCd(refStateCd); final String postalCode = deletedRecordData[8]; address.setPostalCode(postalCode); final String refCountryCd = deletedRecordData[9]; address.setCountryCd(refCountryCd); statementAddress.setAddress(address); } } context.logDebug(methodSpec + "StatementAddress = " + statementAddress); return statementAddress; } private Certifications[] buildCustomerCertificationDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerCertificationDetails - "; context.logDebug(methodSpec); final List customerCerificationDetails = customerData .getCustomerCertificationDetails(); List certificationDetails = new ArrayList(); Certifications certifications = null; if (customerCerificationDetails != null && customerCerificationDetails.size() > 0) { for (CustomerCertification customerCertification : customerCerificationDetails) { certifications = new Certifications(); certifications.setOperation(getOperationCode(CustomerDomainTable.CUSTOMER_CERTIFICATION, customerCertification.getId())); certifications.setCertificateId(Integer.valueOf(customerCertification.getId())); certifications.setCustomerId(customerData.getId()); certifications.setCertificateNumber(customerCertification.getCertificateNumber()); certifications.setTechnicianName(customerCertification.getTechnicianName()); certifications.setCertificationPartGroupId( Integer.valueOf(customerCertification.getCertificationPartGroupId())); certifications .setBeginDate(DateUtil2.getEpochValue(customerCertification.getBeginDate())); certifications.setEndDate(DateUtil2.getEpochValue(customerCertification.getEndDate())); certifications.setNapaReserved(customerCertification.getNapaReserved()); certifications.setLastModifiedDateTime( DateUtil2.getEpochValue(customerCertification.getLastModifiedDate())); certifications.setModifiedByEmployeeNumber( customerCertification.getModifiedByEmployeeNumber()); certifications.setModifiedByEmployeeName( customerCertification.getModifiedByEmployeeName()); certificationDetails.add(certifications); } } if (doesDeletedRecordExists(CustomerDomainTable.CUSTOMER_CERTIFICATION)) { buildCustomerCertificationDeletedRecordDetails(certificationDetails); } context.logDebug(methodSpec + "Customer Certifications = " + certificationDetails); return certificationDetails.toArray(new Certifications[certificationDetails.size()]); } private void buildCustomerCertificationDeletedRecordDetails(final List certificationDetails) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerCertificationDeletedRecordDetails - "; context.logDebug(methodSpec); final String deletedCustomerCertificationRecord = customerChangeQueueDeletedValue; Certifications certifications = null; if(deletedCustomerCertificationRecord != null && deletedCustomerCertificationRecord.trim().length() > 0) { final String[] customerCertificationRecordData = deletedCustomerCertificationRecord .split("\\|", -1); if (customerCertificationRecordData.length == 9) { certifications = new Certifications(); certifications.setOperation(CustomerChangeQueueAction.DELETE); final String customerId = customerCertificationRecordData[0]; certifications.setCustomerId(convertToInt(customerId)); final String id = customerCertificationRecordData[1]; certifications.setCertificateId(convertToInt(id)); final String certificationPartGroupId = customerCertificationRecordData[2]; certifications.setCertificationPartGroupId(convertToInt(certificationPartGroupId)); final String technicianName = customerCertificationRecordData[3]; certifications.setTechnicianName(technicianName); final String beginDate = customerCertificationRecordData[4]; certifications.setBeginDate(DateUtil2.convertStringToEpoch(beginDate, YYYY_MM_DD_PATTERN)); final String endDate = customerCertificationRecordData[5]; certifications.setEndDate(DateUtil2.convertStringToEpoch(endDate, YYYY_MM_DD_PATTERN)); final String certificateNumber = customerCertificationRecordData[6]; certifications.setCertificateNumber(certificateNumber); final String lastModifiedDate = customerCertificationRecordData[7]; certifications.setLastModifiedDateTime(DateUtil2.convertStringToEpoch(lastModifiedDate, YYYY_MM_DD_HH_MM_SS_PATTERN)); final String modifiedByEmployeeId = customerCertificationRecordData[8]; final Employee employee = findEmployeeByEmployeeId(convertToInt(modifiedByEmployeeId)); if(employee != null) { certifications.setModifiedByEmployeeName(employee.getFirstName() + " " + employee.getLastName()); certifications.setModifiedByEmployeeNumber(employee.getEmployeeNumber()); } } } if(certifications != null) { certificationDetails.add(certifications); } } private CommunicationDirs[] buildCommunicationDirectoryDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCommunicationDirectoryDetails - "; context.logDebug(methodSpec); final List communicationDirectoryDetails = customerData .getCustomerCommunicationDirectoryDetails(); CommunicationDirs communicationDirs = null; List communicationDirectoryEntries = new ArrayList(); if(communicationDirectoryDetails != null && communicationDirectoryDetails.size() > 0) { for (CommunicationDirectory communicationDirectory : communicationDirectoryDetails) { communicationDirs = new CommunicationDirs(); communicationDirs.setOperation(getOperationCode(CustomerDomainTable.COMMUNICATION_DIRECTORY, communicationDirectory.getId())); communicationDirs.setCommunicationId(communicationDirectory.getId()); communicationDirs.setAllowDcStockCheck(isFlagChecked(communicationDirectory.isAllowDcStockCheck())); communicationDirs.setDisplayOnHandDetails(isFlagChecked( communicationDirectory.isDisplayOnHandDetails())); communicationDirs.setInvoiceToCustomerId(communicationDirectory.getInvoiceToCustomerId()); communicationDirs.setName(communicationDirectory.getName()); communicationDirs.setPassword(communicationDirectory.getPassword()); communicationDirs.setProlinkAccountNumber(communicationDirectory.getProlinkAccountNumber()); communicationDirs.setTimeoutMinutes(communicationDirectory.getTimeoutMinutes()); communicationDirs.setStoreNumber(communicationDirectory.getStoreNumber()); communicationDirs.setRefCommunicationTypeId(communicationDirectory.getRefCommunicationTypeId()); communicationDirs.setLastLoginDate( DateUtil2.getEpochValue(communicationDirectory.getLastLoginDate())); communicationDirs.setLastModifiedDateTime( DateUtil2.getEpochValue(communicationDirectory.getLastModifiedDate())); communicationDirs.setModifiedByEmployeeNumber(communicationDirectory.getModifiedByEmployeeNumber()); communicationDirs.setModifiedByEmployeeName(communicationDirectory.getModifiedByEmployeeName()); communicationDirectoryEntries.add(communicationDirs); } } if(doesDeletedRecordExists(CustomerDomainTable.COMMUNICATION_DIRECTORY)) { buildCommunicationDirectoryDeletedRecordDetails(communicationDirectoryEntries); } context.logDebug(methodSpec + "Customer Communication Directory Details = " + communicationDirectoryEntries); return communicationDirectoryEntries.toArray(new CommunicationDirs[communicationDirectoryEntries.size()]); } private void buildCommunicationDirectoryDeletedRecordDetails(List communicationDirectoryEntries) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCommunicationDirectoryDeletedRecordDetails - "; context.logDebug(methodSpec); final String communicationDirectoryRecordDeletedData = customerChangeQueueDeletedValue; if (communicationDirectoryRecordDeletedData != null && communicationDirectoryRecordDeletedData.trim().length() > 0) { final String[] deletedRecordData = communicationDirectoryRecordDeletedData.split("\\|", -1); CommunicationDirs communicationDirs = null; if (deletedRecordData.length == 13) { communicationDirs = new CommunicationDirs(); communicationDirs.setOperation(CustomerChangeQueueAction.DELETE); final String invoiceToCustomerId = deletedRecordData[0]; communicationDirs.setInvoiceToCustomerId(convertToInt(invoiceToCustomerId)); final String id = deletedRecordData[1]; communicationDirs.setCommunicationId(convertToInt(id)); final String refCommunicationTypeId = deletedRecordData[2]; communicationDirs.setRefCommunicationTypeId(convertToInt(refCommunicationTypeId)); final String name = deletedRecordData[3]; communicationDirs.setName(name); final String password = deletedRecordData[4]; communicationDirs.setPassword(password); final String lastLoginDate = deletedRecordData[5]; communicationDirs .setLastLoginDate(DateUtil2.convertStringToEpoch(lastLoginDate, YYYY_MM_DD_HH_MM_SS_PATTERN)); final String timeoutMinutes = deletedRecordData[6]; communicationDirs.setTimeoutMinutes(convertToInt(timeoutMinutes)); final String allowDCStockCheck = deletedRecordData[7]; communicationDirs.setAllowDcStockCheck(allowDCStockCheck); final String proLinkAccountNumber = deletedRecordData[8]; communicationDirs.setProlinkAccountNumber(convertToInt(proLinkAccountNumber)); final String displayOnHandDetails = deletedRecordData[9]; communicationDirs.setDisplayOnHandDetails(displayOnHandDetails); final String storeNumber = deletedRecordData[10]; communicationDirs.setStoreNumber(storeNumber); final String lastModifiedDate = deletedRecordData[11]; communicationDirs.setLastModifiedDateTime( DateUtil2.convertStringToEpoch(lastModifiedDate, YYYY_MM_DD_HH_MM_SS_PATTERN)); final String modifiedByEmployeeId = deletedRecordData[12]; if (modifiedByEmployeeId != null) { final Employee employee = findEmployeeByEmployeeId( convertToInt(modifiedByEmployeeId)); if (employee != null) { communicationDirs.setModifiedByEmployeeName( employee.getFirstName() + " " + employee.getLastName()); communicationDirs.setModifiedByEmployeeNumber(employee.getEmployeeNumber()); } } } context.logDebug(methodSpec + "CommunicationDirs = " + communicationDirs); if(communicationDirs != null) { communicationDirectoryEntries.add(communicationDirs); } } } private Contacts[] buildCustomerContactDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerContactDetails - "; context.logDebug(methodSpec); List customerContactDetails = customerData.getCustomerContactDetails(); final List contactList = new ArrayList(); Contacts contacts = null; if (customerContactDetails != null && customerContactDetails.size() > 0) { for (CustomerContact customerContact : customerContactDetails) { contacts = new Contacts(); if(customerContact.getId() != null) { contacts.setOperation(getOperationCode(CustomerDomainTable.CUSTOMER_CONTACT, customerContact.getId().intValue())); } contacts.setContactId(customerContact.getId()); contacts.setCustomerId(customerData.getId()); contacts.setTitle(customerContact.getTitle()); contacts.setName(customerContact.getName()); contacts.setAuthorizedBuyer(isFlagChecked(customerContact.isAuthorizedBuyer())); contacts.setEmail(customerContact.getEmail()); contacts.setHomePhone(customerContact.getHomePhone()); contacts.setPhone(customerContact.getPhone()); contacts.setExtension(customerContact.getExtension()); contacts.setCellPhone(customerContact.getCellPhone()); contacts.setFaxNumber(customerContact.getFaxNumber()); contacts.setPager(customerContact.getPager()); contacts.setNote(customerContact.getNote()); final Address address = new Address(); address.setAddress1(customerContact.getAddress1()); address.setAddress2(customerContact.getAddress2()); address.setAddress3(customerContact.getAddress3()); address.setAddress4(customerContact.getAddress4()); address.setCity(customerContact.getCity()); address.setStateCd(customerContact.getStateCode()); address.setCountryCd(customerContact.getCountryCode()); address.setPostalCode(customerContact.getPostalCode()); contacts.setAddress(address); contacts.setLastModifiedDateTime( DateUtil2.getEpochValue(customerData.getLastModifiedDate())); contacts.setModifiedByEmployeeNumber(customerContact.getModifiedByEmployeeNumber()); contacts.setModifiedByEmployeeName(customerContact.getModifiedByEmployeeName()); contactList.add(contacts); } } if(doesDeletedRecordExists(CustomerDomainTable.CUSTOMER_CONTACT) ) { buildCustomerContactDeletedRecordDetails(contactList); } context.logDebug(methodSpec + "Customer Contacts = " + contactList); return contactList.toArray(new Contacts[contactList.size()]); } private void buildCustomerContactDeletedRecordDetails(final List contactList) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerContactDeletedRecordDetails - "; context.logDebug(methodSpec); final String customerContactDeletedRecord = customerChangeQueueDeletedValue; Contacts contacts = null; if(customerContactDeletedRecord != null && customerContactDeletedRecord.trim().length() > 0) { final String[] deletedRecordData = customerContactDeletedRecord.split("\\|", -1); if(deletedRecordData.length == 23) { contacts = new Contacts(); contacts.setOperation(CustomerChangeQueueAction.DELETE); final String customerId = deletedRecordData[0]; contacts.setCustomerId(convertToInt(customerId)); final String id = deletedRecordData[1]; contacts.setContactId(convertToInt(id)); final String name = deletedRecordData[2]; contacts.setName(name); final String title = deletedRecordData[3]; contacts.setTitle(title); final String phone = deletedRecordData[4]; contacts.setPhone(phone); final String extension = deletedRecordData[5]; contacts.setExtension(extension); final String cellPhone = deletedRecordData[6]; contacts.setCellPhone(cellPhone); final String pager = deletedRecordData[7]; contacts.setPager(pager); final String homePhone = deletedRecordData[8]; contacts.setHomePhone(homePhone); final String faxNumber = deletedRecordData[9]; contacts.setFaxNumber(faxNumber); final String authorizedBuyer = deletedRecordData[10]; contacts.setAuthorizedBuyer(authorizedBuyer); final Address address = new Address(); final String addressLine1 = deletedRecordData[11]; address.setAddress1(addressLine1); final String addressLine2 = deletedRecordData[12]; address.setAddress2(addressLine2); final String addressLine3 = deletedRecordData[13]; address.setAddress3(addressLine3); final String addressLine4 = deletedRecordData[14]; address.setAddress4(addressLine4); final String city = deletedRecordData[15]; address.setCity(city); final String refStateCd = deletedRecordData[16]; address.setStateCd(refStateCd); final String postalCode = deletedRecordData[17]; address.setPostalCode(postalCode); final String refCountryCd = deletedRecordData[18]; address.setCountryCd(refCountryCd); contacts.setAddress(address); final String note = deletedRecordData[19]; contacts.setNote(note); final String email = deletedRecordData[20]; contacts.setEmail(email); final String lastModifiedDate = deletedRecordData[21]; contacts.setLastModifiedDateTime(DateUtil2.convertStringToEpoch(lastModifiedDate, YYYY_MM_DD_HH_MM_SS_PATTERN)); final String modifiedByEmployeeId = deletedRecordData[22]; if (modifiedByEmployeeId != null) { final Employee employee = findEmployeeByEmployeeId( convertToInt(modifiedByEmployeeId)); if (employee != null) { contacts.setModifiedByEmployeeName( employee.getFirstName() + " " + employee.getLastName()); contacts.setModifiedByEmployeeNumber(employee.getEmployeeNumber()); } } } } context.logDebug(methodSpec + "Contacts = " + contacts); if(contacts != null) { contactList.add(contacts); } } private Delivery buildCustomerDeliveryDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerDeliveryDetails - "; context.logDebug(methodSpec); final CustomerDelivery customerDelivery = customerData.getCustomerDelivery(); Delivery delivery = null; if(customerDelivery != null) { delivery = new Delivery(); delivery.setOperation(getCustomerChangeQueueActionCode(CustomerDomainTable.CUSTOMER_DELIVERY)); delivery.setCustomerId(customerData.getId()); delivery.setLoc(Integer.valueOf(customerDelivery.getLocation())); delivery.setDeliveryPriorityId(customerDelivery.getDeliveryPriorityId()); delivery.setLoc(customerData.getLocation()); delivery.setDeliveryOptionCd(customerDelivery.getDeliveryRefOptionCode()); delivery.setDeliveryRouteCd(customerDelivery.getDeliveryRouteCode()); delivery.setTravelTimeCustomer(customerDelivery.getTravelTimeCustomer()); delivery.setDistanceToCustomer(customerDelivery.getDistanceToCustomer()); delivery.setMinAmtFreeDelivery(customerDelivery.getMinAmountFreeDelivery()); delivery.setDeliveryCharge(customerDelivery.getDeliveryCharge()); } if(doesDeletedRecordExists(CustomerDomainTable.CUSTOMER_DELIVERY)) { delivery = buildCustomerDeliveryDeletedRecordDetails(); } context.logDebug(methodSpec + "Customer Delivery = " + delivery); return delivery; } private Previous buildCustomerTableDeletedRecordDetails(final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerMainTableDeleteRecordDetails - "; context.logDebug(methodSpec); Previous previous = null; final String deletedCustomerTableRecord = customerChangeQueueDeletedValue; if (deletedCustomerTableRecord != null && deletedCustomerTableRecord.trim().length() > 0) { final String[] deletedRecordData = deletedCustomerTableRecord.split("\\|", -1); if (deletedRecordData.length == 5) { previous = new Previous(); previous.setDeleted(Boolean.TRUE); String customerId = deletedRecordData[0]; previous.setCustomerId(convertToInt(customerId)); String customerNumber = deletedRecordData[1]; previous.setCustomerNumber(convertToInt(customerNumber)); String globalCustomerId = deletedRecordData[2]; previous.setGlobalCustomerId(convertToInt(globalCustomerId)); String lastModifiedDate = deletedRecordData[3]; previous.setLastModifiedDateTime( DateUtil2.convertStringToEpoch(lastModifiedDate, YYYY_MM_DD_HH_MM_SS_PATTERN)); String modifiedByEmployeeId = deletedRecordData[4]; if (modifiedByEmployeeId != null) { final Employee employee = findEmployeeByEmployeeId( convertToInt(modifiedByEmployeeId)); if (employee != null) { previous.setModifiedByEmployeeName( employee.getFirstName() + " " + employee.getLastName()); previous.setModifiedByEmployeeNumber(employee.getEmployeeNumber()); } } } } if (previous != null) { previous.setMainARStoreNumber(customerData.getMainARStoreNumber()); if (storeProfile != null) { final String storeNumber = storeProfile.getStoreNum(); if (StringUtils.isNotEmpty(storeNumber)) { previous.setStoreNumber(storeNumber); if (storeNumber.length() >= 7) { previous.setStoreDCNumber(storeNumber.substring(0, 7)); } if (storeNumber.length() >= 6) { previous.setStoreShortNumber(storeNumber.substring(6)); } } } if (distributionCenter != null) { previous.setAlphaDCCode(distributionCenter.getAlphaDcCode()); previous.setNapaAcctDCCode(distributionCenter.getNapaAcctDcCode()); } } return previous; } private Delivery buildCustomerDeliveryDeletedRecordDetails() { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.buildCustomerDeliveryDeletedRecordDetails - "; context.logDebug(methodSpec); final String deletedCustomerDeliveryRecord = customerChangeQueueDeletedValue; Delivery delivery = null; if(deletedCustomerDeliveryRecord != null && deletedCustomerDeliveryRecord.trim().length() > 0) { final String[] deletedRecordData = deletedCustomerDeliveryRecord.split("\\|", -1); if (deletedRecordData.length == 9) { delivery = new Delivery(); delivery.setOperation(CustomerChangeQueueAction.DELETE); final String customerId = deletedRecordData[0]; delivery.setCustomerId(convertToInt(customerId)); final String deliveryRefOptionCd = deletedRecordData[1]; delivery.setDeliveryOptionCd(deliveryRefOptionCd); final String deliveryRouteCd = deletedRecordData[2]; delivery.setDeliveryRouteCd(deliveryRouteCd); final String deliveryPriorityId = deletedRecordData[3]; delivery.setDeliveryPriorityId(convertToInt(deliveryPriorityId)); final String travelTimeCustomer = deletedRecordData[4]; delivery.setTravelTimeCustomer(convertToInt(travelTimeCustomer)); final String distanceToCustomer = deletedRecordData[5]; delivery.setDistanceToCustomer(convertToInt(distanceToCustomer)); final String directions = deletedRecordData[6]; delivery.setDirections(directions); final String minAmtFreeDelivery = deletedRecordData[7]; delivery.setMinAmtFreeDelivery(new BigDecimal(minAmtFreeDelivery)); final String deliveryCharge = deletedRecordData[8]; delivery.setDeliveryCharge(new BigDecimal(deliveryCharge)); } } context.logDebug(methodSpec + "Customer Delivery = " + delivery); return delivery; } private void buildCustomerDomainData(final CustomerDomainFeedDetails customerDomainData, final Customer customerData) { final String methodSpec = "[CustomerSync] CustomerDomainDataBuilder.setCustomerDomainData - "; context.logDebug(methodSpec); customerDomainData.setGlobalCustomerId(customerData.getGlobalCustomerId()); customerDomainData.setCustomerId(customerData.getId()); customerDomainData.setModifiedByEmployeeNumber(customerData.getModifiedByEmployeeNumber()); customerDomainData.setModifiedByEmployeeName(customerData.getModifiedByEmployeeName()); customerDomainData.setLastModifiedDateTime(DateUtil2.getEpochValue(customerData.getLastModifiedDate())); customerDomainData.setMainARStoreNumber(customerData.getMainARStoreNumber()); if (storeProfile != null) { final String storeNumber = storeProfile.getStoreNum(); if(StringUtils.isNotEmpty(storeNumber)) { customerDomainData.setStoreNumber(storeNumber); if(storeNumber.length() >= 7) { customerDomainData.setStoreDCNumber(storeNumber.substring(0, 7)); } if(storeNumber.length() >= 6) { customerDomainData.setStoreShortNumber(storeNumber.substring(6)); } } } if (distributionCenter != null) { customerDomainData.setAlphaDCCode(distributionCenter.getAlphaDcCode()); customerDomainData.setNapaAcctDCCode(distributionCenter.getNapaAcctDcCode()); } if (isCustomerAccountRenumbered()) { customerDomainData.setPrevious( buiLdCustomerDomainPreviousRecordDetails(customerDomainData, customerData)); } } private Previous buiLdCustomerDomainPreviousRecordDetails( final CustomerDomainFeedDetails customerDomainData, final Customer customerData) { final Previous previous = new Previous(); previous.setStoreNumber(customerDomainData.getStoreNumber()); previous.setStoreShortNumber(customerDomainData.getStoreShortNumber()); previous.setAlphaDCCode(customerDomainData.getAlphaDCCode()); previous.setNapaAcctDCCode(customerDomainData.getNapaAcctDCCode()); previous.setMainARStoreNumber(customerDomainData.getMainARStoreNumber()); previous.setCustomerNumber(convertToInt(customerChangeQueueDeletedValue.trim())); previous.setEndDate(new Date().getTime()); return previous; } }