// Get Subscribed fields for partners for extract type
List partnerFieldSubscriptionList = adminService
.getSubscribeFieldsByExtractTypeId(Constants.PRODUCT_CORE_EXTRACT_TYPE_ID, batchIdList,
extractorRequest);
for (PartnerFieldSubscriptionResponse partnerFieldSubscriptionResponse : partnerFieldSubscriptionList) {
subscribedFieldsMapForPartner.put(partnerFieldSubscriptionResponse.getFrachiseNumber(),
partnerFieldSubscriptionResponse.getSubscribedFields());
}
return subscribedFieldsMapForPartner;
}
code
private List<ProductDataResponse> getsubscribedFieldByPartner(List<ProductDataResponse> productResponseList,
List<String> listOfSubscribedFields, Boolean cnhProductWeightIsActive) {
List<ProductDataResponse> productDataResponseList = new ArrayList<>();
if (listOfSubscribedFields != null && !listOfSubscribedFields.isEmpty()) {
ObjectMapper productDataResponseMapper = new ObjectMapper();
for (ProductDataResponse productResponse : productResponseList) {
Map<String, Object> productResponseMap = productDataResponseMapper.convertValue(productResponse,
Map.class);
Map<String, Object> partnerSubscribedResponseMap = new HashMap<>();
for (String subscribedField : listOfSubscribedFields) {
partnerSubscribedResponseMap.put(subscribedField, productResponseMap.get(subscribedField));
}
ProductDataResponse structuredObject = productDataResponseMapper
.convertValue(partnerSubscribedResponseMap, ProductDataResponse.class);
Map<String, Object> responseMap = createSubscribedFieldJson(productResponseList,structuredObject,partnerSubscribedResponseMap,cnhProductWeightIsActive);
ProductDataResponse finalObject = productDataResponseMapper
.convertValue(responseMap, ProductDataResponse.class);
finalObject.setProductId(productResponse.getProductId());
finalObject.setBatchId(productResponse.getBatchId());
finalObject.setFranchiseNumber(productResponse.getFranchiseNumber());
productDataResponseList.add(finalObject);
}
}
return productDataResponseList;
}
/**
* getDataForExtract Method - get the data from different source to assemble in the form of ProductDataResponse pojo class
* @param invalidProductIds - gives the list of unprocessed productId
* @param franchiseProductsMap
* @param franchiseOrderedVarinatIds
* @param channelVisorIsAcive
* @param cnhProductWeightIsActive
* @param estimatedServiceResponseMap - to populate the estimated delivery date field for all the partner
* @return
*/
public Map<Integer, List<ProductDataResponse>> getDataForExtract(List<String> invalidProductIds,
Map<String, List<String>> productVariantIdMap, List<ExtractorRequest> extractorRequest,
List<Integer> batchIdList, Boolean cnhProductWeightIsActive) {
Map<Integer, List<ProductDataResponse>> coreExtractResponse = new HashMap<>();
List<ProductDataResponse> productResponseList = new ArrayList<>();
try {
List<ProductStagingResponse> responseList = subscriptionService.getProductsForExtract(batchIdList,
extractorRequest);
logger.info("the staging table response size is :" + responseList.size());
if (responseList == null || responseList.isEmpty()) {
logger.info("No records in staging to be extracted");
return null;
}
List<String> productIdCollection = new ArrayList<>();
for (ProductStagingResponse i : responseList) {
productIdCollection.add(i.getProductId());
}
franchiseProductsMap = responseList.stream()
.collect(Collectors.groupingBy(x -> x.getFranchiseNumber()));
Map<String, List<String>> seasonProductsMap = new HashMap<>();
Map<Integer, Map<String, List<String>>> franchiseSeasonProductsMap = new HashMap<>();
List<String> stagingProductIds = new ArrayList<>();
List<String> productIds = productIdCollection.stream().distinct().collect(Collectors.toList());
List<String> seasons = new ArrayList<>();
// to check the varinats count
// List<String> stagedVariantIds = new ArrayList<>();
for (Map.Entry<Integer, List<ProductStagingResponse>> eachEntry : franchiseProductsMap.entrySet()) {
List<ProductStagingResponse> list = eachEntry.getValue();
List<String> productNum = new ArrayList<>();
List<String> orderedVariantIdList = new ArrayList<>();
for (ProductStagingResponse eachRecord : list) {
productNum.add(eachRecord.getProductId());
// Forming franchiseSeasonProductsMap
if (!stagingProductIds.contains(eachRecord.getProductId())) {
stagingProductIds.add(eachRecord.getProductId());
}
if (!seasons.contains(eachRecord.getSeason())) {
seasons.add(eachRecord.getSeason());
}
if (seasonProductsMap != null && !seasonProductsMap.isEmpty()
&& seasonProductsMap.get(eachRecord.getSeason()) != null) {
seasonProductsMap.get(eachRecord.getSeason()).add(eachRecord.getProductId());
} else {
List<String> products = new ArrayList<>();
products.add(eachRecord.getProductId());
seasonProductsMap.put(eachRecord.getSeason(), products);
}
// Creating the map to get the ordered products variantIds
if (eachRecord.getVariantIds() != null && !eachRecord.getVariantIds().isEmpty()) {
if (!productVariantIdMap.containsKey(eachRecord.getProductId())) {
productVariantIdMap.put(eachRecord.getProductId(), eachRecord.getVariantIds());
orderedVariantIdList.addAll(eachRecord.getVariantIds());
} else {
productVariantIdMap.get(eachRecord.getProductId()).addAll(eachRecord.getVariantIds());
orderedVariantIdList.addAll(eachRecord.getVariantIds());
}
}
}
franchiseSeasonProductsMap.put(eachEntry.getKey(), seasonProductsMap);
}
List<ProductSeasonality> productSeasonalityResponseList = cnhService
.getSeasonalityCollection(seasonProductsMap, batchIdList, extractorRequest);
if (productSeasonalityResponseList == null || productSeasonalityResponseList.isEmpty()) {
logger.info("No records from product seasonality service");
return null;
}
logger.info(
"the finalised productSeasonalityResponseList size is :" + productSeasonalityResponseList.size());
Map<String, List<ProductSeasonality>> productSeasonalityMap = new HashMap<>();
Map<String, String> primarySizeDescMap = cnhService.getPrimarySizeData(batchIdList, extractorRequest);
Map<String, String> secondarySizeDescMap = cnhService.getSecondarySizeData(batchIdList, extractorRequest);
Map<String, PackDefinitionDTO> weaVariantPackDefinitionMap = new HashMap<>();
//IBT Service to get the plan A Raw material Attribute
Map<String, AttrServiceResponse> attrMap = cnhService.getAttributes(productIds, batchIdList, extractorRequest);
//Generate productVariantWeightDimensionMap
if(cnhProductWeightIsActive) {
weaVariantPackDefinitionMap = generateProductVariantWeightDimensionMap(productIds, weaVariantPackDefinitionMap);
}
countryNumMap = ibtService.getCOOForPartners(batchIdList, extractorRequest, franchiseSeasonProductsMap);
// ES service calling
List<String> variantId = new ArrayList<>();
Map<String, String> primarySizeDescIndexMap = new HashMap<>();
Map<String, String> variantGtinMap = new HashMap<>();
Map<String, String> secondarySizeDescIndexMap = new HashMap<>();
if (productSeasonalityResponseList != null && !productSeasonalityResponseList.isEmpty()) {
productSeasonalityMap = productSeasonalityResponseList.stream()
.collect(Collectors.groupingBy(x -> x.getProductId()));
logger.info("the finalised product list size is :" + productIds.size());
for (String Id : productIds) {
List<ProductSeasonality> variant = productSeasonalityMap.get(Id);
if (variant != null && !variant.isEmpty()) {
Map<String, ProductSeasonality> variantSeasonDataMap = variant.stream().distinct()
.collect(Collectors.toMap(x -> x.getSeason().getSeasonName(), x -> x));
for (String oneSeason : seasons) {
ProductSeasonality prductSeasonlity = variantSeasonDataMap.get(oneSeason);
if (variantSeasonDataMap.get(oneSeason) != null) {
for (int i = 0; i < prductSeasonlity.getProductVariants().size(); i++) {
if (prductSeasonlity.getProductVariants() != null
&& !prductSeasonlity.getProductVariants().isEmpty()) {
if (prductSeasonlity.getProductVariants().get(i).getActiveIndicator() == null
|| prductSeasonlity.getProductVariants().get(i)
.getActiveIndicator() == 1) {
variantId.add(prductSeasonlity.getProductVariants().get(i).getVariantId());
String priValues = prductSeasonlity.getProductVariants().get(i)
.getPrimarySizeIndex() + "-"
+ prductSeasonlity.getProductVariants().get(i)
.getPrimarySizeRange();
if (priValues.charAt(0) == '0') {
priValues = priValues.substring(1);
}
if (!primarySizeDescIndexMap.containsKey(
prductSeasonlity.getProductVariants().get(i).getVariantId())) {
primarySizeDescIndexMap.put(
prductSeasonlity.getProductVariants().get(i).getVariantId(),
primarySizeDescMap.get(priValues));
}
String secValues = prductSeasonlity.getProductVariants().get(i)
.getSecondarySizeIndex() + "-"
+ prductSeasonlity.getProductVariants().get(i)
.getSecondarySizeRange();
if (prductSeasonlity.getProductVariants().get(i).getSecondarySizeIndex()
.length() != 1 && secValues.charAt(0) == '0') {
secValues = secValues.substring(1);
}
if (!secondarySizeDescIndexMap.containsKey(
prductSeasonlity.getProductVariants().get(i).getVariantId())) {
secondarySizeDescIndexMap.put(
prductSeasonlity.getProductVariants().get(i).getVariantId(),
secondarySizeDescMap.get(secValues));
}
if (!variantGtinMap.containsKey(
prductSeasonlity.getProductVariants().get(i).getVariantId())) {
variantGtinMap.put(
prductSeasonlity.getProductVariants().get(i).getVariantId(),
prductSeasonlity.getProductVariants().get(i).getGtinNo());
}
}
}
}
}
}
} else {
invalidProductIds.add(Id);
}
}
logger.info("variantGtinMap size is " + variantGtinMap.size());
logger.info(invalidProductIds + " invalidProductIds found in table");
}
List<String> variantIds = variantId.stream().distinct().collect(Collectors.toList());
List<Products> esSeriveResponse = esService.getVariantCollection(variantIds, batchIdList, extractorRequest);
Map<String, List<Products>> esSeriveResponseMap = new HashMap<>();
if (esSeriveResponse != null && !esSeriveResponse.isEmpty()) {
esSeriveResponseMap = esSeriveResponse.stream().collect(Collectors.groupingBy(x -> x.getProductId()));
}
logger.info("esSeriveResponseMap size is: " + esSeriveResponseMap.size());
if (productSeasonalityResponseList != null && !productSeasonalityResponseList.isEmpty()) {
mapProductDataResponse(productSeasonalityMap, productIds, seasons, variantIds, productResponseList,
esSeriveResponseMap, primarySizeDescIndexMap, secondarySizeDescIndexMap, variantGtinMap, attrMap,
batchIdList, extractorRequest, weaVariantPackDefinitionMap,cnhProductWeightIsActive);
}
Map<Integer, List<String>> franchiseProductIdMap = new HashMap<>();
for (ProductStagingResponse response : responseList) {
List<String> prductIds = new ArrayList<>();
if (!franchiseProductIdMap.containsKey(response.getFranchiseNumber())) {
prductIds.add(response.getProductId());
franchiseProductIdMap.put(response.getFranchiseNumber(), prductIds);
} else {
if (!franchiseProductIdMap.get(response.getFranchiseNumber()).contains(response.getProductId())) {
franchiseProductIdMap.get(response.getFranchiseNumber()).add(response.getProductId());
}
}
}
if (productResponseList != null && !productResponseList.isEmpty()) {
for (Map.Entry<Integer, List<String>> map : franchiseProductIdMap.entrySet()) {
List<ProductDataResponse> productDataList = new ArrayList();
List<String> productList = map.getValue();
for (int i = 0; i < productList.size(); i++) {
for (int j = 0; j < productResponseList.size(); j++) {
if (productResponseList.get(j).getProductId().equalsIgnoreCase(productList.get(i))
&& productResponseList.get(j) != null) {
productDataList.add(productResponseList.get(j));
}
}
}
if (productDataList != null && !productDataList.isEmpty()) {
coreExtractResponse.put(map.getKey(), productDataList);
}
}
}
} catch (Exception e) {
logger.error("Error occured while mapping the response", e);
throw new InternalServerError("Internal Server Error");
}
return coreExtractResponse;
}
private Map<String, PackDefinitionDTO> generateProductVariantWeightDimensionMap(List<String> productIdList, Map<String, PackDefinitionDTO> weaVariantPackDefinitionMap) {
for (int i=0;i<productIdList.size();i+=Constants.PRODUCT_WEIGHT_RECORD_PER_REQUEST) {
// Calling CnhProductPackService for getting weight and dimensions
int subIndex = (i + Constants.PRODUCT_WEIGHT_RECORD_PER_REQUEST) > productIdList.size() ? productIdList.size()
: (i + Constants.PRODUCT_WEIGHT_RECORD_PER_REQUEST);
List<String> productIdSubList = productIdList.subList(i, subIndex);
ProductWeightRequest productWeightRequest = new ProductWeightRequest();
productWeightRequest.setProductIds(productIdSubList);
CnhProductPackServiceResponse cnhProductPackServiceResponseList = cnhService
.getProductWehightProductPackService(productWeightRequest);
if(cnhProductPackServiceResponseList != null && cnhProductPackServiceResponseList.getResponse()!=null) {
for(ResponseDTO cnhProductPackServiceResponse : cnhProductPackServiceResponseList.getResponse() )
{
weaVariantPackDefinitionMap.putAll(cnhProductPackServiceResponse.getPackDetails().stream()
.filter(packDetail -> "WEA".equals(packDetail.getPackType()))
.flatMap(packDetail -> packDetail.getPackDefinition().stream()).collect(Collectors
.toMap(PackDefinitionDTO::getVariantArticleNumber, packDefinition -> packDefinition)));
}
}else {
logger.error("Article Variant does not have weight and dimension details {}", productIdSubList);
}
}
return weaVariantPackDefinitionMap;
}
/**
* Final Response to be mapped from ES, CNH and IBT Service data
*
* @param productSeasonalityMap
* @param productIds
* @param seasons
* @param attrMap
* @param extractorRequest
* @param batchIdList
* @param cnhProductWeightIsActive
* @param estimatedServiceResponseMap
* @throws MandatoryFieldException
*/
private void mapProductDataResponse(Map<String, List<ProductSeasonality>> productSeasonalityMap,
List<String> productIds, List<String> seasons, List<String> variantIds,
List<ProductDataResponse> productResponseList, Map<String, List<Products>> esSeriveResponseMap,
Map<String, String> primarySizeDescIndexMap, Map<String, String> secondarySizeDescIndexMap,
Map<String, String> variantGtinMap, Map<String, AttrServiceResponse> attrMap, List<Integer> batchIdList, List<ExtractorRequest> extractorRequest, Map<String, PackDefinitionDTO> weaVariantPackDefinitionMap, Boolean cnhProductWeightIsActive)
throws MandatoryFieldException {
for (String productId : productIds) {
if (productSeasonalityMap != null && productSeasonalityMap.get(productId) != null) {
ProductDataResponse productData = new ProductDataResponse();
List<ProductSeasonality> products = productSeasonalityMap.get(productId);
Map<String, ProductSeasonality> seasonDataMap = products.stream().distinct()
.collect(Collectors.toMap(x -> x.getSeason().getSeasonName(), x -> x));
//Adding product Level data
productData.setProductId(productId);
productData.setDept(products.get(0).getDepartment());
productData.setPrimSizeRange(products.get(0).getPrimarySizeRange());
productData.setSecSizeRange(products.get(0).getSecondarySizeRange());
productData.setMerchandCategory(products.get(0).getMerchandiseCat());
productData.setStrokeNo(products.get(0).getStrokeNum());
productData.setItem(products.get(0).getHierarchy().getValue());
Color colour = new Color();
colour.setColourCode(products.get(0).getColour().getColourCode());
colour.setColourDesc(products.get(0).getColour().getColourDescription());
productData.setColour(colour);
List<ProductDescriptions> productDescription = new ArrayList<>();
List<Description> description = new ArrayList<>();
ProductDescriptions pc = new ProductDescriptions();
pc.setLanguage(Constants.LANGUAGE);
Description desc1 = new Description();
desc1.setDescType(Constants.SHORT);
desc1.setDesc(products.get(0).getProductDescription().getShortDesc());
description.add(desc1);
Description desc2 = new Description();
desc2.setDescType(Constants.LONG);
desc2.setDesc(products.get(0).getProductDescription().getLongDesc());
description.add(desc2);
pc.setDescriptions(description);
productDescription.add(pc);
productData.setProductDesc(productDescription);
for(Attributes attEntry : products.get(0).getAttributes()) {
if(attEntry.getAttTypeDesc().equalsIgnoreCase("PRODUCT TYPE (C)")) {
productData.setProductTypeC(attEntry.getAttDesc());
break;
}
}
if(attrMap != null && !attrMap.isEmpty() && attrMap.get(productId) != null) {
if(attrMap.get(productId).getPlanARawMaterial() != null
&& !attrMap.get(productId).getPlanARawMaterial().isEmpty() && !attrMap.get(productId).getPlanARawMaterial().equalsIgnoreCase("NA")) {
productData.setPlanARawMaterial(attrMap.get(productId).getPlanARawMaterial());
}
if(attrMap.get(productId).getProductShapeEcom() != null
&& !attrMap.get(productId).getProductShapeEcom().isEmpty() && !attrMap.get(productId).getProductShapeEcom().equalsIgnoreCase("NA")) {
productData.setProductShapeEcom(attrMap.get(productId).getProductShapeEcom());
}
}
mapSeasonaldata(productData,seasonDataMap,esSeriveResponseMap, primarySizeDescIndexMap, secondarySizeDescIndexMap, weaVariantPackDefinitionMap,cnhProductWeightIsActive);
productResponseList.add(productData);
}
}
}
private void mapSeasonaldata(ProductDataResponse productData, Map<String, ProductSeasonality> seasonDataMap, Map<String, List<Products>> esSeriveResponseMap, Map<String, String> primarySizeDescIndexMap, Map<String, String> secondarySizeDescIndexMap,
Map<String, PackDefinitionDTO> weaVariantPackDefinitionMap, Boolean cnhProductWeightIsActive) {
// TODO Auto-generated method stub
List<ProductCoreSeason> seasonBlockDataList = new ArrayList<>();
List<String> missingGtinsVariantId = new ArrayList<>();
for(Map.Entry<String, ProductSeasonality> seasonLevelEntry: seasonDataMap.entrySet()) {
ProductCoreSeason seasonBlockData = new ProductCoreSeason();
seasonBlockData.setSeasonName(seasonLevelEntry.getKey());
List<Variant> activeVariantList = new ArrayList<>();
for(ProductVariant entry: seasonLevelEntry.getValue().getProductVariants()) {
if(entry.getActiveIndicator()== null || entry.getActiveIndicator()==1) {
Variant activeVariant = new Variant();
activeVariant.setProductVariantId(entry.getVariantId());
activeVariant.setPrimSizeDesc(primarySizeDescIndexMap.get(entry.getVariantId()));
activeVariant.setSecSizeDesc(secondarySizeDescIndexMap.get(entry.getVariantId()));
if (cnhProductWeightIsActive && weaVariantPackDefinitionMap.containsKey(entry.getVariantId())) {
PackDefinitionDTO packDefinition = weaVariantPackDefinitionMap.get(entry.getVariantId());
ProductPack productPack = new ProductPack();
productPack.setProductWeight(packDefinition.getGrossWeight());
productPack.setLength(packDefinition.getLength());
productPack.setWidth(packDefinition.getWidth());
productPack.setHeight(packDefinition.getHeight());
productPack.setUnitOfDimension(packDefinition.getUnitOfDimension());
productPack.setUnitOfWeight(packDefinition.getUnitOfWeight());
activeVariant.setProductPack(productPack);
}
List<Barcode> barcodesList = new ArrayList<>();
Barcode barcodes = new Barcode();
barcodes.setCategory(Constants.CATEGORY_GTIN);
barcodes.setType(Constants.TYPE_GTIN);
if(entry.getGtinNo()!= null) {
barcodes.setValue(entry.getGtinNo());
} else {
// adding the productId to get missing Gtins
missingGtinsVariantId.add(entry.getVariantId());
}
barcodesList.add(barcodes);
if (null !=esSeriveResponseMap && !esSeriveResponseMap.isEmpty() && null != esSeriveResponseMap.get(entry.getVariantId())) {
if(null!=esSeriveResponseMap.get(entry.getVariantId()).get(0).getCustoms() && null!=esSeriveResponseMap.get(entry.getVariantId()).get(0).getCustoms().getCommodityCode() && !esSeriveResponseMap.get(entry.getVariantId()).get(0).getCustoms().getCommodityCode().isEmpty()) {
seasonBlockData.setHsn(
esSeriveResponseMap.get(entry.getVariantId()).get(0).getCustoms().getCommodityCode());
}
for (int j = 0; j < esSeriveResponseMap.get(entry.getVariantId()).get(0).getVersion().size(); j++) {
if (0 == esSeriveResponseMap.get(entry.getVariantId()).get(0).getVersion().get(j).getVersion()) {
Barcode barcodes1 = new Barcode();
barcodes1.setCategory(Constants.CATEGORY_UPC);
barcodes1.setType(Constants.TYPE_UPC);
if (esSeriveResponseMap.get(entry.getVariantId()).get(0).getVersion().get(j)
.getBarcodes() != null
&& esSeriveResponseMap.get(entry.getVariantId()).get(0).getVersion().get(j).getBarcodes()
.getUPC() != null
&& !esSeriveResponseMap.get(entry.getVariantId()).get(0).getVersion().get(j)
.getBarcodes().getUPC().isEmpty()) {
barcodes1.setValue(esSeriveResponseMap.get(entry.getVariantId()).get(0).getVersion().get(j)
.getBarcodes().getUPC().get(0));
barcodesList.add(barcodes1);
}
}
}
}
activeVariant.setBarcodes(barcodesList);
activeVariantList.add(activeVariant);
}
}
seasonBlockData.setVariants(activeVariantList);
seasonBlockDataList.add(seasonBlockData);
}
productData.setSeasons(seasonBlockDataList);
try {
if (missingGtinsVariantId.size() > 0) {
List<String> missingGtinNVariantId = missingGtinsVariantId.stream().distinct()
.collect(Collectors.toList());
throw new Exception("Gtins Missing " + missingGtinNVariantId);
}
} catch (Exception e) {
MandatoryFieldException mandatoryFieldException = new MandatoryFieldException(e);
mandatoryFieldException.logErrorMessage();
}
}
update below test code based on above class so that ....this is populuated activeVariant.setPrimSizeDesc(primarySizeDescIndexMap.get(entry.getVariantId()));
activeVariant.setSecSizeDesc(secondarySizeDescIndexMap.get(entry.getVariantId()));
@Test
public void processProductDetailsTestForInternationalPartner() throws JsonProcessingException {
List batchIdList = new ArrayList();
batchIdList.add(8196);
List requestList = new ArrayList<>();
ExtractorRequest request = new ExtractorRequest();
request.setBatchId(123);
request.setFranchiseNumber(8196);
requestList.add(request);
code
List<ProductDataResponse> productResponseList = new ArrayList<>();
List<String> productIds = new ArrayList<>();
productIds.add("000000000060292784");
List<String> seasons = new ArrayList<>();
seasons.add("WN21");
Map<String, List<String>> productSeasonalityRequest = new HashMap<>();
productSeasonalityRequest.put(seasons.get(0), productIds);
Mockito.when(adminService.cnhProductWeightIsActive(Mockito.anyList(), Mockito.anyList())).thenReturn(true);
Map<String, List<ProductSeasonality>> productSeasonalityMap = new HashMap<>();
List<ProductSeasonality> productSeasonalityResponseList = new ArrayList<>();
ProductSeasonality productSeasonalty = new ProductSeasonality();
productSeasonalty.setProductId("000000000060292784");
productSeasonalty.setProductType("Z001");
productSeasonalty.setStrokeNum("1400v");
productSeasonalty.setActiveVariantsCount(2);
productSeasonalty.setDepartment("T11");
productSeasonalty.setPrimarySizeRange("ZS");
productSeasonalty.setSecondarySizeRange("");
productSeasonalty.setMerchandiseCat("A42030101");
productSeasonalty.setProductVariantsCount(2);
Colour colour = new Colour();
colour.setColourCode("Z0");
colour.setColourDescription("White");
productSeasonalty.setColour(colour);
ProductDescription productDescription = new ProductDescription();
productDescription.setLongDesc("10P Plain Briefs White");
productDescription.setShortDesc("10P Plain Briefs");
productSeasonalty.setProductDescription(productDescription);
Hierarchy hierarchy = new Hierarchy();
hierarchy.setLevel("08");
hierarchy.setValue("G8-T0657");
productSeasonalty.setHierarchy(hierarchy);
Seasons season = new Seasons();
season.setSeasonName("WN21");
season.setSeasonYear("2021");
productSeasonalty.setSeason(season);
List<Attributes> AttList = new ArrayList<>();
Attributes att = new Attributes();
att.setAttDesc("M S BRAND");
att.setAttTypeDesc("BRANDS");
att.setAttDesc("jeans");
att.setAttTypeDesc("PRODUCT TYPE (C)");
AttList.add(att);
productSeasonalty.setAttributes(AttList);
List<ProductVariant> pvList = new ArrayList<>();
ProductVariant pv = new ProductVariant();
pv.setVariantId("000000060292784002");
pv.setPrimarySizeIndex("7");
pv.setPrimarySizeRange("ZS");
pv.setSecondarySizeIndex("01");
pv.setSecondarySizeRange("SZ");
pv.setActiveIndicator(1);
pvList.add(pv);
ProductVariant pv1 = new ProductVariant();
pv1.setVariantId("000000060292784004");
pv1.setPrimarySizeIndex("5");
pv1.setPrimarySizeRange("ZS");
pv1.setSecondarySizeIndex("01");
pv1.setSecondarySizeRange("SA");
pv1.setActiveIndicator(1);
pvList.add(pv1);
productSeasonalty.setProductVariants(pvList);
productSeasonalityResponseList.add(productSeasonalty);
Mockito.when(cnhService.getSeasonalityCollection(Mockito.any(),Mockito.anyList(), Mockito.anyList()))
.thenReturn(productSeasonalityResponseList);
Map<String, String> primarySizeDescMap = new HashMap<>();
primarySizeDescMap.put("000000060292784002", "2-3y");
primarySizeDescMap.put("000000060292784004", "4-9y");
Mockito.when(cnhService.getPrimarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(primarySizeDescMap);
Map<String, String> secondarySizeDescMap = new HashMap<>();
secondarySizeDescMap.put("000000060292784002", "32");
secondarySizeDescMap.put("000000060292784004", "34");
Mockito.when(cnhService.getSecondarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(secondarySizeDescMap);
AttrServiceResponse attrServiceResponse = new AttrServiceResponse();
attrServiceResponse.setPlanARawMaterial("Cotton");
attrServiceResponse.setProductShapeEcom("FitJeans");
Map<String, AttrServiceResponse> pdtIdnStyleEcomMap = new HashMap<>();
pdtIdnStyleEcomMap.put("000000000060292784", attrServiceResponse);
Mockito.when(cnhService.getAttributes(Mockito.anyList(), Mockito.anyList(), Mockito.anyList())).thenReturn(pdtIdnStyleEcomMap);
Map<Integer,String> countryCodeMap = new HashMap<>();
countryCodeMap.put(75, "DE");
Mockito.when(ibtService.getCountryCode(Mockito.anyList(), Mockito.anyList())).thenReturn(countryCodeMap);
List<CooResponse> cooResponseList = new ArrayList<>();
CooResponse cooResponse = new CooResponse();
cooResponse.setCountryNum(75);
cooResponse.setFranchiseNumber(8196);
cooResponse.setProductId("000000000060292784");
cooResponse.setSeasonName("WN21");
cooResponseList.add(cooResponse);
Map<Integer, List<CooResponse>> cooResponseMap = new HashMap<>();
cooResponseMap.put(8196, cooResponseList);
Mockito.when(ibtService.getCOOForPartners(Mockito.anyList(), Mockito.anyList(), Mockito.anyMap())).thenReturn(cooResponseMap) ;
ProductWeightRequest productWeightRequest = new ProductWeightRequest();
productWeightRequest.setProductIds(productIds);
Mockito.when(cnhService.getProductWehightProductPackService(productWeightRequest)).thenReturn(generateCnhProductPackServiceResponse());
List<String> variantId = new ArrayList<>();
variantId.add("000000060292784002");
variantId.add("000000060292784004");
productSeasonalityMap.put("000000000060292784", productSeasonalityResponseList);
// calling ES Service
List<ProductSeasonality> variant = productSeasonalityMap.get(productIds);
Map<String, ProductSeasonality> variantSeasonDataMap = new HashMap<>();
variantSeasonDataMap.put("000000000060292784", productSeasonalty);
ProductSeasonality prductSeasonlity = variantSeasonDataMap.get(seasons);
List<String> variantIds = new ArrayList<>();
variantIds.add("000000060292784002");
variantIds.add("000000060292784004");
List<Products> esSeriveResponse = new ArrayList<>();
Products product = new Products();
product.setParentProductId("000000000060292784");
product.setProductId("000000060292784002");
List<StrokeDescription> strokeDesc = new ArrayList<>();
StrokeDescription sd = new StrokeDescription();
sd.setDescription("10P Plain Briefs");
strokeDesc.add(sd);
product.setStrokeDesc(strokeDesc);
List<Version> version = new ArrayList<>();
Version versin = new Version();
versin.setVersion(0);
Barcodes barcodes = new Barcodes();
List<String> UPC = new ArrayList<>();
UPC.add("23456");
barcodes.setUPC(UPC);
List<String> EAN13 = new ArrayList<>();
EAN13.add("123456");
barcodes.setEAN13(EAN13);
versin.setBarcodes(barcodes);
version.add(versin);
product.setVersion(version);
Customs customs = new Customs();
customs.setCommodityCode("hsn");
product.setCustoms(customs);
esSeriveResponse.add(product);
Mockito.when(esService.getVariantCollection(Mockito.any(),Mockito.anyList(), Mockito.anyList())).thenReturn(esSeriveResponse);
List<AdminServiceResponse> list1 = new ArrayList<>();
AdminServiceResponse objt = new AdminServiceResponse();
objt.setDestinationPath("absb");
objt.setFileNamePattern("filename");
objt.setFranchiseNumber(8196);
objt.setLatestSeason(false);
objt.setNoOfSeasonsBackward(0);
objt.setNoOfSeasonsForward(0);
objt.setQualifier("ordering");
list1.add(objt);
Mockito.when(cnhService.getNextTwoSeasonFromCurrentSeason(Mockito.anyInt(),Mockito.anyInt(),Mockito.anyList(),Mockito.anyList())).thenReturn(seasons);
Mockito.when(adminService.getDetailsForExtract(Mockito.anyList(), Mockito.anyList())).thenReturn(list1);
Map<Integer, List<ProductDataResponse>> finalResponseMap = new HashMap<>();
finalResponseMap.put(8196, productResponseList);
List<ProductStagingResponse> stageTableList = new ArrayList<>();
ProductStagingResponse response = new ProductStagingResponse();
response.setFranchiseNumber(8196);
response.setProductId("000000000060292784");
response.setVariantIds(variantId);
response.setSeason("WN21");
stageTableList.add(response);
Mockito.when(subscriptionService.getProductsForExtract(Mockito.anyList(), Mockito.anyList())).thenReturn(stageTableList);
Map<String, String> deptnCat = new HashMap<>();
deptnCat.put("T11", "KIDSWEAR");
Map<String,List<String>> requestMap = new HashMap<>();
requestMap.put("WN21", productIds);
Mockito.lenient().when(adminService.getCategoryMapping(Constants.ZALANDO_FRANCHISE_NUMBER)).thenReturn(deptnCat);
List<VariantCategoryDataEntity> variantLevelCategory = new ArrayList<>();
VariantCategoryDataEntity variantCategoryDataEntity = new VariantCategoryDataEntity();
variantCategoryDataEntity.setCategory("womens>clothing>jeans>FitJeans");
variantCategoryDataEntity.setProductVariantId("000000060292784004");
variantCategoryDataEntity.setFranchiseNumber(8196);
variantLevelCategory.add(variantCategoryDataEntity);
Mockito.lenient().when(variantCategoryDataRepository.findByFranchiseNumber(Constants.ZALANDO_FRANCHISE_NUMBER))
.thenReturn(variantLevelCategory);
//doubt
Map<String, Map<String, String>> sellingAttrMap = new HashMap<>();
Map<String, String> attrMap = new HashMap<String, String>();
attrMap.put(Constants.SUBSCRIBED_FIELD_PRODUCT_ID, "000000000060292784");
attrMap.put("CareInstruction", "Machine washable\\nTumble dry");
attrMap.put("Footwear_Sole", "Upper: Leather\\nLining and Sock: Textile\\nOutsole: Other materials");
sellingAttrMap.put("000000060292784002", attrMap);
Mockito.lenient().when(sellingAttributeService.getSellingAttributeMap(Mockito.any(SellingAttributesRequest.class)))
.thenReturn(sellingAttrMap);
Mockito.lenient().when(
blobUtils.uploadToFileShare(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(true);
List<PartnerFieldSubscriptionResponse> list = new ArrayList<>();
PartnerFieldSubscriptionResponse partnerFieldSubscription = new PartnerFieldSubscriptionResponse();
partnerFieldSubscription.setFrachiseNumber(8196);
partnerFieldSubscription.setSubscribedFields(Arrays.asList("strokeNo","dept","primSizeRange","secSizeRange","item","merchandCategory","productTypeC","planARawMaterial","productShapeEcom","colour","colourCode","colourDesc","productDesc","language","descriptions","descType","desc","seasons","seasonName","hsn","coo","variants","productVariantId","primSizeDesc","secSizeDesc","barcodes","Category","type","value","length","width","height","unitOfDimension","unitOfWeight","productWeight"));
list.add(partnerFieldSubscription);
List<ExtractorRequest> batchRequestList = new ArrayList<>();
ExtractorRequest batchRequest = new ExtractorRequest();
batchRequest.setBatchId(123);
batchRequest.setFranchiseNumber(8196);
batchRequestList.add(batchRequest);
List<Integer> franchiseList = new ArrayList<Integer>();
franchiseList.add(8196);
Mockito.lenient()
.when(adminService.getSubscribeFieldsByExtractTypeId(Mockito.anyInt(), Mockito.any(), Mockito.any()))
.thenReturn(list);
boolean flagCount = processor.triggerProcess(requestList);
Assertions.assertTrue(flagCount);
}
To update your test case to ensure that the activeVariant.setPrimSizeDesc(primarySizeDescIndexMap.get(entry.getVariantId())); and activeVariant.setSecSizeDesc(secondarySizeDescIndexMap.get(entry.getVariantId())); lines are correctly populated, you will need to make sure that both the primarySizeDescMap and secondarySizeDescMap contain the expected values for the variant IDs being processed.
Here's a step-by-step guide to modifying the test code accordingly:
Ensure that when you set the mappings for primarySizeDescMap and secondarySizeDescMap, you are actually matching the variant IDs present in your productSeasonalty and its associated ProductVariant instances.
Verify that your variantId list contains the correct variant IDs to test against. If you want to invoke the code that relies on these mappings, the relevant IDs must be correctly referenced in the maps.
Here is the modified test code for the processProductDetailsTestForInternationalPartner method:
java
@Test
public void processProductDetailsTestForInternationalPartner() throws JsonProcessingException {
List<Integer> batchIdList = new ArrayList<>();
batchIdList.add(8196);
List<ExtractorRequest> requestList = new ArrayList<>();
ExtractorRequest request = new ExtractorRequest();
request.setBatchId(123);
request.setFranchiseNumber(8196);
requestList.add(request);
// Mocking Product Data Response
List<ProductDataResponse> productResponseList = new ArrayList<>();
List<String> productIds = new ArrayList<>();
productIds.add("000000000060292784");
List<String> seasons = new ArrayList<>();
seasons.add("WN21");
Map<String, List<String>> productSeasonalityRequest = new HashMap<>();
productSeasonalityRequest.put(seasons.get(0), productIds);
// Mocking the adminService call
Mockito.when(adminService.cnhProductWeightIsActive(Mockito.anyList(), Mockito.anyList())).thenReturn(true);
Map<String, List<ProductSeasonality>> productSeasonalityMap = new HashMap<>();
List<ProductSeasonality> productSeasonalityResponseList = new ArrayList<>();
ProductSeasonality productSeasonalty = new ProductSeasonality();
productSeasonalty.setProductId("000000000060292784");
productSeasonalty.setActiveVariantsCount(2);
productSeasonalty.setDepartment("T11");
productSeasonalty.setPrimarySizeRange("ZS");
productSeasonalty.setSecondarySizeRange("");
productSeasonalty.setMerchandiseCat("A42030101");
Colour colour = new Colour();
colour.setColourCode("Z0");
colour.setColourDescription("White");
productSeasonalty.setColour(colour);
ProductDescription productDescription = new ProductDescription();
productDescription.setLongDesc("10P Plain Briefs White");
productDescription.setShortDesc("10P Plain Briefs");
productSeasonalty.setProductDescription(productDescription);
Hierarchy hierarchy = new Hierarchy();
hierarchy.setLevel("08");
hierarchy.setValue("G8-T0657");
productSeasonalty.setHierarchy(hierarchy);
Seasons season = new Seasons();
season.setSeasonName("WN21");
season.setSeasonYear("2021");
productSeasonalty.setSeason(season);
// Mocking variant data
List<ProductVariant> pvList = new ArrayList<>();
ProductVariant pv = new ProductVariant();
pv.setVariantId("000000060292784002");
pv.setActiveIndicator(1);
pvList.add(pv);
ProductVariant pv1 = new ProductVariant();
pv1.setVariantId("000000060292784004");
pv1.setActiveIndicator(1);
pvList.add(pv1);
productSeasonalty.setProductVariants(pvList);
productSeasonalityResponseList.add(productSeasonalty);
Mockito.when(cnhService.getSeasonalityCollection(Mockito.any(), Mockito.anyList(), Mockito.anyList()))
.thenReturn(productSeasonalityResponseList);
// Setting primary and secondary size descriptions
Map<String, String> primarySizeDescMap = new HashMap<>();
primarySizeDescMap.put("000000060292784002", "2-3y");
primarySizeDescMap.put("000000060292784004", "4-9y");
Mockito.when(cnhService.getPrimarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(primarySizeDescMap);
Map<String, String> secondarySizeDescMap = new HashMap<>();
secondarySizeDescMap.put("000000060292784002", "32");
secondarySizeDescMap.put("000000060292784004", "34");
Mockito.when(cnhService.getSecondarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(secondarySizeDescMap);
// Additional mocking of other necessary data
//...
// Call the process method and validate
boolean flagCount = processor.triggerProcess(requestList);
// Assert that the processing was successful
Assertions.assertTrue(flagCount);
}
Explanation of Changes:
Variants Population: Ensured that the variants in pvList have the correct variant IDs that match the keys in primarySizeDescMap and secondarySizeDescMap.
Mocking Size Descriptions: Mapped the expected descriptions accurately against the associated variant IDs to ensure that during the processing, the setPrimSizeDesc and setSecSizeDesc methods receive appropriate values.
This should effectively test the population of the size descriptions as required in the processProductDetailsTestForInternationalPartner test case while maintaining clarity and correctness in mocking the necessary services and data.
Here's the clarified version of the updated test code highlighting what has changed and what it includes to ensure that the activeVariant.setPrimSizeDesc(primarySizeDescIndexMap.get(entry.getVariantId())); and activeVariant.setSecSizeDesc(secondarySizeDescIndexMap.get(entry.getVariantId())); functionalities work correctly.
Updated Test Code Snippet
java
@Test
public void processProductDetailsTestForInternationalPartner() throws JsonProcessingException {
List<Integer> batchIdList = new ArrayList<>();
batchIdList.add(8196);
List<ExtractorRequest> requestList = new ArrayList<>();
// Setting up ExtractorRequest
ExtractorRequest request = new ExtractorRequest();
request.setBatchId(123);
request.setFranchiseNumber(8196);
requestList.add(request);
// Mocking Product Data Response
List<ProductDataResponse> productResponseList = new ArrayList<>();
// Preparing Product IDs and Seasons
List<String> productIds = new ArrayList<>();
productIds.add("000000000060292784");
List<String> seasons = new ArrayList<>();
seasons.add("WN21");
// Mocking seasonality response
Mockito.when(adminService.cnhProductWeightIsActive(Mockito.anyList(), Mockito.anyList())).thenReturn(true);
Map<String, List<ProductSeasonality>> productSeasonalityMap = new HashMap<>();
List<ProductSeasonality> productSeasonalityResponseList = new ArrayList<>();
ProductSeasonality productSeasonalty = new ProductSeasonality();
productSeasonalty.setProductId("000000000060292784");
productSeasonalty.setActiveVariantsCount(2);
productSeasonalty.setDepartment("T11");
productSeasonalty.setPrimarySizeRange("ZS");
productSeasonalty.setSecondarySizeRange("");
productSeasonalty.setMerchandiseCat("A42030101");
Colour colour = new Colour();
colour.setColourCode("Z0");
colour.setColourDescription("White");
productSeasonalty.setColour(colour);
ProductDescription productDescription = new ProductDescription();
productDescription.setLongDesc("10P Plain Briefs White");
productDescription.setShortDesc("10P Plain Briefs");
productSeasonalty.setProductDescription(productDescription);
Hierarchy hierarchy = new Hierarchy();
hierarchy.setLevel("08");
hierarchy.setValue("G8-T0657");
productSeasonalty.setHierarchy(hierarchy);
// Setting up Seasons
Seasons season = new Seasons();
season.setSeasonName("WN21");
season.setSeasonYear("2021");
productSeasonalty.setSeason(season);
// Mocking variant data
List<ProductVariant> pvList = new ArrayList<>();
ProductVariant pv = new ProductVariant();
pv.setVariantId("000000060292784002");
pv.setActiveIndicator(1);
pvList.add(pv);
ProductVariant pv1 = new ProductVariant();
pv1.setVariantId("000000060292784004");
pv1.setActiveIndicator(1);
pvList.add(pv1);
productSeasonalty.setProductVariants(pvList);
productSeasonalityResponseList.add(productSeasonalty);
Mockito.when(cnhService.getSeasonalityCollection(Mockito.any(), Mockito.anyList(), Mockito.anyList()))
.thenReturn(productSeasonalityResponseList);
// Setting primary and secondary size descriptions
Map<String, String> primarySizeDescMap = new HashMap<>();
primarySizeDescMap.put("000000060292784002", "2-3y");
primarySizeDescMap.put("000000060292784004", "4-9y");
Mockito.when(cnhService.getPrimarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(primarySizeDescMap);
// Mocking secondary size descriptions
Map<String, String> secondarySizeDescMap = new HashMap<>();
secondarySizeDescMap.put("000000060292784002", "32");
secondarySizeDescMap.put("000000060292784004", "34");
Mockito.when(cnhService.getSecondarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(secondarySizeDescMap);
// Mocking additional necessary data...
// (other mocking code here)
// Trigger process and assert outcome
boolean flagCount = processor.triggerProcess(requestList);
// Assert that the processing outcome was successful
Assertions.assertTrue(flagCount);
}
Key New Elements in the Updated Test Code:
Setting Up Mocked Size Description Maps:
The primary size and secondary size description maps were added to ensure that each variant ID can access its respective descriptions.
java
Map<String, String> primarySizeDescMap = new HashMap<>();
primarySizeDescMap.put("000000060292784002", "2-3y");
primarySizeDescMap.put("000000060292784004", "4-9y");
Map<String, String> secondarySizeDescMap = new HashMap<>();
secondarySizeDescMap.put("000000060292784002", "32");
secondarySizeDescMap.put("000000060292784004", "34");
The Mockito.when Calls:
These mocks ensure that when getPrimarySizeData and getSecondarySizeData are called, they return the correct maps that correspond with the variant IDs defined in the ProductVariant objects. This allows the test to verify that the activeVariant object gets populated with the correct size descriptions.
Maintaining Structure:
The overall structure of the test case allows for the validation of product details as they are processed by the triggerProcess method, and the assertions are included to confirm that the correct flow is achieved.
Purpose:
The adjustments ensure that the proper mappings for primary and secondary size descriptions are utilized when processing the product details, which verifies the logic within the ProductCoreProcessor class, specifically in how it populates activeVariant properties.
I apologize for the oversight. Let’s focus on the specific changes that would ensure that the size descriptions are correctly populated in the activeVariant during the test execution. Here’s a streamlined view of the parts that could be modified or clarified to ensure everything works correctly:
Updated Test Case Implementation
The modifications we want to ensure relate to ensuring that when we are processing a variant, the mapping for size descriptions is correctly set up in the test context. However, if you're saying that the relevant parts are already there, I will just highlight how you might ensure that they are directly referenced during test execution.
java
@Test
public void processProductDetailsTestForInternationalPartner() throws JsonProcessingException {
List<Integer> batchIdList = new ArrayList<>();
batchIdList.add(8196);
List<ExtractorRequest> requestList = new ArrayList<>();
ExtractorRequest request = new ExtractorRequest();
request.setBatchId(123);
request.setFranchiseNumber(8196);
requestList.add(request);
// Define product IDs and setup
List<String> productIds = new ArrayList<>();
productIds.add("000000000060292784");
// Prepare the product seasonality response
ProductSeasonality productSeasonalty = new ProductSeasonality();
productSeasonalty.setProductId("000000000060292784");
productSeasonalty.setProductVariants(Arrays.asList(createProductVariant("000000060292784002", "ZS", "01"),
createProductVariant("000000060292784004", "ZS", "01")));
// Mock methods to return expected data
Mockito.when(cnhService.getSeasonalityCollection(Mockito.any(), Mockito.anyList(), Mockito.anyList()))
.thenReturn(Arrays.asList(productSeasonalty));
// Set up size description maps
Map<String, String> primarySizeDescMap = Map.of(
"000000060292784002", "2-3y",
"000000060292784004", "4-9y"
);
Map<String, String> secondarySizeDescMap = Map.of(
"000000060292784002", "32",
"000000060292784004", "34"
);
Mockito.when(cnhService.getPrimarySizeData(Mockito.anyList(), Mockito.anyList()))
.thenReturn(primarySizeDescMap);
Mockito.when(cnhService.getSecondarySizeData(Mockito.anyList(), Mockito.anyList()))
.thenReturn(secondarySizeDescMap);
// Call the triggerProcess
boolean flagCount = processor.triggerProcess(requestList);
// Assert the expected outcome
Assertions.assertTrue(flagCount);
}
// Helper function to create ProductVariant
private ProductVariant createProductVariant(String variantId, String primarySizeRange, String secondarySizeRange) {
ProductVariant pv = new ProductVariant();
pv.setVariantId(variantId);
pv.setPrimarySizeRange(primarySizeRange);
pv.setSecondarySizeRange(secondarySizeRange);
pv.setActiveIndicator(1);
return pv;
}
Key Changes in the Code
The use of the createProductVariant function: This streamlines the creation of ProductVariant instances and keeps the main test method cleaner.
Mapping Set Up: The size maps are set specifically to ensure they relate to the variants being defined. The assertions afterward confirm the overall success of the flow from beginning to end.
Important to Note:
Ensure Clean Context: Make sure that these maps and mocks are correctly structured and referenced within the context of each process call. If primarySizeDescMap.get() or secondarySizeDescMap.get() return null, then it's important to validate that no runtime errors occur due to missing mappings.
Assertions: You might want to capture or check logged outputs or state changes within the ProductCoreProcessor to ensure that the behavior aligns with expectations. This could involve using a spy or similar mechanisms to ensure that setters on activeVariant are invoked with the expected values.
If you've already got these implementations in place, please clarify which specific areas you’d like a more focused adjustment on, or if there are any particular assertions or checks you would like to discuss.