Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
31604 tejbeer 1
package com.spice.profitmandi.dao.service.solr;
2
 
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
7
import java.net.HttpURLConnection;
8
import java.net.URL;
9
import java.net.URLConnection;
10
import java.time.ZoneId;
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Map.Entry;
17
import java.util.stream.Collectors;
18
import java.util.zip.GZIPInputStream;
19
 
20
import org.apache.logging.log4j.LogManager;
21
import org.apache.logging.log4j.Logger;
22
import org.apache.solr.client.solrj.SolrClient;
23
import org.apache.solr.client.solrj.impl.HttpSolrClient;
31612 tejbeer 24
import org.apache.solr.client.solrj.response.schema.SchemaResponse.UpdateResponse;
31604 tejbeer 25
import org.apache.solr.common.SolrInputDocument;
26
import org.json.JSONArray;
27
import org.json.JSONException;
28
import org.json.JSONObject;
29
import org.springframework.beans.factory.annotation.Autowired;
30
import org.springframework.stereotype.Component;
31
 
32
import com.google.gson.Gson;
33
import com.spice.profitmandi.dao.entity.catalog.TagListing;
34
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
31612 tejbeer 35
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
31604 tejbeer 36
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
37
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
38
import com.spice.profitmandi.dao.repository.dtr.Mongo;
31612 tejbeer 39
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
40
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
31604 tejbeer 41
import com.spice.profitmandi.service.tag.ItemTagModel;
42
 
43
import in.shop2020.model.v1.catalog.status;
44
 
45
@Component
46
public class FofoSolr {
47
 
48
	@Autowired
49
	private Gson gson;
50
 
51
	@Autowired
52
	private TagListingRepository tagListingRepository;
53
 
54
	@Autowired
55
	TagRankingRepository tagRankingRepository;
56
 
57
	@Autowired
58
	private Mongo contentMongoClient;
59
 
31612 tejbeer 60
	@Autowired
61
	private WebListingRepository webListingRepository;
62
 
63
	@Autowired
64
	private WebProductListingRepository webProductListingRepository;
65
 
31604 tejbeer 66
	private static final Logger logger = LogManager.getLogger(FofoSolr.class);
67
 
68
	private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
69
 
70
	String solrPath = "http://localhost:8984/solr/demo";
71
	String mongoHost = "localhost";
72
	SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
73
 
74
	private String getAvailabilityJSON() {
75
		String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
76
		return getUrlContent(url);
77
	}
78
 
79
	private String getPendingPOJSON() {
80
		String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
81
		return getUrlContent(url);
82
	}
83
 
84
	private static String getUrlContent(String urlString) {
85
		BufferedReader reader = null;
86
		try {
87
			URL url = new URL(urlString);
88
			URLConnection conn = url.openConnection();
89
			conn.setConnectTimeout(5000);
90
			conn.setReadTimeout(5000);
91
			reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
92
			return reader.lines().collect(Collectors.joining(System.lineSeparator()));
93
		} catch (IOException e) {
94
			e.printStackTrace();
95
		} finally {
96
			if (reader != null) {
97
				try {
98
					reader.close();
99
				} catch (IOException e) {
100
					e.printStackTrace();
101
				}
102
			}
103
		}
104
		return null;
105
	}
106
 
107
	public JSONArray getAvailability() throws IOException, JSONException {
108
		String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
109
		HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
110
		connection.setRequestProperty("Accept-Encoding", "gzip");
111
		BufferedReader reader = null;
112
 
113
		try {
114
			InputStream inputStream = connection.getInputStream();
115
 
116
			if ("gzip".equals(connection.getContentEncoding())) {
117
				inputStream = new GZIPInputStream(inputStream);
118
			}
119
 
120
			reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
121
			StringBuilder responseBuilder = new StringBuilder();
122
			String line;
123
 
124
			while ((line = reader.readLine()) != null) {
125
				responseBuilder.append(line);
126
			}
127
 
128
			JSONObject responseJson = new JSONObject(responseBuilder.toString());
129
			return responseJson.getJSONArray("data");
130
		} finally {
131
			if (reader != null) {
132
				try {
133
					reader.close();
134
				} catch (IOException e) {
135
					// Ignore
136
				}
137
			}
138
		}
139
	}
140
 
141
	public JSONArray getPendingPO() throws IOException, JSONException {
142
		String url = "http://50.116.10.120/reports/run.php?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
143
		HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
144
		connection.setRequestProperty("Accept-Encoding", "gzip");
145
		BufferedReader reader = null;
146
 
147
		try {
148
			InputStream inputStream = connection.getInputStream();
149
 
150
			if ("gzip".equals(connection.getContentEncoding())) {
151
				inputStream = new GZIPInputStream(inputStream);
152
			}
153
 
154
			reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
155
			StringBuilder responseBuilder = new StringBuilder();
156
			String line;
157
 
158
			while ((line = reader.readLine()) != null) {
159
				responseBuilder.append(line);
160
			}
161
 
162
			JSONObject responseJson = new JSONObject(responseBuilder.toString());
163
			return responseJson.getJSONArray("data");
164
		} finally {
165
			if (reader != null) {
166
				try {
167
					reader.close();
168
				} catch (IOException e) {
169
					// Ignore
170
				}
171
			}
172
		}
173
	}
174
 
175
	public Map<String, Map<String, Map<String, Integer>>> getItemMap() throws Exception {
176
		JSONArray availabilityJSONArray = this.getAvailability();
177
		JSONArray pendingPOJSONArray = this.getPendingPO();
178
		Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = new HashMap<>();
179
 
180
		for (int i = 0; i < availabilityJSONArray.length(); i++) {
181
			JSONObject rawAvailability = availabilityJSONArray.getJSONObject(i);
182
			if (!availabilityItemMap.containsKey(rawAvailability.getString("Itemid"))) {
183
				availabilityItemMap.put(rawAvailability.getString("Itemid"),
184
						new HashMap<String, Map<String, Integer>>());
185
			}
186
			if (!availabilityItemMap.get(rawAvailability.getString("Itemid"))
187
					.containsKey(rawAvailability.getString("Warehouseid"))) {
188
				availabilityItemMap.get(rawAvailability.getString("Itemid"))
189
						.put(rawAvailability.getString("Warehouseid"), new HashMap<String, Integer>());
190
				availabilityItemMap.get(rawAvailability.getString("Itemid"))
191
						.get(rawAvailability.getString("Warehouseid")).put("netAvailability", 0);
192
				availabilityItemMap.get(rawAvailability.getString("Itemid"))
193
						.get(rawAvailability.getString("Warehouseid")).put("netPo", 0);
194
			}
195
			int netAvailability = availabilityItemMap.get(rawAvailability.getString("Itemid"))
196
					.get(rawAvailability.getString("Warehouseid")).get("netAvailability")
197
					+ rawAvailability.getInt("Netavailability");
198
			availabilityItemMap.get(rawAvailability.getString("Itemid")).get(rawAvailability.getString("Warehouseid"))
199
					.put("netAvailability", netAvailability);
200
		}
201
 
202
		for (int i = 0; i < pendingPOJSONArray.length(); i++) {
203
			JSONObject rawPendingPo = pendingPOJSONArray.getJSONObject(i);
204
 
205
			String itemId = rawPendingPo.getString("Itemid");
206
			String warehouseId = rawPendingPo.getString("Warehouseid");
207
			if (!availabilityItemMap.containsKey(itemId)) {
208
				availabilityItemMap.put(itemId, new HashMap<String, Map<String, Integer>>());
209
			}
210
			if (!availabilityItemMap.get(itemId).containsKey(warehouseId)) {
211
				availabilityItemMap.get(itemId).put(warehouseId, new HashMap<String, Integer>() {
212
					{
213
						put("netAvailability", 0);
214
						put("netPo", 0);
215
					}
216
				});
217
			}
218
			availabilityItemMap.get(itemId).get(warehouseId).put("netPo",
219
					availabilityItemMap.get(itemId).get(warehouseId).get("netPo") + rawPendingPo.getInt("Unfulfilled"));
220
 
221
		}
222
		return availabilityItemMap;
223
 
224
	}
225
 
31612 tejbeer 226
	public Map<Integer, List<String>> getLabels() {
227
		List<String> labels = Arrays.asList("partner-best-sellers", "partner-price-drop", "new-launches");
228
 
229
		Map<Integer, String> webListing = webListingRepository.selectByUrls(labels).stream()
230
				.collect(Collectors.toMap(x -> x.getId(), x -> x.getUrl()));
231
 
232
		Map<Integer, List<WebProductListing>> webProductListingMap = webProductListingRepository
233
				.selectAllByWebListingIds(new ArrayList<>(webListing.keySet())).stream()
234
				.collect(Collectors.groupingBy(x -> x.getWebListingId()));
235
 
236
		Map<Integer, List<String>> catalogLabelMap = new HashMap<>();
237
		for (Entry<Integer, List<WebProductListing>> webProductListingEntry : webProductListingMap.entrySet()) {
238
 
239
			for (WebProductListing webProduct : webProductListingEntry.getValue()) {
240
 
241
				if (!catalogLabelMap.containsKey(webProduct.getEntityId())) {
242
 
243
					catalogLabelMap.put(webProduct.getEntityId(), new ArrayList<>());
244
 
245
				}
246
 
247
				List<String> itemLabels = catalogLabelMap.get(webProduct.getEntityId());
248
				itemLabels.add(webListing.get(webProduct.getWebListingId()));
249
				catalogLabelMap.put(webProduct.getEntityId(), itemLabels);
250
 
251
			}
252
 
253
		}
254
 
255
		return catalogLabelMap;
256
	}
257
 
31604 tejbeer 258
	public void populateTagItems() throws Exception {
259
		Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
260
		List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
261
		List<Integer> rankingList = new ArrayList<>();
262
		Map<Integer, String> featureMap = new HashMap<>();
263
		for (TagRanking tagRanking : tagRankingList) {
264
			rankingList.add(tagRanking.getCatalogItemId());
265
			featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
266
		}
267
		Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
268
 
31612 tejbeer 269
		List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
270
 
271
		Map<Integer, List<String>> catalogLabelMap = this.getLabels();
272
 
273
		logger.info("catalogLabelMap {}", catalogLabelMap);
274
 
275
		/*
276
		 * List<ItemTagModel> tuples =
277
		 * tagListingRepository.getAllItemTagByStatus(statuses).stream() .filter(x ->
278
		 * x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());
279
		 */
280
 
31604 tejbeer 281
		List<ItemTagModel> tuples = tagListingRepository.getAllItemTagByStatus(statuses);
282
 
283
		Map<String, Object> projection = new HashMap<>();
284
		projection.put("defaultImageUrl", 1);
285
 
31612 tejbeer 286
		List<String> excludeBrands = Arrays.asList("Live Demo", "Dummy", "FOC HANDSET");
31604 tejbeer 287
 
288
		for (ItemTagModel result : tuples) {
289
			TagListing tag = result.getTagListing();
290
			com.spice.profitmandi.dao.entity.catalog.Item item = result.getItem();
291
			if (excludeBrands.contains(item.getBrand())) {
292
				continue;
293
			}
294
 
295
			if (!catalogMap.containsKey(item.getCatalogItemId())) {
296
				Map<String, Object> catalogObj = new HashMap<>();
297
				catalogObj.put("feature", "");
298
				catalogObj.put("title",
299
						String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
300
								.stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
31612 tejbeer 301
				catalogObj.put("brand", new String[] { item.getBrand() });
31604 tejbeer 302
				if (item.getBrand().equals("Huawei") || item.getBrand().equals("Honor")) {
303
					catalogObj.put("brand", new String[] { "Huawei", "Honor" });
304
				}
305
				if (item.getBrand().equals("Mi") || item.getBrand().equals("Xiaomi")
306
						|| item.getBrand().equals("Redmi")) {
307
					catalogObj.put("brand", new String[] { "Mi", "Xiaomi", "Redmi" });
308
				}
309
				catalogObj.put("identifier", item.getCatalogItemId());
310
				catalogObj.put("items", new HashMap<Integer, Map<String, Object>>());
311
				Map<String, Object> filterMap = new HashMap<>();
312
				filterMap.put("_id", item.getCatalogItemId());
313
				// Don't include if catalog not available
314
				try {
315
 
316
					catalogObj.put("imageUrl",
317
							contentMongoClient.getEntityById(item.getCatalogItemId()).getDefaultImageUrl());
318
					System.out.println(catalogObj.get("imageUrl"));
319
				} catch (Exception e) {
320
					try {
321
						catalogObj.put("imageUrl",
322
								"https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
323
					} catch (Exception e2) {
324
						e2.printStackTrace();
325
					}
326
				}
327
				try {
328
					catalogObj.put("rank", rankingList.indexOf(item.getCatalogItemId()));
329
				} catch (Exception e) {
330
					// A very big number
331
					e.printStackTrace();
332
					catalogObj.put("rank", 50000000);
333
				}
334
				if (featureMap.containsKey(item.getCatalogItemId())
335
						&& featureMap.get(item.getCatalogItemId()) != null) {
336
					catalogObj.put("feature", featureMap.get(item.getCatalogItemId()));
337
 
338
					catalogObj.put("categoryId",
339
							CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
340
 
341
				}
342
 
343
				if (item.getCategoryId() == 10006) {
344
					catalogObj.put("categoryId", 3);
345
				}
346
				catalogObj.put("subCategoryId", item.getCategoryId());
31612 tejbeer 347
				catalogObj.put("create_timestamp",
348
						tag.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
349
 
350
				if (catalogLabelMap.containsKey(item.getCatalogItemId())
351
						&& catalogLabelMap.get(item.getCatalogItemId()) != null) {
352
					catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
353
 
354
				}
31604 tejbeer 355
				catalogMap.put(item.getCatalogItemId(), catalogObj);
356
				catalogObj.put("avColor", new HashMap<>());
31612 tejbeer 357
 
31604 tejbeer 358
			}
359
 
360
			Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
361
			Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
362
 
363
			if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
364
				for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
365
						.get(String.valueOf(item.getId())).entrySet()) {
366
					String warehouseId = entry.getKey();
367
					Map<String, Integer> avMap = entry.getValue();
368
					if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
369
						avColorMap.put(Integer.parseInt(warehouseId), 0);
370
					}
371
					int color = avColorMap.get(Integer.parseInt(warehouseId));
372
 
373
					if (avMap.get("netAvailability") > 0) {
374
						color = 2;
375
					} else if (avMap.get("netAvailability") + avMap.get("netPo") > 0) {
376
						color = Math.max(color, 1);
377
					} else {
378
						color = Math.max(color, 0);
379
					}
380
					avColorMap.put(Integer.parseInt(warehouseId), color);
381
 
382
					catalogObj.put("avColor", avColorMap);
383
 
384
				}
385
 
386
			}
387
 
388
			Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
389
 
390
			if (!itemColorMap.containsKey(item.getId())) {
391
				itemColorMap.put(item.getId(), new HashMap<String, Object>() {
392
					{
393
						put("color", item.getColor().replace("f_", ""));
394
						put("tagPricing", new ArrayList<TagListing>());
395
					}
396
				});
397
			}
398
			Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
399
			List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
400
			tagPricing.add(tag);
401
		}
402
 
403
		logger.info("catalogObj {}", catalogMap);
404
		List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
405
		for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
406
			int catalogId = entry.getKey();
407
			Map<String, Object> catalogValMap = entry.getValue();
408
			Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
409
 
410
			boolean active = false;
411
			// Map<Integer, Object> itemsMap = (Map<String, Object>)
412
			// catalogValMap.get("items");
413
			List<SolrInputDocument> itemObjs = new ArrayList<>();
414
			float mop = 0;
415
 
416
			for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
417
				int itemId = itemEntry.getKey();
418
				Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
419
				List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
420
				SolrInputDocument itemObj = new SolrInputDocument();
421
 
422
				for (TagListing taglist : tags) {
423
					active = active || (Boolean) taglist.isActive();
424
					itemObj.setField("id", "itemtag-" + itemId + "-" + taglist.getTagId());
425
					itemObj.setField("color_s", itemMap.get("color"));
426
					itemObj.setField("itemId_i", itemId);
427
					itemObj.setField("tagId_i", taglist.getTagId());
428
					itemObj.setField("mrp_f", taglist.getMrp());
429
					itemObj.setField("mop_f", taglist.getMop());
430
					itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
431
					itemObj.setField("active_b", taglist.isActive());
432
					itemObj.setField("hot_deal_b", taglist.isHotDeals());
433
					mop = taglist.getMop();
434
 
435
				}
436
 
437
				itemObjs.add(itemObj);
438
			}
439
 
440
			logger.info("catalogValMap {}", catalogValMap);
441
 
442
			logger.info("rank {}", catalogValMap.get("rank"));
443
 
444
			SolrInputDocument catalogSolrObj = new SolrInputDocument();
445
 
446
			catalogSolrObj.setField("id", "catalog" + catalogId);
447
			catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
448
			catalogSolrObj.setField("title_s", catalogValMap.get("title"));
31612 tejbeer 449
			// catalogSolrObj.setField("_childDocuments_", itemObjs);
31604 tejbeer 450
			catalogSolrObj.addChildDocuments(itemObjs);
451
			catalogSolrObj.setField("child_b", itemObjs.size() > 0);
452
			catalogSolrObj.setField("catalogId_i", catalogId);
453
			catalogSolrObj.setField("imageUrl_s",
454
					catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
455
			catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
456
			catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
457
			catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
458
			catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
459
			catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
31612 tejbeer 460
			catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
31604 tejbeer 461
			catalogSolrObj.setField("w7573_i", 0);
462
			catalogSolrObj.setField("w7678_i", 0);
463
			catalogSolrObj.setField("w7720_i", 0);
464
			catalogSolrObj.setField("w8468_i", 0);
465
			catalogSolrObj.setField("w8889_i", 0);
466
			catalogSolrObj.setField("w8947_i", 0);
467
			catalogSolrObj.setField("w9213_i", 0);
468
			catalogSolrObj.setField("w9203_i", 0);
469
			catalogSolrObj.setField("mop_f", mop);
31612 tejbeer 470
			catalogSolrObj.setField("show_default_b", false);
471
 
472
			String[] brands = (String[]) catalogValMap.get("brand");
473
			for (String brand : brands) {
474
				if (brand != "FOC") {
475
					catalogSolrObj.setField("show_default_b", true);
476
 
477
				}
478
			}
31604 tejbeer 479
			Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
480
 
481
			for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
482
				int whId = avColorEntry.getKey();
483
				int color = (int) avColorEntry.getValue();
484
				catalogSolrObj.setField("w" + whId + "_i", color);
485
			}
486
			catalogSolrObj.setField("active_b", active);
487
			logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
488
 
489
			catalogSolrObjs.add(catalogSolrObj);
490
 
491
		}
492
 
493
		logger.info("catalogSolrObjs {}", catalogSolrObjs);
494
		solr.deleteByQuery("*:*");
495
		solr.add(catalogSolrObjs);
496
 
31612 tejbeer 497
		org.apache.solr.client.solrj.response.UpdateResponse updateResponse = solr.commit();
31604 tejbeer 498
		logger.info("solr {}", updateResponse.getStatus());
499
 
500
	}
501
 
502
	/*
503
	 * public void populateTagItems() throws Exception { Map<String, Map<String,
504
	 * Map<String, Integer>>> availabilityItemMap = getItemMap(); List<TagRanking>
505
	 * tagRankingList = tagRankingRepository.getAllTagRanking();
506
	 * 
507
	 * List<Integer> rankingList = new ArrayList<>(); SolrInputDocument featureMap =
508
	 * new SolrInputDocument(); for (TagRanking tagRanking : tagRankingList) {
509
	 * rankingList.add(tagRanking.getCatalogItemId());
510
	 * featureMap.addField(String.valueOf(tagRanking.getCatalogItemId()),
511
	 * tagRanking.getFeature()); }
512
	 * 
513
	 * Map<Integer, SolrInputDocument> catalogMap = new HashMap<>(); List<status>
514
	 * statuses = new ArrayList<>(); statuses.add(status.ACTIVE);
515
	 * statuses.add(status.PAUSED_BY_RISK); statuses.add(status.PARTIALLY_ACTIVE);
516
	 * List<ItemTagModel> tuples =
517
	 * tagListingRepository.getAllItemTagByStatus(statuses); SolrInputDocument
518
	 * projection = new SolrInputDocument();
519
	 * 
520
	 * projection.addField("defaultImageUrl", 1); List<String> excludeBrands =
521
	 * Arrays.asList("Live Demo", "FOC", "Dummy", "FOC HANDSET");
522
	 * 
523
	 * for (ItemTagModel result : tuples) { TagListing tag = result.getTagListing();
524
	 * com.spice.profitmandi.dao.entity.catalog.Item item = result.getItem(); if
525
	 * (excludeBrands.contains(item.getBrand())) { continue; }
526
	 * 
527
	 * if (!catalogMap.containsKey(item.getCatalogItemId())) { SolrInputDocument
528
	 * catalogObj = new SolrInputDocument(); catalogObj.addField("feature", "");
529
	 * catalogObj.addField("title", String.join(" ", Arrays.asList(item.getBrand(),
530
	 * item.getModelName(), item.getModelNumber()) .stream().filter(s -> s != null
531
	 * && !s.isEmpty()).collect(Collectors.toList()))); catalogObj.addField("brand",
532
	 * item.getBrand()); if (item.getBrand().equals("Huawei") ||
533
	 * item.getBrand().equals("Honor")) { catalogObj.addField("brand", new String[]
534
	 * { "Huawei", "Honor" }); } if (item.getBrand().equals("Mi") ||
535
	 * item.getBrand().equals("Xiaomi") || item.getBrand().equals("Redmi")) {
536
	 * catalogObj.addField("brand", new String[] { "Mi", "Xiaomi", "Redmi" }); }
537
	 * catalogObj.addField("identifier", item.getCatalogItemId());
538
	 * catalogObj.addField("items", new SolrInputDocument()); SolrInputDocument
539
	 * filterMap = new SolrInputDocument(); filterMap.addField("_id",
540
	 * item.getCatalogItemId());
541
	 * 
542
	 * try {
543
	 * 
544
	 * BrandCatalog brandCatalog = brandsRepository.selectByBrand(item.getBrand());
545
	 * catalogObj.addField("imageUrl", brandCatalog.getLogoUrl());
546
	 * System.out.println(catalogObj.get("imageUrl")); } catch (Exception e) { try {
547
	 * catalogObj.addField("imageUrl",
548
	 * "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId()
549
	 * + ".jpg"); } catch (Exception e2) { e2.printStackTrace(); } } try {
550
	 * catalogObj.addField("rank", rankingList.indexOf(item.getCatalogItemId())); }
551
	 * catch (Exception e) { // A very big number e.printStackTrace();
552
	 * catalogObj.addField("rank", 50000000); } if
553
	 * (featureMap.containsKey(String.valueOf(item.getCatalogItemId())) &&
554
	 * featureMap.get(String.valueOf(item.getCatalogItemId())) != null) {
555
	 * catalogObj.addField("feature", featureMap.get(item.getCatalogItemId()));
556
	 * 
557
	 * catalogObj.addField("categoryId",
558
	 * CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
559
	 * 
560
	 * }
561
	 * 
562
	 * if (item.getCategoryId() == 10006) { catalogObj.addField("categoryId", 3); }
563
	 * catalogObj.addField("subCategoryId", item.getCategoryId());
564
	 * catalogObj.addField("create_timestamp", tag.getCreatedTimestamp());
565
	 * catalogMap.put(item.getCatalogItemId(), catalogObj);
566
	 * catalogObj.addField("avColor", new SolrInputDocument());
567
	 * 
568
	 * // Don't include if catalog not available
569
	 * 
570
	 * catalogObj = catalogMap.get(item.getCatalogItemId()); if
571
	 * (availabilityItemMap.containsKey(String.valueOf(item.getId()))) { for
572
	 * (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
573
	 * .get(String.valueOf(item.getId())).entrySet()) { String warehouseId =
574
	 * entry.getKey(); Map<String, Integer> avMap = entry.getValue();
575
	 * 
576
	 * SolrInputDocument avColorDoc = (SolrInputDocument)
577
	 * catalogObj.getFieldValue("avColor"); //.catalogObj.get if
578
	 * (!avColorDoc.containsKey(warehouseId)) { avColorDoc.addField(warehouseId, 0);
579
	 * } int color = (int) avColorDoc.getFieldValue(warehouseId);
580
	 * 
581
	 * if (avMap.get("netAvailability") > 0) { color = 2; } else if
582
	 * (avMap.get("netAvailability") + avMap.get("netPo") > 0) { color =
583
	 * Math.max(color, 1); } else { color = Math.max(color, 0); }
584
	 * 
585
	 * avColorDoc.addField(warehouseId, 0);
586
	 * 
587
	 * }
588
	 * 
589
	 * }
590
	 * 
591
	 * SolrInputDocument itemColorDoc = (SolrInputDocument)
592
	 * catalogObj.getFieldValue("items");
593
	 * 
594
	 * if (!itemColorDoc.containsKey(item.getId())) {
595
	 * 
596
	 * itemColorDoc.addField(String.valueOf(item.getId()), new SolrInputDocument() {
597
	 * { addField("color", item.getColor().replace("f_", ""));
598
	 * addField("tagPricing", new ArrayList<TagListing>()); } }); }
599
	 * 
600
	 * SolrInputDocument itemMap = (SolrInputDocument) itemColorDoc
601
	 * .getFieldValue(String.valueOf(item.getId()));
602
	 * 
603
	 * List<TagListing> tagPricing = (List<TagListing>)
604
	 * itemMap.getFieldValue("tagPricing"); tagPricing.add(tag);
605
	 * 
606
	 * List<Map<String, Object>> catalogObjs = new ArrayList<>(); for
607
	 * (Entry<Integer, HashMap<String, Object>> entry : catalogMap.entrySet()) { int
608
	 * catalogId = entry.getKey(); Map<String, Object> catalogValMap =
609
	 * entry.getValue();
610
	 * 
611
	 * boolean active = false; Map<String, Object> itemsMap = (Map<String, Object>)
612
	 * catalogValMap.get("items"); List<Map<String, Object>> itemObjs = new
613
	 * ArrayList<>(); float mop = 0;
614
	 * 
615
	 * for (Entry<String, Object> itemEntry : itemsMap.entrySet()) { int itemId =
616
	 * Integer.parseInt(itemEntry.getKey()); Map<String, Object> itemValMap =
617
	 * (Map<String, Object>) itemEntry.getValue(); List<TagListing> tags =
618
	 * (List<TagListing>) catalogValMap.get("tagPricing");
619
	 * 
620
	 * for (TagListing taglist : tags) { active = active || (Boolean)
621
	 * taglist.isActive(); Map<String, Object> itemObj = new HashMap<>();
622
	 * itemObj.put("id", "itemtag-" + itemId + "-" + tag.getTagId());
623
	 * itemObj.put("color_s", itemMap.get("color")); itemObj.put("itemId_i",
624
	 * itemId); itemObj.put("tagId_i", tag.getTagId()); itemObj.put("mrp_f",
625
	 * tag.getMrp()); itemObj.put("mop_f", tag.getMop());
626
	 * itemObj.put("sellingPrice_f", tag.getSellingPrice()); itemObj.put("active_b",
627
	 * tag.isActive()); itemObj.put("hot_deal_b", tag.isHotDeals()); mop =
628
	 * tag.getMop(); itemObjs.add(itemObj); } } // Map<String, Object> catalogObj =
629
	 * new HashMap<String, Object>(); catalogObj.put("id", "catalog" + catalogId);
630
	 * catalogObj.put("rank_i", catalogMap.get("rank")); catalogObj.put("title_s",
631
	 * catalogMap.get("title")); catalogObj.put("_childDocuments_", itemObjs);
632
	 * catalogObj.put("child_b", itemObjs.size() > 0); catalogObj.put("catalogId_i",
633
	 * catalogId); catalogObj.put("imageUrl_s",
634
	 * catalogMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
635
	 * catalogObj.put("feature_s", catalogMap.get("feature"));
636
	 * catalogObj.put("brand_ss", catalogMap.get("brand"));
637
	 * catalogObj.put("create_s", catalogMap.get("create_timestamp"));
638
	 * catalogObj.put("categoryId_i", catalogMap.get("categoryId"));
639
	 * catalogObj.put("subCategoryId_i", catalogMap.get("subCategoryId"));
640
	 * catalogObj.put("w7573_i", 0); catalogObj.put("w7678_i", 0);
641
	 * catalogObj.put("w7720_i", 0); catalogObj.put("w8468_i", 0);
642
	 * catalogObj.put("w8889_i", 0); catalogObj.put("w8947_i", 0);
643
	 * catalogObj.put("w9213_i", 0); catalogObj.put("w9203_i", 0);
644
	 * catalogObj.put("mop_f", mop); for (Entry<Integer, Integer> avColorEntry :
645
	 * avColorMap.entrySet()) { int whId = avColorEntry.getKey(); int color = (int)
646
	 * avColorEntry.getValue(); catalogObj.put("w" + whId + "_i", color);
647
	 * 
648
	 * catalogObj.put("active_b", active); catalogObjs.add(catalogObj);
649
	 * solr.deleteByQuery("*:*"); // solr.add((catalogObjs); }
650
	 * 
651
	 * } } }
652
	 * 
653
	 * }
654
	 */
655
 
656
	public void pushData() throws Exception {
657
		this.populateTagItems();
658
	}
659
}