Subversion Repositories SmartDukaan

Rev

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

Rev 24995 Rev 25010
Line 5... Line 5...
5
import java.util.HashMap;
5
import java.util.HashMap;
6
import java.util.HashSet;
6
import java.util.HashSet;
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.concurrent.atomic.AtomicInteger;
10
import java.util.stream.Collectors;
11
import java.util.stream.Collectors;
11
 
12
 
12
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletRequest;
13
 
14
 
14
import org.apache.commons.lang3.StringUtils;
15
import org.apache.commons.lang3.StringUtils;
Line 17... Line 18...
17
import org.apache.logging.log4j.Logger;
18
import org.apache.logging.log4j.Logger;
18
import org.json.JSONArray;
19
import org.json.JSONArray;
19
import org.json.JSONObject;
20
import org.json.JSONObject;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Value;
22
import org.springframework.beans.factory.annotation.Value;
-
 
23
import org.springframework.cache.annotation.Cacheable;
22
import org.springframework.http.HttpStatus;
24
import org.springframework.http.HttpStatus;
23
import org.springframework.http.MediaType;
25
import org.springframework.http.MediaType;
24
import org.springframework.http.ResponseEntity;
26
import org.springframework.http.ResponseEntity;
25
import org.springframework.stereotype.Controller;
27
import org.springframework.stereotype.Controller;
26
import org.springframework.transaction.annotation.Transactional;
28
import org.springframework.transaction.annotation.Transactional;
Line 33... Line 35...
33
import com.eclipsesource.json.JsonArray;
35
import com.eclipsesource.json.JsonArray;
34
import com.eclipsesource.json.JsonObject;
36
import com.eclipsesource.json.JsonObject;
35
import com.eclipsesource.json.JsonValue;
37
import com.eclipsesource.json.JsonValue;
36
import com.google.gson.Gson;
38
import com.google.gson.Gson;
37
import com.google.gson.reflect.TypeToken;
39
import com.google.gson.reflect.TypeToken;
-
 
40
import com.mongodb.BasicDBObject;
38
import com.mongodb.DBObject;
41
import com.mongodb.DBObject;
39
import com.spice.profitmandi.common.enumuration.SchemeType;
42
import com.spice.profitmandi.common.enumuration.SchemeType;
40
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
43
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
41
import com.spice.profitmandi.common.model.ProfitMandiConstants;
44
import com.spice.profitmandi.common.model.ProfitMandiConstants;
42
import com.spice.profitmandi.common.model.UserInfo;
45
import com.spice.profitmandi.common.model.UserInfo;
43
import com.spice.profitmandi.common.web.client.RestClient;
46
import com.spice.profitmandi.common.web.client.RestClient;
44
import com.spice.profitmandi.common.web.util.ResponseSender;
47
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
48
import com.spice.profitmandi.dao.entity.catalog.Category;
45
import com.spice.profitmandi.dao.entity.catalog.Item;
49
import com.spice.profitmandi.dao.entity.catalog.Item;
46
import com.spice.profitmandi.dao.entity.catalog.TagListing;
50
import com.spice.profitmandi.dao.entity.catalog.TagListing;
47
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
51
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
48
import com.spice.profitmandi.dao.model.UserCart;
52
import com.spice.profitmandi.dao.model.UserCart;
-
 
53
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
49
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
54
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
50
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
55
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
51
import com.spice.profitmandi.dao.repository.dtr.Mongo;
56
import com.spice.profitmandi.dao.repository.dtr.Mongo;
52
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
57
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
53
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
58
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
Line 82... Line 87...
82
 
87
 
83
	@Autowired
88
	@Autowired
84
	private PricingService pricingService;
89
	private PricingService pricingService;
85
 
90
 
86
	@Autowired
91
	@Autowired
-
 
92
	private CategoryRepository categoryRepository;
-
 
93
 
-
 
94
	@Autowired
87
	private Mongo mongoClient;
95
	private Mongo mongoClient;
88
 
96
 
89
	@Autowired
97
	@Autowired
90
	private UserAccountRepository userAccountRepository;
98
	private UserAccountRepository userAccountRepository;
91
 
99
 
92
	@Autowired
100
	@Autowired
93
	private ResponseSender<?> responseSender;
101
	private ResponseSender<?> responseSender;
94
 
102
 
95
	@Autowired
103
	@Autowired
-
 
104
	private CategoryRepository repository;
-
 
105
 
-
 
106
	@Autowired
96
	private TagListingRepository tagListingRepository;
107
	private TagListingRepository tagListingRepository;
97
 
108
 
98
	@Autowired
109
	@Autowired
99
	private ItemRepository itemRepository;
110
	private ItemRepository itemRepository;
100
 
111
 
Line 227... Line 238...
227
			}
238
			}
228
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
239
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
229
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
240
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
230
			dealResponse = getCatalogResponse(docs, hotDeal);
241
			dealResponse = getCatalogResponse(docs, hotDeal);
231
			if (Mongo.EMAIL_BLOCKED_BRANDS.containsKey(userInfo.getEmail())) {
242
			if (Mongo.EMAIL_BLOCKED_BRANDS.containsKey(userInfo.getEmail())) {
-
 
243
				dealResponse.stream()
232
				dealResponse.stream().filter(x -> Mongo.EMAIL_BLOCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()));
244
						.filter(x -> Mongo.EMAIL_BLOCKED_BRANDS.get(userInfo.getEmail()).contains(x.getBrand()));
233
			}
245
			}
234
		} else {
246
		} else {
235
			return responseSender.badRequest(
247
			return responseSender.badRequest(
236
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
248
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
237
		}
249
		}
Line 416... Line 428...
416
		}
428
		}
417
		return responseSender.ok(dealResponse.get(0));
429
		return responseSender.ok(dealResponse.get(0));
418
	}
430
	}
419
 
431
 
420
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
432
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
433
	@Cacheable(value = "display", cacheManager = "thirtyMinsTimeOutCacheManager")
421
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
434
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
422
			@RequestParam(required = false, defaultValue = "0") int categoryId) {
435
			@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
423
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
436
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
437
		List<DBObject> brandsDisplay = null;
-
 
438
		if (categoryId == 3) {
424
		List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
439
			brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
-
 
440
		} else {
-
 
441
			brandsDisplay = this.getAccessories();
-
 
442
		}
425
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
443
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
426
	}
444
	}
427
 
445
 
-
 
446
	private List<DBObject> getAccessories() throws Exception {
-
 
447
		List<DBObject> subCategories = new ArrayList<>();
-
 
448
		RestClient rc = new RestClient();
-
 
449
		Map<String, String> params = new HashMap<>();
-
 
450
		params.put("q", "categoryId_i:6");
-
 
451
		params.put("group", "true");
-
 
452
		params.put("group.field", "subCategoryId_i");
-
 
453
		params.put("wt", "json");
-
 
454
		String response = null;
-
 
455
		try {
-
 
456
			response = rc.get(SchemeType.HTTP, "dtr", 8984, "solr/demo/select", params);
-
 
457
		} catch (HttpHostConnectException e) {
-
 
458
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
459
		}
-
 
460
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
-
 
461
		JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
-
 
462
		List<Integer> categoryIds = new ArrayList<>();
-
 
463
		for(int i=0;i< groups.length();i++) {
-
 
464
			JSONObject groupObject = groups.getJSONObject(i); 
-
 
465
			int subCategoryId =  groupObject.getInt("groupValue");
-
 
466
			int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
-
 
467
		}
-
 
468
		
-
 
469
		List<Category> categories = categoryRepository.selectByIds(categoryIds);
-
 
470
		AtomicInteger i= new AtomicInteger(0);
-
 
471
		categories.forEach(x->{
-
 
472
			DBObject object = new BasicDBObject();
-
 
473
			object.put("name", x.getLabel());
-
 
474
			object.put("rank", i.incrementAndGet());
-
 
475
			object.put("categoryId", 6);
-
 
476
			object.put("url", "http://api.profittill.com/uploads/campaigns/" + x.getId() + ".png");
-
 
477
		});
-
 
478
		
-
 
479
	}
-
 
480
 
428
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
481
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
429
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
482
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
430
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
483
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
431
	}
484
	}
432
 
485