Subversion Repositories SmartDukaan

Rev

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