Subversion Repositories SmartDukaan

Rev

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

Rev 24117 Rev 24149
Line 195... Line 195...
195
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
195
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
196
						StringUtils.join(tagIds, " ")));
196
						StringUtils.join(tagIds, " ")));
197
			} else {
197
			} else {
198
				mandatoryQ.add(
198
				mandatoryQ.add(
199
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
199
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
200
				
-
 
201
				
200
 
202
			}
201
			}
203
			params.put("q", StringUtils.join(mandatoryQ, " "));
202
			params.put("q", StringUtils.join(mandatoryQ, " "));
204
			params.put("fl", "*, [child parentFilter=id:catalog*]");
203
			params.put("fl", "*, [child parentFilter=id:catalog*]");
205
			params.put("sort", "rank_i asc, create_s desc");
204
			params.put("sort", "rank_i asc, create_s desc");
206
			params.put("start", String.valueOf(offset));
205
			params.put("start", String.valueOf(offset));
Line 212... Line 211...
212
			} catch (HttpHostConnectException e) {
211
			} catch (HttpHostConnectException e) {
213
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
212
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
214
			}
213
			}
215
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
214
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
216
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
215
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
217
			dealResponse=getCatalogResponse(docs,hotDeal);
216
			dealResponse = getCatalogResponse(docs, hotDeal);
218
		} else {
217
		} else {
219
			return responseSender.badRequest(
218
			return responseSender.badRequest(
220
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
219
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
221
		}
220
		}
222
		return responseSender.ok(dealResponse);
221
		return responseSender.ok(dealResponse);
Line 269... Line 268...
269
		}
268
		}
270
		return responseSender.ok(responseObject);
269
		return responseSender.ok(responseObject);
271
	}
270
	}
272
 
271
 
273
	/*
272
	/*
274
	 * @RequestMapping(value = "/direct-deals",
273
	 * @RequestMapping(value = "/direct-deals", method=RequestMethod.GET,produces =
275
	 * method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
274
	 * MediaType.APPLICATION_JSON_VALUE)
276
	 * 
275
	 * 
277
	 * @ApiImplicitParams({
276
	 * @ApiImplicitParams({
278
	 * 
277
	 * 
279
	 * @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required =
278
	 * @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
280
	 * true, dataType = "string", paramType = "header") }) public
279
	 * dataType = "string", paramType = "header") }) public ResponseEntity<?>
281
	 * ResponseEntity<?> getDirectDeals(HttpServletRequest
-
 
282
	 * request, @RequestParam(value="categoryId") String
280
	 * getDirectDeals(HttpServletRequest request, @RequestParam(value="categoryId")
283
	 * categoryId,@RequestParam(value="offset") String offset,
281
	 * String categoryId,@RequestParam(value="offset") String offset,
284
	 * 
282
	 * 
285
	 * @RequestParam(value="limit") String limit, @RequestParam(value="sort",
283
	 * @RequestParam(value="limit") String limit, @RequestParam(value="sort",
286
	 * required=false) String sort, @RequestParam(value="direction",
284
	 * required=false) String sort, @RequestParam(value="direction", required=false)
287
	 * required=false) String direction,
285
	 * String direction,
288
	 * 
286
	 * 
289
	 * @RequestParam(value="filterData", required=false) String filterData ){
287
	 * @RequestParam(value="filterData", required=false) String filterData ){
290
	 * 
288
	 * 
291
	 * return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK); }
289
	 * return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK); }
292
	 */
290
	 */
Line 354... Line 352...
354
			}
352
			}
355
		}
353
		}
356
		/*
354
		/*
357
		 * final ProfitMandiResponse<?> profitMandiResponse = new
355
		 * final ProfitMandiResponse<?> profitMandiResponse = new
358
		 * ProfitMandiResponse<>(LocalDateTime.now(),
356
		 * ProfitMandiResponse<>(LocalDateTime.now(),
359
		 * request.getRequestURL().toString(), HttpStatus.OK.toString(),
357
		 * request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK,
360
		 * HttpStatus.OK, ResponseStatus.SUCCESS, dealsResponse);
358
		 * ResponseStatus.SUCCESS, dealsResponse);
361
		 */
359
		 */
362
		return responseSender.ok(dealsResponse);
360
		return responseSender.ok(dealsResponse);
363
	}
361
	}
364
 
362
 
365
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
363
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
Line 377... Line 375...
377
			RestClient rc = new RestClient();
375
			RestClient rc = new RestClient();
378
			Map<String, String> params = new HashMap<>();
376
			Map<String, String> params = new HashMap<>();
379
			List<String> mandatoryQ = new ArrayList<>();
377
			List<String> mandatoryQ = new ArrayList<>();
380
			String catalogString = "catalog" + id;
378
			String catalogString = "catalog" + id;
381
 
379
 
382
				mandatoryQ.add(
-
 
383
						String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
380
			mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
384
								categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
381
					categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
385
			
382
 
386
			params.put("q", StringUtils.join(mandatoryQ, " "));
383
			params.put("q", StringUtils.join(mandatoryQ, " "));
387
			params.put("fl", "*, [child parentFilter=id:catalog*]");
384
			params.put("fl", "*, [child parentFilter=id:catalog*]");
388
			params.put("sort", "rank_i asc, create_s desc");
385
			params.put("sort", "rank_i asc, create_s desc");
389
			params.put("wt", "json");
386
			params.put("wt", "json");
390
			String response = null;
387
			String response = null;
Line 393... Line 390...
393
			} catch (HttpHostConnectException e) {
390
			} catch (HttpHostConnectException e) {
394
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
391
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
395
			}
392
			}
396
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
393
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
397
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
394
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
398
			dealResponse=getCatalogResponse(docs,false);
395
			dealResponse = getCatalogResponse(docs, false);
399
		} else {
396
		} else {
400
			return responseSender.badRequest(
397
			return responseSender.badRequest(
401
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
398
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
402
		}
399
		}
403
		return responseSender.ok(dealResponse.get(0));
400
		return responseSender.ok(dealResponse.get(0));
404
	}
401
	}
405
	
-
 
406
 
402
 
407
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
403
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
408
	public ResponseEntity<?> getBrandsToDisplay(@RequestParam(required = false, defaultValue = "0") int categoryId) {
404
	public ResponseEntity<?> getBrandsToDisplay(@RequestParam(required = false, defaultValue = "0") int categoryId) {
409
		return new ResponseEntity<>(mongoClient.getBrandsToDisplay(categoryId), HttpStatus.OK);
405
		return new ResponseEntity<>(mongoClient.getBrandsToDisplay(categoryId), HttpStatus.OK);
410
	}
406
	}
Line 445... Line 441...
445
			}
441
			}
446
		}
442
		}
447
		return responseSender.ok(responseObject);
443
		return responseSender.ok(responseObject);
448
	}
444
	}
449
 
445
 
450
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal) throws ProfitMandiBusinessException {
446
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
-
 
447
			throws ProfitMandiBusinessException {
451
		Map<Integer, TagListing> itemTagListingMap = null;
448
		Map<Integer, TagListing> itemTagListingMap = null;
452
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
449
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
453
		List<Integer> tagIds = Arrays.asList(4);
450
		List<Integer> tagIds = Arrays.asList(4);
454
		if (docs.length() > 0) {
451
		if (docs.length() > 0) {
455
			HashSet<Integer> itemsSet = new HashSet<>();
452
			HashSet<Integer> itemsSet = new HashSet<>();
Line 472... Line 469...
472
			ffdr.setCatalogId(doc.getInt("catalogId_i"));
469
			ffdr.setCatalogId(doc.getInt("catalogId_i"));
473
			ffdr.setImageUrl(doc.getString("imageUrl_s"));
470
			ffdr.setImageUrl(doc.getString("imageUrl_s"));
474
			ffdr.setTitle(doc.getString("title_s"));
471
			ffdr.setTitle(doc.getString("title_s"));
475
			try {
472
			try {
476
				ffdr.setFeature(doc.getString("feature_s"));
473
				ffdr.setFeature(doc.getString("feature_s"));
477
			} catch(Exception e) {
474
			} catch (Exception e) {
478
				ffdr.setFeature(null);
475
				ffdr.setFeature(null);
479
				logger.info("Could not find Feature_s for {}", ffdr.getCatalogId()) ;
476
				logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
480
			}
477
			}
481
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
478
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
482
 
479
 
483
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
480
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
484
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
481
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
Line 524... Line 521...
524
						}
521
						}
525
						if (totalAvailability <= 0) {
522
						if (totalAvailability <= 0) {
526
							continue;
523
							continue;
527
						}
524
						}
528
					} else {
525
					} else {
-
 
526
						// For accessories item availability should at be ordered for Rs.1000
-
 
527
						if (item.getCategoryId() == 10020 || fdi.getSellingPrice() < 100) {
-
 
528
							fdi.setAvailability((int) Math.ceil(1000 / fdi.getSellingPrice()));
-
 
529
						} else {
529
						fdi.setAvailability(10);
530
							fdi.setAvailability(10);
-
 
531
						}
530
					}
532
					}
531
					fdi.setQuantityStep(1);
533
					fdi.setQuantityStep(1);
532
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
534
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
533
					fofoAvailabilityInfoMap.put(itemId, fdi);
535
					fofoAvailabilityInfoMap.put(itemId, fdi);
534
				}
536
				}