Subversion Repositories SmartDukaan

Rev

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