Subversion Repositories SmartDukaan

Rev

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