Subversion Repositories SmartDukaan

Rev

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

Rev 24948 Rev 24949
Line 7... Line 7...
7
import java.util.Iterator;
7
import java.util.Iterator;
8
import java.util.List;
8
import java.util.List;
9
import java.util.Map;
9
import java.util.Map;
10
import java.util.stream.Collectors;
10
import java.util.stream.Collectors;
11
 
11
 
12
import javax.mail.search.SearchTerm;
-
 
13
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletRequest;
14
 
13
 
15
import org.apache.commons.lang3.StringUtils;
14
import org.apache.commons.lang3.StringUtils;
16
import org.apache.http.conn.HttpHostConnectException;
15
import org.apache.http.conn.HttpHostConnectException;
17
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.LogManager;
Line 105... Line 104...
105
	@Autowired
104
	@Autowired
106
	private RoleManager roleManagerService;
105
	private RoleManager roleManagerService;
107
 
106
 
108
	List<String> filterableParams = Arrays.asList("brand");
107
	List<String> filterableParams = Arrays.asList("brand");
109
	public static final Map<String, List<String>> EMAIL_BLOCKED_BRANDS = new HashMap<>();
108
	public static final Map<String, List<String>> EMAIL_BLOCKED_BRANDS = new HashMap<>();
110
	
109
 
111
	static {
110
	static {
112
		EMAIL_BLOCKED_BRANDS.put("sachinindri2006@gmail.com", Arrays.asList("Vivo"));
111
		EMAIL_BLOCKED_BRANDS.put("sachinindri2006@gmail.com", Arrays.asList("Vivo"));
113
		EMAIL_BLOCKED_BRANDS.put("akamboj828@gmail.com", Arrays.asList("Vivo"));
112
		EMAIL_BLOCKED_BRANDS.put("akamboj828@gmail.com", Arrays.asList("Vivo"));
114
		EMAIL_BLOCKED_BRANDS.put("babitaranirk@gmail.com", Arrays.asList("Vivo"));
113
		EMAIL_BLOCKED_BRANDS.put("babitaranirk@gmail.com", Arrays.asList("Vivo"));
115
		EMAIL_BLOCKED_BRANDS.put("testpxps@gmail.com", Arrays.asList("Gionee"));
114
		EMAIL_BLOCKED_BRANDS.put("testpxps@gmail.com", Arrays.asList("Gionee"));
Line 202... Line 201...
202
 
201
 
203
				mandatoryQ.add(
202
				mandatoryQ.add(
204
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
203
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
205
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
204
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
206
			} else if (subCategoryId != null) {
205
			} else if (subCategoryId != null) {
207
				mandatoryQ.add(
206
				mandatoryQ
208
						String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
207
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
209
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
208
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
210
			} else if (queryTerm != null) {
209
			} else if (queryTerm != null) {
211
				mandatoryQ.add(
-
 
212
						String.format("+(*:%s)",
-
 
213
								queryTerm, StringUtils.join(tagIds, " ")));
210
				mandatoryQ.add(String.format("+%s", queryTerm));
214
			} else if (hotDeal) {
211
			} else if (hotDeal) {
215
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
212
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
216
						StringUtils.join(tagIds, " ")));
213
						StringUtils.join(tagIds, " ")));
217
			} else {
214
			} else {
218
				mandatoryQ.add(
215
				mandatoryQ.add(
Line 231... Line 228...
231
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
228
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
232
			}
229
			}
233
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
230
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
234
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
231
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
235
			dealResponse = getCatalogResponse(docs, hotDeal);
232
			dealResponse = getCatalogResponse(docs, hotDeal);
236
			if(EMAIL_BLOCKED_BRANDS.containsKey(userInfo.getEmail())) {
233
			if (EMAIL_BLOCKED_BRANDS.containsKey(userInfo.getEmail())) {
237
				dealResponse.stream().filter(x->EMAIL_BLOCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()));
234
				dealResponse.stream().filter(x -> EMAIL_BLOCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()));
238
			}
235
			}
239
		} else {
236
		} else {
240
			return responseSender.badRequest(
237
			return responseSender.badRequest(
241
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
238
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
242
		}
239
		}
Line 421... Line 418...
421
		}
418
		}
422
		return responseSender.ok(dealResponse.get(0));
419
		return responseSender.ok(dealResponse.get(0));
423
	}
420
	}
424
 
421
 
425
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
422
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
426
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,  @RequestParam(required = false, defaultValue = "0") int categoryId) {
423
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
-
 
424
			@RequestParam(required = false, defaultValue = "0") int categoryId) {
427
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
425
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
428
		List<DBObject> brandsDisplay = mongoClient.getBrandsToDisplay(categoryId);
426
		List<DBObject> brandsDisplay = mongoClient.getBrandsToDisplay(categoryId);
429
		if(EMAIL_BLOCKED_BRANDS.containsKey(userInfo.getEmail())) {
427
		if (EMAIL_BLOCKED_BRANDS.containsKey(userInfo.getEmail())) {
430
			List<String> blockedBrands = EMAIL_BLOCKED_BRANDS.get(userInfo.getEmail());
428
			List<String> blockedBrands = EMAIL_BLOCKED_BRANDS.get(userInfo.getEmail());
431
			brandsDisplay = brandsDisplay.stream().filter(x->!blockedBrands.contains(x.get("name"))).collect(Collectors.toList());
429
			brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.get("name")))
-
 
430
					.collect(Collectors.toList());
432
		}
431
		}
433
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
432
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
434
	}
433
	}
435
 
434
 
436
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
435
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)