package com.genpt.nsight; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; import com.datastax.driver.core.SimpleStatement; import com.genpt.nsight.config.NSightProperties; import com.genpt.nsight.store.ip.StoreIPClient; import com.genpt.nsight.store.ip.model.StoreIPResponse; import com.genpt.nsight.v1.model.*; import com.genpt.nsight.v1.model.dto.SiteDTO; import com.genpt.nsight.v1.model.dto.SiteRelationDTO; import com.genpt.nsight.v3.service.ConfigManagementService; import com.genpt.nsight.v4.AvailabilityServiceContextV4; import com.genpt.nsight.v4.model.DetailRequest; import com.genpt.nsight.v4.model.ProductAvailabilityRequest; import com.genpt.nsight.v4.model.StoreHours; import lombok.Getter; import lombok.Setter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.time.DayOfWeek; import java.time.LocalTime; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @Component @Getter @Setter public class NSightCacheLoader { private static final Logger LOGGER = LoggerFactory.getLogger(NSightCacheLoader.class); @Autowired NSightProperties nSightProperties; @Autowired StoreIPClient storeIPClient; @Autowired Session session; private Map aliasToSiteIdMap; private Map inactiveAliasToSiteIdMap; private Map siteIdToSiteMap; private Map> supplierLocationMap; private Set dcSet; private Set supplierIdSet; //virtual kits data map Map productKitMapUS; Map productKitMapCA; //storeID to store map Map storeIPMap; private Set combinedFriendSet = new HashSet<>(); private Map BuyerIDToSiteMap; private Set dontCallStoreSet = new HashSet<>();; private Set combinedDCSet = new HashSet<>();; private Map UAPDCMap = new HashMap<>(); //private Map> supplierHQMap = new HashMap<>(); private Map displayNameMap = new HashMap<>(); private Map> storeHoursMap = new HashMap<>(); private Map> storeHoursList = new HashMap<>(); private Map zipToTimezoneIDMap = new HashMap<>(); private String invDataSvcPilotStores; private String deliveryDataSvcPilotStores; private String nonNapaStores; Map countryCodeMap; @Autowired ConfigManagementService configManagementService; public void reset() { aliasToSiteIdMap = null; inactiveAliasToSiteIdMap = null; siteIdToSiteMap = null; supplierLocationMap = null; dcSet = null; productKitMapUS = null; productKitMapCA = null; storeIPMap=null; BuyerIDToSiteMap=null; displayNameMap=null; storeHoursMap=null; countryCodeMap=null; //dontCallStoreSet=null; } public void loadAll() { loadTimezoneID(); loadSiteAttributes(); loadSites(); loadRelationships(); loadVirtualKit(); loadStoreIPsNew(); loadBuyerID(); loadUAPDCs(); loadInventoryPilotStores(); loadCountryCodes(); } public void processSiteChanges() { loadTimezoneID(); loadSiteAttributes(); loadSites(); loadRelationships(); loadStoreIPsNew(); loadBuyerID(); loadUAPDCs(); loadInventoryPilotStores(); loadCountryCodes(); } public void reloadHQLineAbbrev( Map siteDTOMap) { this.siteIdToSiteMap = siteDTOMap; loadVirtualKit(); loadStoreIPsNew(); } private boolean loadCountryCodes(){ boolean isSuccess = false; Map countrCodeTempMap = new HashMap<>(); long startTime = System.currentTimeMillis(); LOGGER.info("Application: NSight , Loading CountryCode Map from Cassandra"); SimpleStatement countryStatement = new SimpleStatement("select alpha_3_code, alpha_2_code from country_code;"); int count = 0; ResultSet rsSites = session.execute(countryStatement); while (!rsSites.isExhausted()) { Row row = rsSites.one(); String alpha3Code = row.getString("alpha_3_code"); String alpha2Code = row.getString("alpha_2_code"); countrCodeTempMap.put(alpha3Code, alpha2Code); count++; } LOGGER.info("Application: NSight , Loaded total {} Country Codes , total time: {} ", count, (System.currentTimeMillis() - startTime)); if (count > 0) { isSuccess = true; countryCodeMap =countrCodeTempMap; } return isSuccess; } private boolean loadTimezoneID(){ boolean isSuccess = false; try { //zipToTimezoneIDMap.clear(); Map zipToTimezoneIDMapTemp = new HashMap<>(); long startTime = System.currentTimeMillis(); LOGGER.info("Application: NSight , Loading TimezoneiDs Map from Cassandra"); SimpleStatement vkStatement = new SimpleStatement( "select zip_code, time_zone_id from site_timezone;");//uap_dc_abbrev rtdci_dc_abbrev int count = 0; ResultSet rsSites = session.execute(vkStatement); while (!rsSites.isExhausted()) { Row row = rsSites.one(); String zip_code = row.getString("zip_code"); String time_zone_id = row.getString("time_zone_id"); zipToTimezoneIDMapTemp.put(zip_code, time_zone_id); count++; } LOGGER.info("Application: NSight , Loaded total {} TimezoneiDs , total time: {} ", count, (System.currentTimeMillis() - startTime)); if (count > 0) { isSuccess = true; zipToTimezoneIDMap =zipToTimezoneIDMapTemp; } }catch (Exception ex){ LOGGER.error("Application: NSight , Exception occurred while loading timezoneID's. Exception :{} ",ex); } return isSuccess; } private boolean loadUAPDCs(){ boolean isSuccess = false; try { UAPDCMap.clear(); long startTime = System.currentTimeMillis(); LOGGER.info("Application: NSight , Loading UAP DC Map from Cassandra"); SimpleStatement vkStatement = new SimpleStatement( "SELECT uap_dc_abbrev, rtdci_dc_abbrev FROM uap_dc_map");//uap_dc_abbrev rtdci_dc_abbrev int count = 0; ResultSet rsSites = session.execute(vkStatement); while (!rsSites.isExhausted()) { Row row = rsSites.one(); String uap_dc_abbrev = row.getString("uap_dc_abbrev"); String rtdci_dc_abbrev = row.getString("rtdci_dc_abbrev"); UAPDCMap.put(uap_dc_abbrev, rtdci_dc_abbrev); count++; } LOGGER.info("Application: NSight , Loaded total {} UAPDCs , total time: {} ", count, (System.currentTimeMillis() - startTime)); if (count > 0) { isSuccess = true; } }catch (Exception ex){ LOGGER.error("Application: NSight , Exception occurred while loading UAPDC's. Exception :{} ",ex); } return isSuccess; } private boolean loadSiteAttributes() { boolean isSuccess = false; LOGGER.info("Application: NSight , Loading Site Attributes"); try { Map> storeHoursListTemp = new HashMap<>(); long startTime = System.currentTimeMillis(); LOGGER.info("Application: NSight , Loading Site Attributes from Cassandra"); SimpleStatement vkStatement = new SimpleStatement( "select site_identifier, name,value from site_attributes"); int count = 0; ResultSet rsSites = session.execute(vkStatement); Map tempDisplayNameMap = new HashMap<>(); Map> tempStoreHoursMap = new HashMap<>(); while (!rsSites.isExhausted()) { Row row = rsSites.one(); UUID siteID = row.getUUID("site_identifier"); String attributeName = row.getString("name"); String attributeValue = row.getString("value"); if (attributeName.compareToIgnoreCase("Display Name")==0){ tempDisplayNameMap.put(String.valueOf(siteID), attributeValue); } if (attributeName.contains("NormalStoreHours-") && attributeValue.compareToIgnoreCase("00:00-00:00")!=0 && attributeValue.compareToIgnoreCase("0000-0000")!=0){ //get the entry for this site try { Map siteMap = tempStoreHoursMap.get(String.valueOf(siteID)); if (siteMap == null) { siteMap = new HashMap<>(); } String start = attributeValue.substring(0, attributeValue.indexOf('-')); String end = attributeValue.substring(attributeValue.indexOf('-') + 1, attributeValue.length()); int starthour = Integer.parseInt(start.substring(0, start.indexOf(':'))); int startMin = Integer.parseInt(start.substring(start.indexOf(':') + 1, start.length())); int endhour = Integer.parseInt(end.substring(0, end.indexOf(':'))); int endMin = Integer.parseInt(end.substring(end.indexOf(':') + 1, end.length())); LocalTime startStore = LocalTime.of(starthour, startMin, 0); LocalTime endStore = LocalTime.of(endhour, endMin, 0); StoreHours storeHours = new StoreHours(); storeHours.setOpen(startStore); storeHours.setClose(endStore); String dayofWeek = attributeName.substring(attributeName.indexOf('-') + 1); siteMap.put(dayofWeek.toUpperCase(), storeHours); tempStoreHoursMap.put(String.valueOf(siteID), siteMap); }catch (Exception ex){ LOGGER.info("Application: NSight , Exception for site {} loading store hours ", siteID); } } count++; } LOGGER.info("Application: NSight , Loaded total {} Site Attributes , total time: {} ", count, (System.currentTimeMillis() - startTime)); if (count > 0) { this.displayNameMap = tempDisplayNameMap; this.storeHoursMap=tempStoreHoursMap; isSuccess = true; //move everyting to a list so store hours are sorted EnumSet dows = EnumSet.allOf( DayOfWeek.class ); for (Map.Entry> entry: tempStoreHoursMap.entrySet()) {//iterate each site Map mapByDay = entry.getValue(); ArrayList arrayList = new ArrayList<>(); for (DayOfWeek dow : dows) { StoreHours storeHoursFrommap = mapByDay.get(dow.name()); arrayList.add(storeHoursFrommap); }//end of days for this site storeHoursListTemp.put(entry.getKey(), arrayList); } this.storeHoursList=storeHoursListTemp; } }catch (Exception ex){ LOGGER.info("Application: NSight , Exception occurred while loading site attributes. Exception :{} ",ex); } return isSuccess; } private boolean loadBuyerID() { boolean isSuccess = false; try { long startTime = System.currentTimeMillis(); LOGGER.info("Application: NSight , Loading loadBuyerID from Cassandra"); SimpleStatement vkStatement = new SimpleStatement( "SELECT primary_store_number, buyer_partner_id, account_name FROM buyerid_store_map"); int count = 0; ResultSet rsSites = session.execute(vkStatement); Map tempBuyerMap = new HashMap<>(); while (!rsSites.isExhausted()) { Row row = rsSites.one(); String storeNumber = row.getString("primary_store_number"); String buyerID = row.getString("buyer_partner_id"); String accountName = row.getString("account_name"); tempBuyerMap.put(buyerID, storeNumber + "|" + accountName); count++; } LOGGER.info("Application: NSight , Loaded total {} BuyerIDS , total time: {} ", count, (System.currentTimeMillis() - startTime)); if (count > 0) { this.BuyerIDToSiteMap = tempBuyerMap; isSuccess = true; } }catch (Exception ex){ LOGGER.info("Application: NSight , Exception occurred while loading BuyerID. Exception :{} ",ex); } return isSuccess; } private boolean loadVirtualKit(){ long startTime = System.currentTimeMillis(); boolean isSuccess = false; LOGGER.info("Application: NSight , Loading loadVirtualKitsCassandra"); SimpleStatement vkStatement = new SimpleStatement( "SELECT country, kit_line_abbrev, kit_part_number, component_line_abbrev, component_part_number, kit_part_description, component_quantity_needed FROM virtual_kits"); try { ResultSet rsSites = session.execute(vkStatement); int count = 0; int numberOfPartsUS = 0; int numberOfPartsCA = 0; long start = System.currentTimeMillis(); Map tempProductKitMapUS = new HashMap<>(); Map tempProductKitMapCA = new HashMap<>(); while (!rsSites.isExhausted()) { Row row = rsSites.one(); String country = row.getString("country"); String lineAbbrev = row.getString("kit_line_abbrev"); String partNumber = row.getString("kit_part_number"); String key = lineAbbrev + "-" + partNumber; int quantity = row.getInt("component_quantity_needed"); String component_line_abbrev = row.getString("component_line_abbrev"); String component_part_number = row.getString("component_part_number"); KitComponent kitComponent = new KitComponent(component_line_abbrev, component_part_number, quantity); if(country.compareToIgnoreCase("CAN")==0) { ProductKit productKit = tempProductKitMapCA.get(key); if (productKit == null) { productKit = new ProductKit(new ArrayList<>()); tempProductKitMapCA.put(key, productKit); } productKit.getKitComponents().add(kitComponent); }else{ ProductKit productKit = tempProductKitMapUS.get(key); if (productKit == null) { productKit = new ProductKit(new ArrayList<>()); tempProductKitMapUS.put(key, productKit); } productKit.getKitComponents().add(kitComponent); } count++; } if (count > 0) { isSuccess = true; this.productKitMapUS = tempProductKitMapUS; numberOfPartsUS = productKitMapUS.size(); this.productKitMapCA = tempProductKitMapCA; numberOfPartsCA = productKitMapCA.size(); LOGGER.info("Application: NSight , Loaded total {} VirtualKit Cassandra US records for {} , total time: {} ", count, numberOfPartsUS, (System.currentTimeMillis() - startTime)); LOGGER.info("Application: NSight , Loaded total {} VirtualKit Cassandra CA records for {} , total time: {} ", count, numberOfPartsCA, (System.currentTimeMillis() - startTime)); } else { LOGGER.info("Application: NSight , Not Loading total {} VirtualKit Cassandra US records for {} , total time: {} ", count, numberOfPartsUS, (System.currentTimeMillis() - startTime)); LOGGER.info("Application: NSight , Not Loading total {} VirtualKit Cassandra CA records for {} , total time: {} ", count, numberOfPartsCA, (System.currentTimeMillis() - startTime)); } }catch (Exception e){ LOGGER.info("Application: NSight , Exception occurred while loading VirtualKit. Exception :{} ",e); } return isSuccess; } /** * Function to load all the site data into a Hashmap. Will load the Site data from the Site Table * into multiple hashmaps so that the lookup can be done either by SiteiD or by * alias names/value combination. Also stores all Supplier Site data in a hashmap so we can lookup * Supplier locations by Supplier JDE Identifier */ private void loadSites() { //for the combinedDCSet just clear and repopulate combinedDCSet.clear(); //create temporary maps to populate data HashMap tempSiteIdToSiteMap = new HashMap<>(); HashMap tempAliasToSiteIdMap = new HashMap<>(); HashMap tempInactiveAliasToSiteIdMap = new HashMap<>(); HashMap> tempSupplierLocationMap = new HashMap<>(); Set tempDCSet = new HashSet<>(); Set tempSupplierIdSet = new HashSet<>(); SimpleStatement siteLoadStatement = new SimpleStatement( "SELECT alias_name, alias_value, data_as_of_ts, inventory_snapshot_ts, pricing_type, site_active_flag, site_type, store_partition_key, zip_code, site_identifier, pos_type, pos_url, pos_password, time_zone, site_active_override_flag, city, state, availability_from_store_flag, main_counter_flag, store_alias, country FROM site"); ResultSet rsSites = session.execute(siteLoadStatement); int count = 0; long start = System.currentTimeMillis(); while (!rsSites.isExhausted()) { Row row = rsSites.one(); //site_active_override_flag boolean isSiteActive = row.getBool("site_active_flag"); boolean isNull = row.isNull("site_active_override_flag"); if (!isNull) isSiteActive = row.getBool("site_active_override_flag"); UUID storeUUID = row.getUUID("site_identifier"); String posType = row.getString("pos_type"); String posUrl = row.getString("pos_url"); String posPassword = row.getString("pos_password"); boolean isCityNull = row.isNull("city"); String city = null; if (!isCityNull) city = row.getString("city"); boolean isStateNull = row.isNull("state"); String state = null; if (!isStateNull) state = row.getString("state"); boolean isGetFromStoreNull = row.isNull("availability_from_store_flag"); boolean availability_from_store_flag = false ; if (!isGetFromStoreNull) availability_from_store_flag = row.getBool("availability_from_store_flag"); boolean isMainCounterNull = row.isNull("main_counter_flag"); boolean main_counter_flag = false ; if (!isMainCounterNull) main_counter_flag = row.getBool("main_counter_flag"); boolean isStoreAliasNull = row.isNull("store_alias"); String storeAlias = null; if (!isStoreAliasNull) storeAlias = row.getString("store_alias"); String zipCode = row.getString("zip_code"); String timeZoneID =null; if (zipCode!=null) { if (zipCode.contains("-")) timeZoneID = zipToTimezoneIDMap.get(zipCode.substring(0, zipCode.indexOf("-"))); else timeZoneID = zipToTimezoneIDMap.get(zipCode); if (timeZoneID == null) LOGGER.info("Application: NSight , loadSites:: Site {}, TimezoneID has invalid data for zipcode {} ", storeUUID, zipCode); }else LOGGER.info("Application: NSight , loadSites:: Site {}, Zipcode has invalid data for zipcode {} ", storeUUID, zipCode); //need to store a seperate map of inactive sites if ( storeUUID != null && !isSiteActive) { String siteIdentifier = String.valueOf(storeUUID); String siteAliasName = row.getString("alias_name"); String aliasValue = row.getString("alias_value"); //See if Store exists in SiteMap SiteDTO siteDTO = tempSiteIdToSiteMap.get(siteIdentifier); if(siteDTO == null) { //pass the displayName too and the timezone id siteDTO = new SiteDTO(row.getString("pricing_type"),siteIdentifier,posType, posUrl, posPassword, row.getString("site_type"), row.getString("store_partition_key"), row.getString("zip_code"), new ArrayList<>(),new ArrayList<>(),new HashMap<>(),null,isSiteActive, row.getString("time_zone"), city, state,availability_from_store_flag,main_counter_flag, storeAlias,row.getString("country"),displayNameMap.get(siteIdentifier),timeZoneID); if(siteDTO.getSiteIdentifier() == null && siteDTO.getSiteType() == null || siteDTO.getSiteIdentifier() == null) { continue; } tempSiteIdToSiteMap.put(siteDTO.getSiteIdentifier(), siteDTO); } tempInactiveAliasToSiteIdMap.put(siteAliasName + "|" + aliasValue, siteIdentifier);//populate the map for the Aliases if(aliasValue != null) { siteDTO.getSiteIdentifierList().add(new SiteIdentifier(siteAliasName, aliasValue.split("%")[0],"")); } } //store active sites in active site map if ( storeUUID != null && isSiteActive) { String siteIdentifier = String.valueOf(storeUUID); String siteAliasName = row.getString("alias_name"); String aliasValue = row.getString("alias_value"); //See if Store exists in SiteMap SiteDTO siteDTO = tempSiteIdToSiteMap.get(siteIdentifier); if(siteDTO == null) { siteDTO = new SiteDTO(row.getString("pricing_type"),siteIdentifier,posType, posUrl, posPassword, row.getString("site_type"), row.getString("store_partition_key"), row.getString("zip_code"), new ArrayList<>(),new ArrayList<>(),new HashMap<>(),null,isSiteActive,row.getString("time_zone"), city, state,availability_from_store_flag,main_counter_flag, storeAlias,row.getString("country"),displayNameMap.get(siteIdentifier),timeZoneID); if(siteDTO.getSiteIdentifier() == null && siteDTO.getSiteType() == null || siteDTO.getSiteIdentifier() == null) { continue; } tempSiteIdToSiteMap.put(siteDTO.getSiteIdentifier(), siteDTO); } tempAliasToSiteIdMap.put(siteAliasName + "|" + aliasValue, siteDTO.getSiteIdentifier());//populate the map for the Aliases //System.out.println("Added to Site Active Map: " + site.siteIdentifier+" "+site.site_active_flag); //need to populate the reverse based on site ID's //we will add only aliases that are for active sites if(aliasValue != null) { siteDTO.getSiteIdentifierList().add(new SiteIdentifier(siteAliasName, aliasValue.split("%")[0],"")); } if(siteDTO.getSiteType()!=null) { //lets add the map to populate the supplier locations for the JDE identifier if (siteDTO.getSiteType().equalsIgnoreCase("Supplier") && siteAliasName.equalsIgnoreCase("Supplier JDE Identifier")) { //System.out.println("Found Supplier: " + site.toString()); String[] keys = aliasValue.split("%"); if (keys.length > 1) { //System.out.println("Need to lookup Array for ID: " + keys[0] + " and Location: " + site.siteIdentifier); ArrayList locationArray = tempSupplierLocationMap.get(keys[0]); if (locationArray != null) { //System.out.println("Array exists for ID: " + keys[0] + " with size: " + locationArray.size()); locationArray.add(siteDTO.getSiteIdentifier()); tempSupplierLocationMap.put(keys[0], locationArray); } else { //System.out.println("Array DOES NOT exists for ID: " + keys[0]); locationArray = new ArrayList<>(); locationArray.add(siteDTO.getSiteIdentifier()); tempSupplierLocationMap.put(keys[0], locationArray); } } else LOGGER.info("Application: NSight , loadSites::Supplier has invalid alias values... " ); if (siteDTO.getSiteIdentifier() != null && siteDTO.getSiteIdentifier().length() > 0) { tempSupplierIdSet.add(siteDTO.getSiteIdentifier()); } }//end of is a supplier if (siteDTO.getSiteType().equalsIgnoreCase("DC")) { //add the DC to the map if (siteDTO.getSiteIdentifier() != null && siteDTO.getSiteIdentifier().length() > 0) { tempDCSet.add(siteDTO.getSiteIdentifier()); // add the combined DC is present if (siteAliasName.compareToIgnoreCase("DC Abbreviation Code")==0) if (nSightProperties.getCombineDCList().contains(","+aliasValue+",")) combinedDCSet.add(siteDTO.getSiteIdentifier()); } } } else LOGGER.info("Application: NSight , loadSites:: Site type can not be null" ); } count++; } //Reassign HQLineAbbrev if(getSiteIdToSiteMap() != null) { tempSiteIdToSiteMap.forEach((k, v) -> { SiteDTO existing = getSiteIdToSiteMap().get(k); if(existing != null) { v.setHqLineAbbrevMapping(existing.getHqLineAbbrevMapping()); } }); } //now assign the Global maps with the newly populated data only if we have got data if (count > 0) { setSiteIdToSiteMap(tempSiteIdToSiteMap); setAliasToSiteIdMap(tempAliasToSiteIdMap); setInactiveAliasToSiteIdMap(tempInactiveAliasToSiteIdMap); setSupplierLocationMap(tempSupplierLocationMap); setDcSet(tempDCSet); setSupplierIdSet(tempSupplierIdSet); } LOGGER.info("Application: NSight , loadSites::Loaded Total sites into Hashmap: {} , total time in ms : {} ", count, (System.currentTimeMillis() - start)); LOGGER.info("Application: NSight , loadSites::Loaded Total Suppliers in SupplierMap: {} ", tempSupplierLocationMap.size()); } /** * Function to Load All Site Relationships into a HashMap. */ private void loadRelationships() { int count = 0; SimpleStatement siteRelLoadStatement = new SimpleStatement("SELECT site_identifier, relationship_type, related_site_identifier, related_site_type, related_store_partition_key, relationship_rank FROM site_relationship"); ResultSet rsSiteRels = session.execute(siteRelLoadStatement); long start = System.currentTimeMillis(); while (!rsSiteRels.isExhausted()) { Row row = rsSiteRels.one(); UUID siteUUID = row.getUUID("site_identifier"); if(siteUUID != null) { String siteId = String.valueOf(siteUUID); String relatedSiteID = String.valueOf(row.getUUID("related_site_identifier")); SiteDTO relatedSiteDTO = getSiteIdToSiteMap().get(relatedSiteID); if (relatedSiteDTO == null) { LOGGER.warn("Related Site Identifier is NULL for : {} ", relatedSiteID ); }else { SiteRelationDTO siteRelation = new SiteRelationDTO(row.getString("relationship_type"), relatedSiteID, row.getString("related_site_type"), row.getString("related_store_partition_key"), row.getInt("relationship_rank"), relatedSiteDTO.getPosType(), relatedSiteDTO.getPosURL(), relatedSiteDTO.getPosPassword(),relatedSiteDTO.getRetrieveFromStore()); if (siteRelation.getRelatedSiteIdentifier() == null || siteRelation.getRelatedSiteType() == null || siteRelation.getRelationshipType() == null) { continue; } SiteDTO siteDTO = getSiteIdToSiteMap().get(siteId); if (siteDTO != null) { siteDTO.getSiteRelationDTOList().add(siteRelation); if ("Primary DC".equalsIgnoreCase(siteRelation.getRelationshipType())) { siteDTO.setPrimaryDCSiteId(siteRelation.getRelatedSiteIdentifier()); } if ("Combined Inventory Friends".equalsIgnoreCase(siteRelation.getRelationshipType())) { combinedFriendSet.add(siteId); } count++; } }//else not null related site id } } LOGGER.info("Application: NSight , loadRelationships::Loaded Total Relationships into Hashmap: {} , total time in ms : {} ", count, (System.currentTimeMillis() - start)); } private void loadStoreIPsNew() { long startTime = System.currentTimeMillis(); //write to file // String fileName = System.getProperty("instance-name"); String fileName = nSightProperties.getStoreipfile(); LOGGER.info("Application: NSight , Loading StoreIPs using StoreIP service"); dontCallStoreSet.clear(); Map tempStoreMap = new HashMap<>(); int count=0; try { LOGGER.info("Application: NSight , Begin invoking StoreIP service"); StoreIPResponse storeIPResponse = storeIPClient.getStoreIP("ALL"); if(storeIPResponse!= null) count = storeIPResponse.getStoreLookupResponse().getStoreList().size(); if(count < nSightProperties.getStoreIPThreshold()) LOGGER.error("Application: NSight , Avoiding cache refresh as storeIP Threshold not met. Count of storeip's returned by service {} ", count); if (storeIPResponse !=null && count >= nSightProperties.getStoreIPThreshold()) { //create the file used for backup loads /* BufferedWriter writer = null; try {// exceptions with file should not affect normal processing writer = new BufferedWriter(new FileWriter(fileName)); } catch (IOException e) { e.printStackTrace(); } */ storeIPResponse.getStoreLookupResponse().getStoreList().forEach(store ->{ String active_flag = store.getActiveFlag(); if (active_flag !=null && active_flag.compareToIgnoreCase("false")==0) dontCallStoreSet.add(store.getStoreId()); tempStoreMap.put(store.getStoreId(), store.getStoreIp()); }); LOGGER.info("Application: NSight , Completed loading store IPs to cache: {} , total time: {} ", count , (System.currentTimeMillis() - startTime) ); //Now write to file /* final BufferedWriter finalWriter = writer; tempStoreMap.forEach((storeID, storeIP) ->{ String line = storeID + "," + storeIP; if (finalWriter != null) { try { finalWriter.write(line); finalWriter.newLine(); } catch (IOException e) { e.printStackTrace(); } } } ); if (finalWriter != null) finalWriter.close();*/ } else { //read from file LOGGER.info("Application: NSight , Loading StoreIPs from " + fileName); try (Stream stream = Files.lines(Paths.get(fileName))) { StringBuilder contentBuilder = new StringBuilder(); stream.forEach(s -> contentBuilder.append(s).append("|")); String allLines = contentBuilder.toString(); String lines[] = allLines.split("\\|"); count = lines.length; if(count >= nSightProperties.getStoreIPThreshold()) { for (int i = 0; i < lines.length ;i++){ String currentLine = lines[i]; if (!currentLine.contains("STORE_ID")) { String storeID = currentLine.substring(1, currentLine.indexOf("\",")); String storeIP = currentLine.substring(currentLine.indexOf(",") + 2, currentLine.length()); storeIP = storeIP.substring(0, storeIP.indexOf("\",")); tempStoreMap.put(storeID, storeIP); } } } else { LOGGER.error("Application: NSight , Avoiding cache refresh as storeIP Threshold not met. Total Number of entries found in files {} ", lines.length); } } catch (IOException e) { e.printStackTrace(); } } if (count > 0) {// got data /* if (this.storeIPMap != null) { int existingCount = this.storeIPMap.size(); if (existingCount > 0) { int percentageCount = (count / existingCount) * 100; if (percentageCount > 90) this.storeIPMap = tempStoreMap; else LOGGER.error("Threshold not met while loading StoreIps , Existing Count : {}, Current Count: {} ", existingCount, count); } }else*/ this.storeIPMap = tempStoreMap; }else LOGGER.error(" StoreIps Not Loaded, Current Count: {} ",count); } catch (Exception e) { LOGGER.error("Error while loading StoreIps , Message : {}, StackTrace: {} ", e.getMessage(), e.getStackTrace()); } } public void loadInventoryPilotStores(){ try { AvailabilityServiceContextV4 availabilityServiceContextV4 = new AvailabilityServiceContextV4(); ProductAvailabilityRequest productAvailabilityRequest = new ProductAvailabilityRequest(); HeaderRequest headerRequest = new HeaderRequest(); headerRequest.setCorrelationId("NSightProductAvailability"+System.currentTimeMillis()); headerRequest.setCountryCode("US"); headerRequest.setLanguageCode("EN"); Requestor requestor = new Requestor(); RequestorIdentifier requestorIdentifier = new RequestorIdentifier(); requestorIdentifier.setType("NSight"); requestorIdentifier.setValue("NSight"); requestor.setRequestorIdentifier(requestorIdentifier); headerRequest.setRequestor(requestor); productAvailabilityRequest.setHeaderRequest(headerRequest); com.genpt.nsight.v4.model.DetailRequest detailRequest = new DetailRequest(); detailRequest.setParts(new HashSet<>()); productAvailabilityRequest.setDetailRequest(detailRequest); availabilityServiceContextV4.setRequest(productAvailabilityRequest); String response = configManagementService.getPilotStoresV4(availabilityServiceContextV4,"InvDataSvcPilotStores"); LOGGER.info("Loaded InvDataSvcPilotStores Pilot Stores: {}", response); setInvDataSvcPilotStores(response!=null?response:""); response = configManagementService.getPilotStoresV4(availabilityServiceContextV4,"DeliveryDataSvcPilotStores"); LOGGER.info("Loaded DeliveryDataSvcPilotStores Pilot Stores: {}", response); setDeliveryDataSvcPilotStores(response!=null?response:""); response = configManagementService.getPilotStoresV4(availabilityServiceContextV4,"NONNAPA_STORELIST"); LOGGER.info("Loaded NONNAPA_STORELIST Pilot Stores: {}", response); setNonNapaStores(response!=null?response:""); } catch (Exception e) { throw new RuntimeException(e); } } }