Subversion Repositories SmartDukaan

Rev

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

Rev 25014 Rev 25015
Line 203... Line 203...
203
			if (queryTerm != null && !queryTerm.equals("null")) {
203
			if (queryTerm != null && !queryTerm.equals("null")) {
204
				mandatoryQ.add(String.format("+(%s)", queryTerm));
204
				mandatoryQ.add(String.format("+(%s)", queryTerm));
205
			} else {
205
			} else {
206
				queryTerm = null;
206
				queryTerm = null;
207
			}
207
			}
208
			if (StringUtils.isNotBlank(brand)) {
-
 
209
				mandatoryQ.add(
-
 
210
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
-
 
211
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
-
 
212
			} else if (subCategoryId != 0) {
208
			if (subCategoryId != 0) {
213
				mandatoryQ
209
				mandatoryQ
214
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
210
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
215
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
211
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
216
 
-
 
217
			} else if (hotDeal) {
212
			} else if (hotDeal) {
218
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
213
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
219
						StringUtils.join(tagIds, " ")));
214
						StringUtils.join(tagIds, " ")));
-
 
215
 
-
 
216
			} else if (StringUtils.isNotBlank(brand)) {
-
 
217
				mandatoryQ.add(
-
 
218
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
-
 
219
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
-
 
220
 
220
			} else {
221
			} else {
221
				mandatoryQ.add(
222
				mandatoryQ.add(
222
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
223
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
223
			}
224
			}
224
			params.put("q", StringUtils.join(mandatoryQ, " "));
225
			params.put("q", StringUtils.join(mandatoryQ, " "));
Line 458... Line 459...
458
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
459
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
459
		}
460
		}
460
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
461
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
461
		JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
462
		JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
462
		List<Integer> categoryIds = new ArrayList<>();
463
		List<Integer> categoryIds = new ArrayList<>();
463
		for(int i=0;i< groups.length();i++) {
464
		for (int i = 0; i < groups.length(); i++) {
464
			JSONObject groupObject = groups.getJSONObject(i); 
465
			JSONObject groupObject = groups.getJSONObject(i);
465
			int subCategoryId =  groupObject.getInt("groupValue");
466
			int subCategoryId = groupObject.getInt("groupValue");
466
			int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
467
			int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
467
			categoryIds.add(subCategoryId);
468
			categoryIds.add(subCategoryId);
468
		}
469
		}
469
		
470
 
470
		List<Category> categories = categoryRepository.selectByIds(categoryIds);
471
		List<Category> categories = categoryRepository.selectByIds(categoryIds);
471
		AtomicInteger i= new AtomicInteger(0);
472
		AtomicInteger i = new AtomicInteger(0);
472
		categories.forEach(x->{
473
		categories.forEach(x -> {
473
			DBObject dbObject = new BasicDBObject();
474
			DBObject dbObject = new BasicDBObject();
474
			dbObject.put("name", x.getLabel());
475
			dbObject.put("name", x.getLabel());
475
			dbObject.put("subCategoryId", x.getId());
476
			dbObject.put("subCategoryId", x.getId());
476
			dbObject.put("rank", i.incrementAndGet());
477
			dbObject.put("rank", i.incrementAndGet());
477
			dbObject.put("categoryId", 6);
478
			dbObject.put("categoryId", 6);
478
			dbObject.put("url", "http://api.profittill.com/uploads/campaigns/" + x.getId() + ".png");
479
			dbObject.put("url", "http://api.profittill.com/uploads/campaigns/" + x.getId() + ".png");
479
			subCategories.add(dbObject);
480
			subCategories.add(dbObject);
480
		});
481
		});
481
		
482
 
482
		return subCategories;
483
		return subCategories;
483
		
484
 
484
	}
485
	}
485
 
486
 
486
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
487
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
487
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
488
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
488
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
489
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);