Subversion Repositories SmartDukaan

Rev

Rev 26575 | Rev 26630 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26575 Rev 26589
Line 211... Line 211...
211
		}
211
		}
212
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
212
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
213
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
213
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
214
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
214
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
215
 
215
 
216
		Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x->x.getId()==id).collect(Collectors.toList()).get(0);
216
		Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id)
-
 
217
				.collect(Collectors.toList()).get(0);
217
		bucket.setFofoCatalogResponses(dealResponse);
218
		bucket.setFofoCatalogResponses(dealResponse);
218
		return responseSender.ok(bucket);
219
		return responseSender.ok(bucket);
219
	}
220
	}
220
 
221
 
221
	private String getCommaSeparateTags(int userId) {
222
	private String getCommaSeparateTags(int userId) {
Line 284... Line 285...
284
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
285
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
285
			}
286
			}
286
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
287
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
287
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
288
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
288
			dealResponse = getCatalogResponse(docs, hotDeal);
289
			dealResponse = getCatalogResponse(docs, hotDeal);
-
 
290
			/*
289
			if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
291
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
290
				dealResponse.stream()
292
			 * dealResponse.stream() .filter(x ->
291
						.filter(x -> Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()));
293
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
-
 
294
			 * ; }
-
 
295
			 */
-
 
296
		} else {
-
 
297
			return responseSender.badRequest(
-
 
298
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
-
 
299
		}
-
 
300
		return responseSender.ok(dealResponse);
-
 
301
	}
-
 
302
 
-
 
303
	@ApiImplicitParams({
-
 
304
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
305
	@RequestMapping(value = "/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
306
	public ResponseEntity<?> partnerStock(HttpServletRequest request,
-
 
307
			@RequestParam(value = "categoryId", required = false, defaultValue = "(3 OR 6)") String categoryId,
-
 
308
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
-
 
309
			@RequestParam(value = "sort", required = false) String sort,
-
 
310
			@RequestParam(value = "brand", required = false) String brand,
-
 
311
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
-
 
312
			@RequestParam(value = "q", required = false) String queryTerm,
-
 
313
			@RequestParam(value = " ", required = false, defaultValue = "true") boolean partnerStockOnly)
-
 
314
			throws Throwable {
-
 
315
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
-
 
316
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
317
		UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
-
 
318
		
-
 
319
		logger.info("Retiler Id ==> {}", uc.getUserId());
-
 
320
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
-
 
321
			if(partnerStockOnly) {
-
 
322
				
292
			}
323
			}
-
 
324
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
-
 
325
			RestClient rc = new RestClient();
-
 
326
			Map<String, String> params = new HashMap<>();
-
 
327
			List<String> mandatoryQ = new ArrayList<>();
-
 
328
			if (queryTerm != null && !queryTerm.equals("null")) {
-
 
329
				mandatoryQ.add(String.format("+(%s)", queryTerm));
-
 
330
			} else {
-
 
331
				queryTerm = null;
-
 
332
			}
-
 
333
			if (subCategoryId != 0) {
-
 
334
				mandatoryQ
-
 
335
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
-
 
336
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
-
 
337
			} else if (StringUtils.isNotBlank(brand)) {
-
 
338
				mandatoryQ.add(
-
 
339
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
-
 
340
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
-
 
341
 
-
 
342
			} else {
-
 
343
				mandatoryQ.add(
-
 
344
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
-
 
345
			}
-
 
346
			params.put("q", StringUtils.join(mandatoryQ, " "));
-
 
347
			params.put("fl", "*, [child parentFilter=id:catalog*]");
-
 
348
			if (queryTerm == null) {
-
 
349
				params.put("sort", "create_s desc");
-
 
350
			}
-
 
351
			params.put("start", String.valueOf(offset));
-
 
352
			params.put("rows", String.valueOf(limit));
-
 
353
			params.put("wt", "json");
-
 
354
			String response = null;
-
 
355
			try {
-
 
356
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
-
 
357
			} catch (HttpHostConnectException e) {
-
 
358
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
359
			}
-
 
360
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
361
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
362
			dealResponse = getCatalogResponse(docs, false);
-
 
363
			/*
-
 
364
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
-
 
365
			 * dealResponse.stream() .filter(x ->
-
 
366
			 * Mongo.PARTNER_BLoCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()))
-
 
367
			 * ; }
-
 
368
			 */
293
		} else {
369
		} else {
294
			return responseSender.badRequest(
370
			return responseSender.badRequest(
295
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
371
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
296
		}
372
		}
297
		return responseSender.ok(dealResponse);
373
		return responseSender.ok(dealResponse);
Line 555... Line 631...
555
		List<Integer> tagIds = Arrays.asList(4);
631
		List<Integer> tagIds = Arrays.asList(4);
556
		if (docs.length() > 0) {
632
		if (docs.length() > 0) {
557
			HashSet<Integer> itemsSet = new HashSet<>();
633
			HashSet<Integer> itemsSet = new HashSet<>();
558
			for (int i = 0; i < docs.length(); i++) {
634
			for (int i = 0; i < docs.length(); i++) {
559
				JSONObject doc = docs.getJSONObject(i);
635
				JSONObject doc = docs.getJSONObject(i);
560
				if(doc.has("_childDocuments_")) {
636
				if (doc.has("_childDocuments_")) {
561
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
637
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
562
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
638
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
563
						int itemId = childItem.getInt("itemId_i");
639
						int itemId = childItem.getInt("itemId_i");
564
						itemsSet.add(itemId);
640
						itemsSet.add(itemId);
565
					}
641
					}
566
				}
642
				}
567
			}
643
			}
568
			if(itemsSet.size() == 0) {
644
			if (itemsSet.size() == 0) {
569
				return dealResponse;
645
				return dealResponse;
570
			}
646
			}
571
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
647
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
572
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
648
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
573
		}
649
		}
Line 584... Line 660...
584
			} catch (Exception e) {
660
			} catch (Exception e) {
585
				ffdr.setFeature(null);
661
				ffdr.setFeature(null);
586
				logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
662
				logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
587
			}
663
			}
588
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
664
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
589
			if(doc.has("_childDocuments_")) {
665
			if (doc.has("_childDocuments_")) {
590
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
666
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
591
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
667
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
592
					int itemId = childItem.getInt("itemId_i");
668
					int itemId = childItem.getInt("itemId_i");
593
					TagListing tl = itemTagListingMap.get(itemId);
669
					TagListing tl = itemTagListingMap.get(itemId);
594
					if (tl == null) {
670
					if (tl == null) {
Line 619... Line 695...
619
							fdi.setMinBuyQuantity(10);
695
							fdi.setMinBuyQuantity(10);
620
						} else {
696
						} else {
621
							fdi.setMinBuyQuantity(1);
697
							fdi.setMinBuyQuantity(1);
622
						}
698
						}
623
						if (hotDeal || !tl.isActive()) {
699
						if (hotDeal || !tl.isActive()) {
624
							
700
 
625
							int totalAvailability = 0; // Using item availability
701
							int totalAvailability = 0; // Using item availability
626
							// cache for now but can be
702
							// cache for now but can be
627
							// changed to
703
							// changed to
628
							// use caching later.
704
							// use caching later.
629
							try {
705
							try {
Line 658... Line 734...
658
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
734
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
659
			boolean hotDeal) throws ProfitMandiBusinessException {
735
			boolean hotDeal) throws ProfitMandiBusinessException {
660
		Map<Integer, TagListing> itemTagListingMap = null;
736
		Map<Integer, TagListing> itemTagListingMap = null;
661
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
737
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
662
		List<Integer> tagIds = Arrays.asList(4);
738
		List<Integer> tagIds = Arrays.asList(4);
663
		
739
 
664
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
740
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
665
				.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
741
				.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
666
 
742
 
667
		for (int i = 0; i < docs.length(); i++) {
743
		for (int i = 0; i < docs.length(); i++) {
668
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
744
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
Line 670... Line 746...
670
 
746
 
671
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
747
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
672
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
748
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
673
				int itemId = childItem.getInt("itemId_i");
749
				int itemId = childItem.getInt("itemId_i");
674
				TagListing tl = itemTagListingMap.get(itemId);
750
				TagListing tl = itemTagListingMap.get(itemId);
675
				if(tl==null) {
751
				if (tl == null) {
676
					continue;
752
					continue;
677
				}
753
				}
678
				if (hotDeal) {
754
				if (hotDeal) {
679
					if (!tl.isHotDeals()) {
755
					if (!tl.isHotDeals()) {
680
						continue;
756
						continue;