Subversion Repositories SmartDukaan

Rev

Rev 26575 | Rev 26630 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21339 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.util.ArrayList;
22336 amit.gupta 4
import java.util.Arrays;
21339 kshitij.so 5
import java.util.HashMap;
23814 amit.gupta 6
import java.util.HashSet;
22952 amit.gupta 7
import java.util.Iterator;
21339 kshitij.so 8
import java.util.List;
9
import java.util.Map;
25875 amit.gupta 10
import java.util.Optional;
25959 amit.gupta 11
import java.util.Set;
25010 amit.gupta 12
import java.util.concurrent.atomic.AtomicInteger;
23814 amit.gupta 13
import java.util.stream.Collectors;
21339 kshitij.so 14
 
15
import javax.servlet.http.HttpServletRequest;
16
 
22319 amit.gupta 17
import org.apache.commons.lang3.StringUtils;
23532 amit.gupta 18
import org.apache.http.conn.HttpHostConnectException;
23786 amit.gupta 19
import org.apache.logging.log4j.LogManager;
20
import org.apache.logging.log4j.Logger;
22319 amit.gupta 21
import org.json.JSONArray;
22
import org.json.JSONObject;
22273 amit.gupta 23
import org.springframework.beans.factory.annotation.Autowired;
21339 kshitij.so 24
import org.springframework.beans.factory.annotation.Value;
25
import org.springframework.http.HttpStatus;
26
import org.springframework.http.MediaType;
27
import org.springframework.http.ResponseEntity;
28
import org.springframework.stereotype.Controller;
22286 amit.gupta 29
import org.springframework.transaction.annotation.Transactional;
21339 kshitij.so 30
import org.springframework.web.bind.annotation.PathVariable;
31
import org.springframework.web.bind.annotation.RequestMapping;
32
import org.springframework.web.bind.annotation.RequestMethod;
33
import org.springframework.web.bind.annotation.RequestParam;
34
 
35
import com.eclipsesource.json.Json;
36
import com.eclipsesource.json.JsonArray;
37
import com.eclipsesource.json.JsonObject;
38
import com.eclipsesource.json.JsonValue;
39
import com.google.gson.Gson;
21356 kshitij.so 40
import com.google.gson.reflect.TypeToken;
25010 amit.gupta 41
import com.mongodb.BasicDBObject;
24163 amit.gupta 42
import com.mongodb.DBObject;
21643 ashik.ali 43
import com.spice.profitmandi.common.enumuration.SchemeType;
21339 kshitij.so 44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22289 amit.gupta 46
import com.spice.profitmandi.common.model.UserInfo;
21643 ashik.ali 47
import com.spice.profitmandi.common.web.client.RestClient;
22319 amit.gupta 48
import com.spice.profitmandi.common.web.util.ResponseSender;
25010 amit.gupta 49
import com.spice.profitmandi.dao.entity.catalog.Category;
23426 amit.gupta 50
import com.spice.profitmandi.dao.entity.catalog.Item;
23814 amit.gupta 51
import com.spice.profitmandi.dao.entity.catalog.TagListing;
23861 amit.gupta 52
import com.spice.profitmandi.dao.entity.inventory.ItemAvailabilityCache;
22361 amit.gupta 53
import com.spice.profitmandi.dao.model.UserCart;
25010 amit.gupta 54
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
23426 amit.gupta 55
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23814 amit.gupta 56
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
22333 amit.gupta 57
import com.spice.profitmandi.dao.repository.dtr.Mongo;
22361 amit.gupta 58
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
22989 amit.gupta 59
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
23798 amit.gupta 60
import com.spice.profitmandi.service.authentication.RoleManager;
25880 amit.gupta 61
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
25882 amit.gupta 62
import com.spice.profitmandi.service.inventory.Bucket;
25880 amit.gupta 63
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
64
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
25875 amit.gupta 65
import com.spice.profitmandi.service.inventory.ItemBucketService;
25879 amit.gupta 66
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
22287 amit.gupta 67
import com.spice.profitmandi.service.pricing.PricingService;
21356 kshitij.so 68
import com.spice.profitmandi.web.res.DealBrands;
21339 kshitij.so 69
import com.spice.profitmandi.web.res.DealObjectResponse;
70
import com.spice.profitmandi.web.res.DealsResponse;
71
 
72
import io.swagger.annotations.ApiImplicitParam;
73
import io.swagger.annotations.ApiImplicitParams;
74
import io.swagger.annotations.ApiOperation;
75
 
76
@Controller
22319 amit.gupta 77
@Transactional(rollbackFor = Throwable.class)
21339 kshitij.so 78
public class DealsController {
79
 
23568 govind 80
	private static final Logger logger = LogManager.getLogger(DealsController.class);
21339 kshitij.so 81
 
82
	@Value("${python.api.host}")
83
	private String host;
23816 amit.gupta 84
 
21339 kshitij.so 85
	@Value("${python.api.port}")
86
	private int port;
23816 amit.gupta 87
 
88
	// This is now unused as we are not supporting multiple companies.
23300 amit.gupta 89
	@Value("${gadgetCops.invoice.cc}")
23816 amit.gupta 90
	private String[] ccGadgetCopInvoiceTo;
22319 amit.gupta 91
 
92
	@Autowired
93
	private PricingService pricingService;
23816 amit.gupta 94
 
22273 amit.gupta 95
	@Autowired
25010 amit.gupta 96
	private CategoryRepository categoryRepository;
97
 
98
	@Autowired
22333 amit.gupta 99
	private Mongo mongoClient;
25879 amit.gupta 100
 
25875 amit.gupta 101
	@Autowired
102
	private ItemBucketService itemBucketService;
23816 amit.gupta 103
 
22333 amit.gupta 104
	@Autowired
22361 amit.gupta 105
	private UserAccountRepository userAccountRepository;
23816 amit.gupta 106
 
22989 amit.gupta 107
	@Autowired
22931 ashik.ali 108
	private ResponseSender<?> responseSender;
23816 amit.gupta 109
 
22554 amit.gupta 110
	@Autowired
25010 amit.gupta 111
	private CategoryRepository repository;
112
 
113
	@Autowired
23814 amit.gupta 114
	private TagListingRepository tagListingRepository;
23816 amit.gupta 115
 
23814 amit.gupta 116
	@Autowired
23426 amit.gupta 117
	private ItemRepository itemRepository;
23816 amit.gupta 118
 
23786 amit.gupta 119
	@Autowired
23861 amit.gupta 120
	private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
121
 
122
	@Autowired
23798 amit.gupta 123
	private RoleManager roleManagerService;
23816 amit.gupta 124
 
22336 amit.gupta 125
	List<String> filterableParams = Arrays.asList("brand");
24949 amit.gupta 126
 
22319 amit.gupta 127
	@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21339 kshitij.so 128
	@ApiImplicitParams({
22319 amit.gupta 129
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21339 kshitij.so 130
	@ApiOperation(value = "Get deals")
22319 amit.gupta 131
	public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
132
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
133
			@RequestParam(value = "sort", required = false) String sort,
134
			@RequestParam(value = "direction", required = false) String direction,
23816 amit.gupta 135
			@RequestParam(value = "filterData", required = false) String filterData)
136
			throws ProfitMandiBusinessException {
22319 amit.gupta 137
		logger.info("Request " + request.getParameterMap());
21339 kshitij.so 138
		String response = null;
22319 amit.gupta 139
		int userId = (int) request.getAttribute("userId");
23816 amit.gupta 140
 
141
		// If pincode belongs to Specific warehouse marked
142
		// availability should be fetched for that warehouse only
143
		// show only skus belonging to that specific
144
		// else use normal flow
22319 amit.gupta 145
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
146
		// TODO: move to properties
147
		String uri = "/deals/" + userId;
23532 amit.gupta 148
		RestClient rc = new RestClient();
21339 kshitij.so 149
		Map<String, String> params = new HashMap<>();
150
		params.put("offset", offset);
151
		params.put("limit", limit);
152
		params.put("categoryId", categoryId);
153
		params.put("direction", direction);
154
		params.put("sort", sort);
155
		params.put("filterData", filterData);
22272 amit.gupta 156
		params.put("source", "deals");
23786 amit.gupta 157
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
22289 amit.gupta 158
			params.put("tag_ids", getCommaSeparateTags(userId));
159
		}
21356 kshitij.so 160
		List<Object> responseObject = new ArrayList<>();
23532 amit.gupta 161
		try {
23816 amit.gupta 162
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
23532 amit.gupta 163
		} catch (HttpHostConnectException e) {
164
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
165
		}
23816 amit.gupta 166
 
21339 kshitij.so 167
		JsonArray result_json = Json.parse(response).asArray();
22319 amit.gupta 168
		for (JsonValue j : result_json) {
23816 amit.gupta 169
			// logger.info("res " + j.asArray());
21339 kshitij.so 170
			List<Object> innerObject = new ArrayList<>();
22319 amit.gupta 171
			for (JsonValue jsonObject : j.asArray()) {
21356 kshitij.so 172
				innerObject.add(toDealObject(jsonObject.asObject()));
21339 kshitij.so 173
			}
22319 amit.gupta 174
			if (innerObject.size() > 0) {
21339 kshitij.so 175
				responseObject.add(innerObject);
176
			}
177
		}
23022 ashik.ali 178
		return responseSender.ok(responseObject);
21339 kshitij.so 179
	}
180
 
25876 amit.gupta 181
	@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
25879 amit.gupta 182
	public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
25875 amit.gupta 183
		logger.info("Request " + request.getParameterMap());
184
		return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
185
	}
25879 amit.gupta 186
 
187
	@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
25880 amit.gupta 188
	public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
25879 amit.gupta 189
			throws ProfitMandiBusinessException {
25880 amit.gupta 190
		List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
25968 amit.gupta 191
		Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream()
192
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
193
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
194
				.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
25879 amit.gupta 195
		RestClient rc = new RestClient();
196
		Map<String, String> params = new HashMap<>();
197
		List<String> mandatoryQ = new ArrayList<>();
25968 amit.gupta 198
		mandatoryQ.add(
199
				String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
25959 amit.gupta 200
		params.put("start", "0");
201
		params.put("rows", "100");
25879 amit.gupta 202
		params.put("q", StringUtils.join(mandatoryQ, " "));
203
		params.put("fl", "*, [child parentFilter=id:catalog*]");
204
 
205
		params.put("wt", "json");
206
		String response = null;
207
		try {
26573 amit.gupta 208
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
25879 amit.gupta 209
		} catch (HttpHostConnectException e) {
210
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
211
		}
212
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
213
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
25968 amit.gupta 214
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
26051 amit.gupta 215
 
26589 amit.gupta 216
		Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id)
217
				.collect(Collectors.toList()).get(0);
25882 amit.gupta 218
		bucket.setFofoCatalogResponses(dealResponse);
219
		return responseSender.ok(bucket);
25879 amit.gupta 220
	}
221
 
23816 amit.gupta 222
	private String getCommaSeparateTags(int userId) {
22361 amit.gupta 223
		UserCart uc = userAccountRepository.getUserCart(userId);
224
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
22287 amit.gupta 225
		List<String> strTagIds = new ArrayList<>();
226
		for (Integer tagId : tagIds) {
227
			strTagIds.add(String.valueOf(tagId));
22273 amit.gupta 228
		}
22287 amit.gupta 229
		return String.join(",", strTagIds);
22273 amit.gupta 230
	}
231
 
22319 amit.gupta 232
	@ApiImplicitParams({
233
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
234
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
24091 tejbeer 235
	public ResponseEntity<?> getFofo(HttpServletRequest request,
236
			@RequestParam(value = "categoryId", required = false, defaultValue = "(3 OR 6)") String categoryId,
22319 amit.gupta 237
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
23816 amit.gupta 238
			@RequestParam(value = "sort", required = false) String sort,
239
			@RequestParam(value = "brand", required = false) String brand,
25011 amit.gupta 240
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
24946 amit.gupta 241
			@RequestParam(value = "q", required = false) String queryTerm,
24091 tejbeer 242
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
22328 amit.gupta 243
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
22319 amit.gupta 244
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
23786 amit.gupta 245
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
25879 amit.gupta 246
			// UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
25389 tejbeer 247
			List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getRetailerId());
23816 amit.gupta 248
			RestClient rc = new RestClient();
22319 amit.gupta 249
			Map<String, String> params = new HashMap<>();
22336 amit.gupta 250
			List<String> mandatoryQ = new ArrayList<>();
24974 amit.gupta 251
			if (queryTerm != null && !queryTerm.equals("null")) {
24975 amit.gupta 252
				mandatoryQ.add(String.format("+(%s)", queryTerm));
253
			} else {
254
				queryTerm = null;
24971 amit.gupta 255
			}
25015 amit.gupta 256
			if (subCategoryId != 0) {
24949 amit.gupta 257
				mandatoryQ
258
						.add(String.format("+(subCategoryId_i:%s) +{!parent which=\"subCategoryId_i:%s\"} tagId_i:(%s)",
24875 amit.gupta 259
								subCategoryId, subCategoryId, StringUtils.join(tagIds, " ")));
23814 amit.gupta 260
			} else if (hotDeal) {
23816 amit.gupta 261
				mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
262
						StringUtils.join(tagIds, " ")));
25015 amit.gupta 263
 
264
			} else if (StringUtils.isNotBlank(brand)) {
265
				mandatoryQ.add(
266
						String.format("+(categoryId_i:%s) +(brand_ss:%s) +{!parent which=\"brand_ss:%s\"} tagId_i:(%s)",
267
								categoryId, brand, brand, StringUtils.join(tagIds, " ")));
268
 
22347 amit.gupta 269
			} else {
23816 amit.gupta 270
				mandatoryQ.add(
271
						String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
22336 amit.gupta 272
			}
23816 amit.gupta 273
			params.put("q", StringUtils.join(mandatoryQ, " "));
22319 amit.gupta 274
			params.put("fl", "*, [child parentFilter=id:catalog*]");
24995 amit.gupta 275
			if (queryTerm == null) {
24975 amit.gupta 276
				params.put("sort", "create_s desc");
277
			}
22319 amit.gupta 278
			params.put("start", String.valueOf(offset));
279
			params.put("rows", String.valueOf(limit));
280
			params.put("wt", "json");
23532 amit.gupta 281
			String response = null;
282
			try {
26575 amit.gupta 283
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
23532 amit.gupta 284
			} catch (HttpHostConnectException e) {
285
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
286
			}
22319 amit.gupta 287
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
288
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
24149 amit.gupta 289
			dealResponse = getCatalogResponse(docs, hotDeal);
26589 amit.gupta 290
			/*
291
			 * if (Mongo.PARTNER_BLoCKED_BRANDS.containsKey(userInfo.getEmail())) {
292
			 * dealResponse.stream() .filter(x ->
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
 
24168 amit.gupta 323
			}
26589 amit.gupta 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
			 */
22319 amit.gupta 369
		} else {
23816 amit.gupta 370
			return responseSender.badRequest(
371
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
22319 amit.gupta 372
		}
373
		return responseSender.ok(dealResponse);
374
	}
22273 amit.gupta 375
 
22319 amit.gupta 376
	@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22272 amit.gupta 377
	@ApiImplicitParams({
22319 amit.gupta 378
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
22272 amit.gupta 379
	@ApiOperation(value = "Get online deals")
22319 amit.gupta 380
	public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
381
			@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
382
			@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
383
			@RequestParam(value = "direction", required = false) String direction,
384
			@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
385
		logger.info("Request " + request.getParameterMap());
22272 amit.gupta 386
		String response = null;
22319 amit.gupta 387
		int userId = (int) request.getAttribute("userId");
22289 amit.gupta 388
 
22319 amit.gupta 389
		String uri = "/deals/" + userId;
23532 amit.gupta 390
		RestClient rc = new RestClient();
22272 amit.gupta 391
		Map<String, String> params = new HashMap<>();
392
		params.put("offset", offset);
393
		params.put("limit", limit);
394
		params.put("categoryId", categoryId);
395
		params.put("direction", direction);
396
		params.put("sort", sort);
397
		params.put("source", "online");
398
		params.put("filterData", filterData);
23816 amit.gupta 399
		/*
400
		 * if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
401
		 * params.put("tag_ids", getCommaSeparateTags(userId)); }
402
		 */
22272 amit.gupta 403
		List<Object> responseObject = new ArrayList<>();
23532 amit.gupta 404
		try {
405
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
406
		} catch (HttpHostConnectException e) {
407
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
408
		}
22931 ashik.ali 409
 
22272 amit.gupta 410
		JsonArray result_json = Json.parse(response).asArray();
22319 amit.gupta 411
		for (JsonValue j : result_json) {
23816 amit.gupta 412
			// logger.info("res " + j.asArray());
22272 amit.gupta 413
			List<Object> innerObject = new ArrayList<>();
22319 amit.gupta 414
			for (JsonValue jsonObject : j.asArray()) {
22272 amit.gupta 415
				innerObject.add(toDealObject(jsonObject.asObject()));
416
			}
22319 amit.gupta 417
			if (innerObject.size() > 0) {
22272 amit.gupta 418
				responseObject.add(innerObject);
419
			}
420
		}
23022 ashik.ali 421
		return responseSender.ok(responseObject);
22272 amit.gupta 422
	}
423
 
22319 amit.gupta 424
	private Object toDealObject(JsonObject jsonObject) {
425
		if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
21339 kshitij.so 426
			return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
427
		}
428
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
429
	}
22319 amit.gupta 430
 
431
	@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21356 kshitij.so 432
	@ApiImplicitParams({
22319 amit.gupta 433
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21356 kshitij.so 434
	@ApiOperation(value = "Get brand list and count for category")
22319 amit.gupta 435
	public ResponseEntity<?> getBrands(HttpServletRequest request,
23816 amit.gupta 436
			@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
22319 amit.gupta 437
		logger.info("Request " + request.getParameterMap());
21356 kshitij.so 438
		String response = null;
22319 amit.gupta 439
		// TODO: move to properties
21356 kshitij.so 440
		String uri = ProfitMandiConstants.URL_BRANDS;
23532 amit.gupta 441
		RestClient rc = new RestClient();
21356 kshitij.so 442
		Map<String, String> params = new HashMap<>();
443
		params.put("category_id", category_id);
21358 kshitij.so 444
		List<DealBrands> dealBrandsResponse = null;
23532 amit.gupta 445
		try {
446
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
447
		} catch (HttpHostConnectException e) {
448
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
449
		}
23816 amit.gupta 450
 
22319 amit.gupta 451
		dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
452
		}.getType());
23022 ashik.ali 453
 
454
		return responseSender.ok(dealBrandsResponse);
21356 kshitij.so 455
	}
22319 amit.gupta 456
 
457
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
21445 kshitij.so 458
	@ApiImplicitParams({
22319 amit.gupta 459
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21445 kshitij.so 460
	@ApiOperation(value = "Get unit deal object")
23816 amit.gupta 461
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
462
			throws ProfitMandiBusinessException {
21445 kshitij.so 463
		String response = null;
22319 amit.gupta 464
		// TODO: move to properties
465
		String uri = "getDealById/" + id;
466
		System.out.println("Unit deal " + uri);
23532 amit.gupta 467
		RestClient rc = new RestClient();
21445 kshitij.so 468
		Map<String, String> params = new HashMap<>();
469
		DealsResponse dealsResponse = null;
23532 amit.gupta 470
		try {
471
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
472
		} catch (HttpHostConnectException e) {
473
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
474
		}
23816 amit.gupta 475
 
21445 kshitij.so 476
		JsonObject result_json = Json.parse(response).asObject();
22319 amit.gupta 477
		if (!result_json.isEmpty()) {
21445 kshitij.so 478
			dealsResponse = new Gson().fromJson(response, DealsResponse.class);
22952 amit.gupta 479
			Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
23816 amit.gupta 480
			while (iter.hasNext()) {
22952 amit.gupta 481
				AvailabilityInfo ai = iter.next();
23816 amit.gupta 482
				if (ai.getAvailability() <= 0)
22952 amit.gupta 483
					iter.remove();
484
			}
21445 kshitij.so 485
		}
22952 amit.gupta 486
		return responseSender.ok(dealsResponse);
21445 kshitij.so 487
	}
23816 amit.gupta 488
 
24091 tejbeer 489
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
490
	@ApiImplicitParams({
491
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
492
	@ApiOperation(value = "Get unit deal object")
493
	public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
494
			throws ProfitMandiBusinessException {
495
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
496
		List<Integer> tagIds = Arrays.asList(4);
497
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
498
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
499
			String categoryId = "(3 OR 6)";
500
			UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
501
			RestClient rc = new RestClient();
502
			Map<String, String> params = new HashMap<>();
503
			List<String> mandatoryQ = new ArrayList<>();
504
			String catalogString = "catalog" + id;
505
 
24149 amit.gupta 506
			mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
507
					categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
508
 
24091 tejbeer 509
			params.put("q", StringUtils.join(mandatoryQ, " "));
510
			params.put("fl", "*, [child parentFilter=id:catalog*]");
511
			params.put("sort", "rank_i asc, create_s desc");
512
			params.put("wt", "json");
513
			String response = null;
514
			try {
26575 amit.gupta 515
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
24091 tejbeer 516
			} catch (HttpHostConnectException e) {
517
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
518
			}
519
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
520
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
24149 amit.gupta 521
			dealResponse = getCatalogResponse(docs, false);
24091 tejbeer 522
		} else {
523
			return responseSender.badRequest(
524
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
525
		}
526
		return responseSender.ok(dealResponse.get(0));
527
	}
528
 
22333 amit.gupta 529
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
24949 amit.gupta 530
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
25010 amit.gupta 531
			@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
24163 amit.gupta 532
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
25543 amit.gupta 533
		logger.info("userInfo [{}]", userInfo);
25879 amit.gupta 534
		List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
535
				categoryId);
24163 amit.gupta 536
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
22333 amit.gupta 537
	}
25879 amit.gupta 538
 
25813 amit.gupta 539
	@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
540
	public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
541
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
542
		logger.info("userInfo [{}]", userInfo);
543
		List<DBObject> subCateogriesDisplay = this.getSubCategoriesToDisplay();
544
		return new ResponseEntity<>(subCateogriesDisplay, HttpStatus.OK);
545
	}
23816 amit.gupta 546
 
25011 amit.gupta 547
	private List<DBObject> getSubCategoriesToDisplay() throws Exception {
25010 amit.gupta 548
		List<DBObject> subCategories = new ArrayList<>();
549
		RestClient rc = new RestClient();
550
		Map<String, String> params = new HashMap<>();
551
		params.put("q", "categoryId_i:6");
552
		params.put("group", "true");
553
		params.put("group.field", "subCategoryId_i");
554
		params.put("wt", "json");
25126 amit.gupta 555
		params.put("rows", "50");
25014 amit.gupta 556
		params.put("fl", "subCategoryId_i");
25010 amit.gupta 557
		String response = null;
558
		try {
26575 amit.gupta 559
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
25010 amit.gupta 560
		} catch (HttpHostConnectException e) {
561
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
562
		}
563
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
564
		JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
565
		List<Integer> categoryIds = new ArrayList<>();
25015 amit.gupta 566
		for (int i = 0; i < groups.length(); i++) {
567
			JSONObject groupObject = groups.getJSONObject(i);
568
			int subCategoryId = groupObject.getInt("groupValue");
25010 amit.gupta 569
			int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
25013 amit.gupta 570
			categoryIds.add(subCategoryId);
25010 amit.gupta 571
		}
25015 amit.gupta 572
 
25010 amit.gupta 573
		List<Category> categories = categoryRepository.selectByIds(categoryIds);
25015 amit.gupta 574
		AtomicInteger i = new AtomicInteger(0);
575
		categories.forEach(x -> {
25011 amit.gupta 576
			DBObject dbObject = new BasicDBObject();
577
			dbObject.put("name", x.getLabel());
578
			dbObject.put("subCategoryId", x.getId());
579
			dbObject.put("rank", i.incrementAndGet());
580
			dbObject.put("categoryId", 6);
26441 tejbeer 581
			dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
25011 amit.gupta 582
			subCategories.add(dbObject);
25010 amit.gupta 583
		});
25015 amit.gupta 584
 
25011 amit.gupta 585
		return subCategories;
25015 amit.gupta 586
 
25010 amit.gupta 587
	}
588
 
22446 amit.gupta 589
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22448 amit.gupta 590
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
22447 amit.gupta 591
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
22446 amit.gupta 592
	}
23816 amit.gupta 593
 
23793 tejbeer 594
	@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
595
	public ResponseEntity<?> getSubcategoriesToDisplay() {
596
		return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
597
	}
23816 amit.gupta 598
 
22406 amit.gupta 599
	@ApiImplicitParams({
23816 amit.gupta 600
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
22401 amit.gupta 601
	@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
22931 ashik.ali 602
	public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
22401 amit.gupta 603
		StringBuffer sb = new StringBuffer("/getDealsForNotification/");
604
		String uri = sb.append(skus).toString();
23532 amit.gupta 605
		RestClient rc = new RestClient();
606
		String response;
607
		try {
608
			response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
23816 amit.gupta 609
		} catch (HttpHostConnectException e) {
23532 amit.gupta 610
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
611
		}
22406 amit.gupta 612
		JsonArray result_json = Json.parse(response).asArray();
22407 amit.gupta 613
		List<Object> responseObject = new ArrayList<>();
614
		for (JsonValue j : result_json) {
23816 amit.gupta 615
			// logger.info("res " + j.asArray());
22407 amit.gupta 616
			List<Object> innerObject = new ArrayList<>();
617
			for (JsonValue jsonObject : j.asArray()) {
618
				innerObject.add(toDealObject(jsonObject.asObject()));
619
			}
620
			if (innerObject.size() > 0) {
621
				responseObject.add(innerObject);
622
			}
623
		}
22408 amit.gupta 624
		return responseSender.ok(responseObject);
22401 amit.gupta 625
	}
21339 kshitij.so 626
 
24149 amit.gupta 627
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal)
628
			throws ProfitMandiBusinessException {
24091 tejbeer 629
		Map<Integer, TagListing> itemTagListingMap = null;
630
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
631
		List<Integer> tagIds = Arrays.asList(4);
632
		if (docs.length() > 0) {
633
			HashSet<Integer> itemsSet = new HashSet<>();
634
			for (int i = 0; i < docs.length(); i++) {
635
				JSONObject doc = docs.getJSONObject(i);
26589 amit.gupta 636
				if (doc.has("_childDocuments_")) {
26515 amit.gupta 637
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
638
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
639
						int itemId = childItem.getInt("itemId_i");
640
						itemsSet.add(itemId);
641
					}
24091 tejbeer 642
				}
643
			}
26589 amit.gupta 644
			if (itemsSet.size() == 0) {
26573 amit.gupta 645
				return dealResponse;
646
			}
24091 tejbeer 647
			itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
648
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
649
		}
650
 
651
		for (int i = 0; i < docs.length(); i++) {
652
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
653
			JSONObject doc = docs.getJSONObject(i);
654
			FofoCatalogResponse ffdr = new FofoCatalogResponse();
655
			ffdr.setCatalogId(doc.getInt("catalogId_i"));
656
			ffdr.setImageUrl(doc.getString("imageUrl_s"));
657
			ffdr.setTitle(doc.getString("title_s"));
24117 amit.gupta 658
			try {
659
				ffdr.setFeature(doc.getString("feature_s"));
24149 amit.gupta 660
			} catch (Exception e) {
24117 amit.gupta 661
				ffdr.setFeature(null);
24149 amit.gupta 662
				logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
24117 amit.gupta 663
			}
24091 tejbeer 664
			ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
26589 amit.gupta 665
			if (doc.has("_childDocuments_")) {
26515 amit.gupta 666
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
667
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
668
					int itemId = childItem.getInt("itemId_i");
669
					TagListing tl = itemTagListingMap.get(itemId);
670
					if (tl == null) {
671
						logger.warn("Could not find item id {}", itemId);
24091 tejbeer 672
						continue;
673
					}
26515 amit.gupta 674
					if (hotDeal) {
675
						if (!tl.isHotDeals()) {
676
							continue;
677
						}
24091 tejbeer 678
					}
26515 amit.gupta 679
					float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
680
					if (fofoAvailabilityInfoMap.containsKey(itemId)) {
681
						if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
682
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
683
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
684
						}
24091 tejbeer 685
					} else {
26515 amit.gupta 686
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
687
						fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
688
						fdi.setMop((float) childItem.getDouble("mop_f"));
689
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
690
						fdi.setTagId(childItem.getInt("tagId_i"));
691
						fdi.setItem_id(itemId);
692
						Item item = itemRepository.selectById(itemId);
693
						// In case its tampered glass moq should be 5
694
						if (item.getCategoryId() == 10020) {
695
							fdi.setMinBuyQuantity(10);
696
						} else {
697
							fdi.setMinBuyQuantity(1);
24091 tejbeer 698
						}
26515 amit.gupta 699
						if (hotDeal || !tl.isActive()) {
26589 amit.gupta 700
 
26515 amit.gupta 701
							int totalAvailability = 0; // Using item availability
702
							// cache for now but can be
703
							// changed to
704
							// use caching later.
705
							try {
706
								ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
707
								totalAvailability = iac.getTotalAvailability();
708
								fdi.setAvailability(totalAvailability);
709
							} catch (Exception e) {
710
								continue;
711
							}
712
							if (totalAvailability <= 0) {
713
								continue;
714
							}
715
						} else {
716
							// For accessories item availability should at be ordered for Rs.1000
717
							fdi.setAvailability(100);
24091 tejbeer 718
						}
26515 amit.gupta 719
						fdi.setQuantityStep(1);
720
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
721
						fofoAvailabilityInfoMap.put(itemId, fdi);
24091 tejbeer 722
					}
723
				}
724
			}
725
			if (fofoAvailabilityInfoMap.values().size() > 0) {
726
				ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
727
				dealResponse.add(ffdr);
728
			}
729
		}
730
		return dealResponse;
731
 
732
	}
733
 
25968 amit.gupta 734
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
735
			boolean hotDeal) throws ProfitMandiBusinessException {
25879 amit.gupta 736
		Map<Integer, TagListing> itemTagListingMap = null;
737
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
738
		List<Integer> tagIds = Arrays.asList(4);
26589 amit.gupta 739
 
25968 amit.gupta 740
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
741
				.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
25880 amit.gupta 742
 
25879 amit.gupta 743
		for (int i = 0; i < docs.length(); i++) {
744
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
745
			JSONObject doc = docs.getJSONObject(i);
25880 amit.gupta 746
 
25879 amit.gupta 747
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
748
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
749
				int itemId = childItem.getInt("itemId_i");
750
				TagListing tl = itemTagListingMap.get(itemId);
26589 amit.gupta 751
				if (tl == null) {
25968 amit.gupta 752
					continue;
753
				}
25879 amit.gupta 754
				if (hotDeal) {
755
					if (!tl.isHotDeals()) {
756
						continue;
757
					}
758
				}
759
				float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
760
				if (fofoAvailabilityInfoMap.containsKey(itemId)) {
761
					if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
762
						fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
763
						fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
764
					}
765
				} else {
766
					FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
767
					fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
768
					fdi.setMop((float) childItem.getDouble("mop_f"));
769
					fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
770
					fdi.setTagId(childItem.getInt("tagId_i"));
771
					fdi.setItem_id(itemId);
772
					Item item = itemRepository.selectById(itemId);
773
					// In case its tampered glass moq should be 5
774
					if (item.getCategoryId() == 10020) {
775
						fdi.setMinBuyQuantity(10);
776
					} else {
777
						fdi.setMinBuyQuantity(1);
778
					}
26050 amit.gupta 779
					fdi.setAvailability(itemFilter.get(itemId));
25879 amit.gupta 780
					fdi.setQuantityStep(1);
781
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
782
					fofoAvailabilityInfoMap.put(itemId, fdi);
783
				}
784
			}
785
			if (fofoAvailabilityInfoMap.values().size() > 0) {
25880 amit.gupta 786
				for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
25879 amit.gupta 787
					FofoCatalogResponse ffdr = new FofoCatalogResponse();
788
					ffdr.setCatalogId(doc.getInt("catalogId_i"));
789
					ffdr.setImageUrl(doc.getString("imageUrl_s"));
790
					ffdr.setTitle(doc.getString("title_s"));
791
					try {
792
						ffdr.setFeature(doc.getString("feature_s"));
793
					} catch (Exception e) {
794
						ffdr.setFeature(null);
795
						logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
796
					}
797
					ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
798
					ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
799
					dealResponse.add(ffdr);
800
				}
801
			}
802
		}
803
		return dealResponse;
25880 amit.gupta 804
 
25879 amit.gupta 805
	}
25967 amit.gupta 806
}