Subversion Repositories SmartDukaan

Rev

Rev 36971 | 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
 
33973 tejus.loha 3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
33245 ranu 5
import com.google.gson.Gson;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
33562 amit.gupta 7
import com.spice.profitmandi.common.model.ProfitMandiConstants;
33973 tejus.loha 8
import com.spice.profitmandi.dao.entity.catalog.SuperCatalogMapping;
33245 ranu 9
import com.spice.profitmandi.dao.entity.catalog.TagListing;
10
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
11
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
34021 ranu 12
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
13
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
36971 amit 14
import com.spice.profitmandi.dao.repository.catalog.*;
33245 ranu 15
import com.spice.profitmandi.dao.repository.dtr.Mongo;
16
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
17
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
33542 amit.gupta 18
import com.spice.profitmandi.dao.repository.similarModel.SimilarModelRepository;
33973 tejus.loha 19
import com.spice.profitmandi.service.catalog.SuperCatalogModel;
34021 ranu 20
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
33245 ranu 21
import com.spice.profitmandi.service.tag.ItemTagModel;
22
import in.shop2020.model.v1.catalog.status;
31604 tejbeer 23
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
25
import org.apache.solr.client.solrj.SolrClient;
26
import org.apache.solr.client.solrj.impl.HttpSolrClient;
27
import org.apache.solr.common.SolrInputDocument;
28
import org.json.JSONArray;
29
import org.json.JSONException;
30
import org.json.JSONObject;
31
import org.springframework.beans.factory.annotation.Autowired;
31613 tejbeer 32
import org.springframework.beans.factory.annotation.Value;
31604 tejbeer 33
import org.springframework.stereotype.Component;
34
 
33245 ranu 35
import java.io.BufferedReader;
36
import java.io.IOException;
37
import java.io.InputStream;
38
import java.io.InputStreamReader;
39
import java.net.HttpURLConnection;
40
import java.net.URL;
41
import java.net.URLConnection;
42
import java.time.ZoneId;
43
import java.util.*;
44
import java.util.Map.Entry;
45
import java.util.stream.Collectors;
46
import java.util.zip.GZIPInputStream;
31604 tejbeer 47
 
48
@Component
49
public class FofoSolr {
50
 
33542 amit.gupta 51
    @Autowired
52
    private Gson gson;
31604 tejbeer 53
 
33542 amit.gupta 54
    @Autowired
55
    private TagListingRepository tagListingRepository;
31604 tejbeer 56
 
33542 amit.gupta 57
    @Autowired
35357 ranu 58
    private CatalogRepository catalogRepository;
59
 
60
    @Autowired
33542 amit.gupta 61
    TagRankingRepository tagRankingRepository;
31604 tejbeer 62
 
33542 amit.gupta 63
    @Autowired
64
    private Mongo contentMongoClient;
31604 tejbeer 65
 
33542 amit.gupta 66
    @Autowired
67
    private WebListingRepository webListingRepository;
31612 tejbeer 68
 
33542 amit.gupta 69
    @Autowired
70
    private WebProductListingRepository webProductListingRepository;
31612 tejbeer 71
 
33973 tejus.loha 72
    @Autowired
73
    private SuperCatalogMappingRepository superCatalogMappingRepository;
74
 
33542 amit.gupta 75
    @Value("${new.solr.url}")
76
    private String solrUrl;
31613 tejbeer 77
 
33542 amit.gupta 78
    @Value("${reportico.url}")
79
    private String reporticoUrl;
33486 amit.gupta 80
 
33542 amit.gupta 81
    private static final Logger logger = LogManager.getLogger(FofoSolr.class);
31604 tejbeer 82
 
35797 amit 83
    private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10007, 10010, 14202, 14203);
31604 tejbeer 84
 
36971 amit 85
    @Autowired
86
    ModelFlagshipRepository modelFlagshipRepository;
87
 
33542 amit.gupta 88
    private static String getUrlContent(String urlString) {
89
        BufferedReader reader = null;
90
        try {
91
            URL url = new URL(urlString);
92
            URLConnection conn = url.openConnection();
93
            conn.setConnectTimeout(5000);
94
            conn.setReadTimeout(5000);
95
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
96
            return reader.lines().collect(Collectors.joining(System.lineSeparator()));
97
        } catch (IOException e) {
98
            e.printStackTrace();
99
        } finally {
100
            if (reader != null) {
101
                try {
102
                    reader.close();
103
                } catch (IOException e) {
104
                    e.printStackTrace();
105
                }
106
            }
107
        }
108
        return null;
109
    }
31604 tejbeer 110
 
33542 amit.gupta 111
    public JSONArray getAvailability() throws IOException, JSONException {
112
        String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
113
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
114
        connection.setRequestProperty("Accept-Encoding", "gzip");
115
        BufferedReader reader = null;
31604 tejbeer 116
 
33542 amit.gupta 117
        try {
118
            InputStream inputStream = connection.getInputStream();
31604 tejbeer 119
 
33542 amit.gupta 120
            if ("gzip".equals(connection.getContentEncoding())) {
121
                inputStream = new GZIPInputStream(inputStream);
122
            }
31604 tejbeer 123
 
33542 amit.gupta 124
            reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
125
            StringBuilder responseBuilder = new StringBuilder();
126
            String line;
31604 tejbeer 127
 
33542 amit.gupta 128
            while ((line = reader.readLine()) != null) {
129
                responseBuilder.append(line);
130
            }
31604 tejbeer 131
 
33542 amit.gupta 132
            JSONObject responseJson = new JSONObject(responseBuilder.toString());
133
            return responseJson.getJSONArray("data");
134
        } finally {
135
            if (reader != null) {
136
                try {
137
                    reader.close();
138
                } catch (IOException e) {
139
                    // Ignore
140
                }
141
            }
142
        }
143
    }
31604 tejbeer 144
 
33542 amit.gupta 145
    public JSONArray getPendingPO() throws IOException, JSONException {
146
        String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
147
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
148
        connection.setRequestProperty("Accept-Encoding", "gzip");
149
        BufferedReader reader = null;
31604 tejbeer 150
 
33542 amit.gupta 151
        try {
152
            InputStream inputStream = connection.getInputStream();
31604 tejbeer 153
 
33542 amit.gupta 154
            if ("gzip".equals(connection.getContentEncoding())) {
155
                inputStream = new GZIPInputStream(inputStream);
156
            }
31604 tejbeer 157
 
33542 amit.gupta 158
            reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
159
            StringBuilder responseBuilder = new StringBuilder();
160
            String line;
31604 tejbeer 161
 
33542 amit.gupta 162
            while ((line = reader.readLine()) != null) {
163
                responseBuilder.append(line);
164
            }
31604 tejbeer 165
 
33542 amit.gupta 166
            JSONObject responseJson = new JSONObject(responseBuilder.toString());
167
            return responseJson.getJSONArray("data");
168
        } finally {
169
            if (reader != null) {
170
                try {
171
                    reader.close();
172
                } catch (IOException e) {
173
                    // Ignore
174
                }
175
            }
176
        }
177
    }
31604 tejbeer 178
 
34021 ranu 179
    @Autowired
180
    SaholicInventoryService saholicInventoryService;
181
 
33542 amit.gupta 182
    public Map<String, Map<String, Map<String, Integer>>> getItemMap() throws Exception {
34021 ranu 183
 
184
//        JSONArray availabilityJSONArray = this.getAvailability();
35343 ranu 185
        List<SaholicCIS> saholicCISList = saholicInventoryService.getSaholicStockListWithoutCatalogMovingStatus();
34021 ranu 186
 
187
//        JSONArray pendingPOJSONArray = this.getPendingPO();
188
        List<SaholicPOItem> saholicPOItemList = saholicInventoryService.getSaholicPOItemList();
189
 
33542 amit.gupta 190
        Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = new HashMap<>();
34021 ranu 191
        for (SaholicCIS rawAvailability : saholicCISList) {
31604 tejbeer 192
 
34021 ranu 193
            String itemId = String.valueOf(rawAvailability.getItemId());
194
            String warehouseId = String.valueOf(rawAvailability.getWarehouseId());
195
 
196
            if (!availabilityItemMap.containsKey(itemId)) {
197
                availabilityItemMap.put(itemId, new HashMap<>());
33542 amit.gupta 198
            }
34021 ranu 199
            if (!availabilityItemMap.get(itemId).containsKey(warehouseId)) {
200
                availabilityItemMap.get(itemId).put(warehouseId, new HashMap<String, Integer>());
201
                availabilityItemMap.get(itemId).get(warehouseId).put("netAvailability", 0);
202
                availabilityItemMap.get(itemId).get(warehouseId).put("netPo", 0);
33542 amit.gupta 203
            }
34021 ranu 204
            int netAvailability = availabilityItemMap.get(itemId).get(warehouseId).get("netAvailability") + rawAvailability.getNetavailability();
205
            availabilityItemMap.get(itemId).get(warehouseId).put("netAvailability", netAvailability);
33542 amit.gupta 206
        }
31604 tejbeer 207
 
34021 ranu 208
        for (SaholicPOItem rawPendingPo : saholicPOItemList) {
209
            String itemId = String.valueOf(rawPendingPo.getItemId());
210
            String warehouseId = String.valueOf(rawPendingPo.getWarehouseId());
33542 amit.gupta 211
            if (!availabilityItemMap.containsKey(itemId)) {
212
                availabilityItemMap.put(itemId, new HashMap<String, Map<String, Integer>>());
213
            }
214
            if (!availabilityItemMap.get(itemId).containsKey(warehouseId)) {
215
                availabilityItemMap.get(itemId).put(warehouseId, new HashMap<String, Integer>() {
216
                    {
217
                        put("netAvailability", 0);
218
                        put("netPo", 0);
219
                    }
220
                });
221
            }
222
            availabilityItemMap.get(itemId).get(warehouseId).put("netPo",
34021 ranu 223
                    availabilityItemMap.get(itemId).get(warehouseId).get("netPo") + rawPendingPo.getUnfulfilledQty());
31604 tejbeer 224
 
33542 amit.gupta 225
        }
226
        return availabilityItemMap;
31604 tejbeer 227
 
33542 amit.gupta 228
    }
31604 tejbeer 229
 
33245 ranu 230
    public Map<Integer, List<String>> getLabels() throws ProfitMandiBusinessException {
33542 amit.gupta 231
        List<String> labels = Arrays.asList("partner-best-sellers", "partner-price-drop", "new-launches",
232
                "upgrade-offer", "special-support");
31612 tejbeer 233
 
33542 amit.gupta 234
        Map<Integer, String> webListing = webListingRepository.selectByUrls(labels).stream()
235
                .collect(Collectors.toMap(x -> x.getId(), x -> x.getUrl()));
31612 tejbeer 236
 
33542 amit.gupta 237
        Map<Integer, List<WebProductListing>> webProductListingMap = webProductListingRepository
238
                .selectAllByWebListingIds(new ArrayList<>(webListing.keySet())).stream()
239
                .collect(Collectors.groupingBy(x -> x.getWebListingId()));
31612 tejbeer 240
 
33542 amit.gupta 241
        Map<Integer, List<String>> catalogLabelMap = new HashMap<>();
242
        for (Entry<Integer, List<WebProductListing>> webProductListingEntry : webProductListingMap.entrySet()) {
31612 tejbeer 243
 
33542 amit.gupta 244
            for (WebProductListing webProduct : webProductListingEntry.getValue()) {
31612 tejbeer 245
 
33542 amit.gupta 246
                if (!catalogLabelMap.containsKey(webProduct.getEntityId())) {
31612 tejbeer 247
 
33542 amit.gupta 248
                    catalogLabelMap.put(webProduct.getEntityId(), new ArrayList<>());
31612 tejbeer 249
 
33542 amit.gupta 250
                }
31612 tejbeer 251
 
33542 amit.gupta 252
                List<String> itemLabels = catalogLabelMap.get(webProduct.getEntityId());
253
                itemLabels.add(webListing.get(webProduct.getWebListingId()));
254
                catalogLabelMap.put(webProduct.getEntityId(), itemLabels);
31612 tejbeer 255
 
33542 amit.gupta 256
            }
31612 tejbeer 257
 
33542 amit.gupta 258
        }
31612 tejbeer 259
 
33542 amit.gupta 260
        return catalogLabelMap;
261
    }
31612 tejbeer 262
 
33542 amit.gupta 263
    @Autowired
264
    SimilarModelRepository similarModelRepository;
31604 tejbeer 265
 
33542 amit.gupta 266
    public void populateTagItems() throws Exception {
267
        Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
268
        List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
269
        List<Integer> rankingList = new ArrayList<>();
270
        Map<Integer, String> featureMap = new HashMap<>();
271
        for (TagRanking tagRanking : tagRankingList) {
272
            rankingList.add(tagRanking.getCatalogItemId());
273
            featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
274
        }
275
        //Get Similar Models
33570 amit.gupta 276
        /*List<SimilarModel> similarModels = similarModelRepository.selectAll();
31612 tejbeer 277
 
33570 amit.gupta 278
        Map<Integer, List<Integer>> similarModelsMap = similarModels.stream().collect(Collectors.groupingBy(SimilarModel::getCatalogId, Collectors.mapping(x -> x.getSimilarCatalogId(), Collectors.toList())));*/
31612 tejbeer 279
 
33542 amit.gupta 280
        Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
31612 tejbeer 281
 
33542 amit.gupta 282
        List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
31612 tejbeer 283
 
33542 amit.gupta 284
        Map<Integer, List<String>> catalogLabelMap = this.getLabels();
31604 tejbeer 285
 
33973 tejus.loha 286
        //logger.info("catalogLabelMap {}", catalogLabelMap);
31604 tejbeer 287
 
35364 ranu 288
        List<ItemTagModel> itemTagModels = tagListingRepository.getAllItemTagByStatus(statuses);
31604 tejbeer 289
 
35364 ranu 290
        logger.info("itemTagModels {}" , itemTagModels.size());
35358 ranu 291
 
35365 ranu 292
        List<Integer> eolWithOutStock = catalogRepository.findAllWithEOLWithOutStock();
35426 ranu 293
        List<Integer> eolWithBadQty = catalogRepository.findAllWithNoGoodStock();
35357 ranu 294
 
35365 ranu 295
        Set<Integer> eolSet = new HashSet<>(eolWithOutStock);
35426 ranu 296
        eolSet.addAll(eolWithBadQty);
35358 ranu 297
 
36971 amit 298
        // Flagship models active as of today (catalog.model_flagship start_date/end_date)
299
        Set<Integer> flagshipSet = modelFlagshipRepository.selectActiveFlagshipCatalogIds();
35426 ranu 300
 
36971 amit 301
        // Flagship is surfaced as a label (prepended so it shows first, ahead of all other flags)
302
        for (Integer flagshipCatalogId : flagshipSet) {
303
            catalogLabelMap.computeIfAbsent(flagshipCatalogId, k -> new ArrayList<>()).add(0, "flagship");
304
        }
305
 
306
 
35365 ranu 307
        logger.info("eolSetIds.size {}" , eolSet.size());
35357 ranu 308
 
33542 amit.gupta 309
        Map<String, Object> projection = new HashMap<>();
310
        projection.put("defaultImageUrl", 1);
31604 tejbeer 311
 
33542 amit.gupta 312
        List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET");
31604 tejbeer 313
 
33562 amit.gupta 314
        Map<Float, List<Integer>> priceModelMap = new TreeMap<>();
315
        for (ItemTagModel itemTagModel : itemTagModels) {
316
            TagListing tagListing = itemTagModel.getTagListing();
317
            com.spice.profitmandi.dao.entity.catalog.Item item = itemTagModel.getItem();
33542 amit.gupta 318
            if (excludeBrands.contains(item.getBrand())) {
319
                continue;
320
            }
31604 tejbeer 321
 
33542 amit.gupta 322
            if (!catalogMap.containsKey(item.getCatalogItemId())) {
33571 amit.gupta 323
                if (!priceModelMap.containsKey(tagListing.getMop()) && item.getCategoryId() == 10006) {
33572 amit.gupta 324
                    priceModelMap.put(tagListing.getMop(), new ArrayList<>());
33562 amit.gupta 325
                }
33570 amit.gupta 326
                if (item.getCategoryId() == 10006) {
33571 amit.gupta 327
                    List<Integer> priceModels = priceModelMap.get(tagListing.getMop());
33565 amit.gupta 328
                    priceModels.add(item.getCatalogItemId());
329
                }
33562 amit.gupta 330
 
33542 amit.gupta 331
                Map<String, Object> catalogObj = new HashMap<>();
33570 amit.gupta 332
                catalogObj.put("stockColor", 0);
33542 amit.gupta 333
                catalogObj.put("feature", "");
334
                catalogObj.put("hsnCode", item.getHsnCode());
335
                catalogObj.put("title",
336
                        String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
337
                                .stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
338
                catalogObj.put("brand", new String[]{item.getBrand()});
339
                if (item.getBrand().equals("Huawei") || item.getBrand().equals("Honor")) {
340
                    catalogObj.put("brand", new String[]{"Huawei", "Honor"});
341
                }
342
                if (item.getBrand().equals("Mi") || item.getBrand().equals("Xiaomi")
343
                        || item.getBrand().equals("Redmi")) {
344
                    catalogObj.put("brand", new String[]{"Mi", "Xiaomi", "Redmi"});
345
                }
346
                catalogObj.put("identifier", item.getCatalogItemId());
347
                catalogObj.put("items", new HashMap<Integer, Map<String, Object>>());
348
                Map<String, Object> filterMap = new HashMap<>();
349
                filterMap.put("_id", item.getCatalogItemId());
350
                // Don't include if catalog not available
351
                try {
352
                    String imageUrl = contentMongoClient.getEntityById(item.getCatalogItemId()).getDefaultImageUrl();
31624 tejbeer 353
 
33542 amit.gupta 354
                    if (imageUrl != null) {
355
                        catalogObj.put("imageUrl", imageUrl);
356
                    } else {
357
                        catalogObj.put("imageUrl",
358
                                "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
359
                    }
360
                } catch (Exception e) {
361
                    try {
362
                        catalogObj.put("imageUrl",
363
                                "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
364
                    } catch (Exception e2) {
365
                        e2.printStackTrace();
366
                    }
367
                }
368
                try {
369
                    catalogObj.put("rank", rankingList.indexOf(item.getCatalogItemId()));
370
                } catch (Exception e) {
371
                    // A very big number
372
                    e.printStackTrace();
373
                    catalogObj.put("rank", 50000000);
374
                }
375
                if (featureMap.containsKey(item.getCatalogItemId())
376
                        && featureMap.get(item.getCatalogItemId()) != null) {
377
                    catalogObj.put("feature", featureMap.get(item.getCatalogItemId()));
31612 tejbeer 378
 
33542 amit.gupta 379
                }
31612 tejbeer 380
 
33542 amit.gupta 381
                catalogObj.put("categoryId", CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
31612 tejbeer 382
 
37114 amit 383
                if (item.getCategoryId() == 10006 || item.getCategoryId() == 10007) {
33542 amit.gupta 384
                    catalogObj.put("categoryId", 3);
385
                }
386
                catalogObj.put("subCategoryId", item.getCategoryId());
387
                catalogObj.put("create_timestamp",
33562 amit.gupta 388
                        tagListing.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
31604 tejbeer 389
 
33542 amit.gupta 390
                if (catalogLabelMap.containsKey(item.getCatalogItemId())
391
                        && catalogLabelMap.get(item.getCatalogItemId()) != null) {
392
                    catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
31604 tejbeer 393
 
33542 amit.gupta 394
                }
395
                catalogMap.put(item.getCatalogItemId(), catalogObj);
396
                catalogObj.put("avColor", new HashMap<>());
31604 tejbeer 397
 
33542 amit.gupta 398
            }
31604 tejbeer 399
 
33542 amit.gupta 400
            Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
401
            Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
31604 tejbeer 402
 
33542 amit.gupta 403
            if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
33570 amit.gupta 404
                int itemStockColor = 0;
33542 amit.gupta 405
                for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
406
                        .get(String.valueOf(item.getId())).entrySet()) {
407
                    String warehouseId = entry.getKey();
408
                    Map<String, Integer> avMap = entry.getValue();
409
                    if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
410
                        avColorMap.put(Integer.parseInt(warehouseId), 0);
411
                    }
412
                    int color = avColorMap.get(Integer.parseInt(warehouseId));
31604 tejbeer 413
 
33542 amit.gupta 414
                    if (avMap.get("netAvailability") > 0) {
415
                        color = 2;
33562 amit.gupta 416
                    } else if (avMap.get("netPo") > 0) {
33542 amit.gupta 417
                        color = Math.max(color, 1);
418
                    } else {
419
                        color = Math.max(color, 0);
420
                    }
421
                    avColorMap.put(Integer.parseInt(warehouseId), color);
31604 tejbeer 422
 
33542 amit.gupta 423
                    catalogObj.put("avColor", avColorMap);
33570 amit.gupta 424
                    if (color > itemStockColor) {
425
                        itemStockColor = color;
426
                    }
33542 amit.gupta 427
                }
33570 amit.gupta 428
                if (itemStockColor > 0 && itemStockColor > (Integer) catalogObj.get("stockColor")) {
429
                    catalogObj.put("stockColor", itemStockColor);
430
                }
33542 amit.gupta 431
            }
31604 tejbeer 432
 
33542 amit.gupta 433
            Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
31604 tejbeer 434
 
33542 amit.gupta 435
            if (!itemColorMap.containsKey(item.getId())) {
436
                itemColorMap.put(item.getId(), new HashMap<String, Object>() {
437
                    {
438
                        put("color", item.getColor().replace("f_", ""));
439
                        put("tagPricing", new ArrayList<TagListing>());
440
                    }
441
                });
442
            }
443
            Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
444
            List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
33562 amit.gupta 445
            tagPricing.add(tagListing);
33542 amit.gupta 446
        }
33562 amit.gupta 447
        //logger.info("catalogObj {}", catalogMap);
31604 tejbeer 448
 
33973 tejus.loha 449
        List<SuperCatalogModel> superCatalogMappingList = superCatalogMappingRepository.selectJoinedData();
450
        List<SuperCatalogMapping> superCatalogs = superCatalogMappingRepository.selectAll();
33542 amit.gupta 451
        List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
452
        for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
453
            int catalogId = entry.getKey();
34229 vikas.jang 454
            Optional<SuperCatalogModel> superCatalogMapping = findMappingByCatalogId(superCatalogMappingList, catalogId, itemTagModels);
33542 amit.gupta 455
            Map<String, Object> catalogValMap = entry.getValue();
456
            Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
31604 tejbeer 457
 
33542 amit.gupta 458
            boolean active = false;
459
            // Map<Integer, Object> itemsMap = (Map<String, Object>)
460
            // catalogValMap.get("items");
461
            List<SolrInputDocument> itemObjs = new ArrayList<>();
462
            float mop = 0;
33574 amit.gupta 463
            float dp = 0;
31604 tejbeer 464
 
33542 amit.gupta 465
            for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
466
                int itemId = itemEntry.getKey();
467
                Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
468
                List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
469
                SolrInputDocument itemObj = new SolrInputDocument();
31604 tejbeer 470
 
34136 amit.gupta 471
                for (TagListing tagListing : tags) {
472
                    active = active || tagListing.isActive();
473
                    itemObj.setField("id", "itemtag-" + itemId + "-" + tagListing.getTagId());
33542 amit.gupta 474
                    itemObj.setField("color_s", itemMap.get("color"));
475
                    itemObj.setField("itemId_i", itemId);
34136 amit.gupta 476
                    itemObj.setField("tagId_i", tagListing.getTagId());
477
                    itemObj.setField("mrp_f", tagListing.getMrp());
478
                    itemObj.setField("mop_f", tagListing.getMop());
479
                    itemObj.setField("sellingPrice_f", tagListing.getSellingPrice());
480
                    itemObj.setField("active_b", tagListing.isActive());
481
                    itemObj.setField("hot_deal_b", tagListing.isHotDeals());
482
                    mop = tagListing.getMop();
483
                    dp = tagListing.getSellingPrice();
33542 amit.gupta 484
                }
485
                itemObjs.add(itemObj);
486
            }
31604 tejbeer 487
 
33542 amit.gupta 488
            SolrInputDocument catalogSolrObj = new SolrInputDocument();
489
            catalogSolrObj.setField("id", "catalog" + catalogId);
490
            catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
491
            catalogSolrObj.setField("title_s", catalogValMap.get("title"));
492
            catalogSolrObj.addChildDocuments(itemObjs);
493
            catalogSolrObj.setField("child_b", itemObjs.size() > 0);
494
            catalogSolrObj.setField("catalogId_i", catalogId);
33980 ranu 495
            logger.info("superCatalogMapping1- {}", superCatalogMapping);
33973 tejus.loha 496
            if (superCatalogMapping.isPresent()) {
497
                int superCatalogId = superCatalogMapping.get().getSuperCatalogId();
34229 vikas.jang 498
                String superCatalogMappingVariants = findMappingVariantsByCatalogId(superCatalogs, superCatalogId, itemTagModels);
33973 tejus.loha 499
                catalogSolrObj.setField("superCatalog_i", superCatalogId);
500
                catalogSolrObj.setField("superCatalog_s", superCatalogMapping.get().getSuperCatalogName());
501
                catalogSolrObj.setField("superCatalogVariants_s", superCatalogMappingVariants);
502
            } else {
503
                catalogSolrObj.setField("superCatalog_i", 0);
34023 vikas.jang 504
                catalogSolrObj.setField("superCatalog_s", catalogValMap.get("title"));
33973 tejus.loha 505
                catalogSolrObj.setField("superCatalogVariants_s", "[]");
506
            }
33542 amit.gupta 507
            catalogSolrObj.setField("imageUrl_s",
508
                    catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
509
            catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
510
            catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
511
            catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
512
            catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
513
            catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
514
            catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
515
            catalogSolrObj.setField("mop_f", mop);
33574 amit.gupta 516
            catalogSolrObj.setField("dp_f", dp);
33542 amit.gupta 517
            catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
518
            catalogSolrObj.setField("show_default_b", true);
31710 tejbeer 519
 
33542 amit.gupta 520
            String[] brands = (String[]) catalogValMap.get("brand");
521
            for (String brand : brands) {
522
                if (brand.equals("FOC")) {
523
                    catalogSolrObj.setField("show_default_b", false);
524
                }
31604 tejbeer 525
 
33542 amit.gupta 526
                if (brand.equals("Live Demo")) {
527
                    catalogSolrObj.setField("show_default_b", false);
528
                }
529
            }
530
            Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
33499 amit.gupta 531
 
33570 amit.gupta 532
            for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
533
                catalogSolrObj.setField("w" + warehouseId + "_i", 0);
534
            }
33542 amit.gupta 535
            for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
536
                int whId = avColorEntry.getKey();
33562 amit.gupta 537
                int color = avColorEntry.getValue();
33542 amit.gupta 538
                catalogSolrObj.setField("w" + whId + "_i", color);
539
            }
33570 amit.gupta 540
 
541
            List<Integer> similalarModels = null;
542
            if ((Integer) catalogValMap.get("categoryId") == 3) {
33571 amit.gupta 543
                float starPrice = mop - 500f;
544
                float endPrice = mop + 1000f;
33570 amit.gupta 545
                similalarModels = new ArrayList<>();
546
                for (Entry<Float, List<Integer>> floatListEntry : priceModelMap.entrySet()) {
547
                    float modelPrice = floatListEntry.getKey();
548
                    if (modelPrice >= starPrice && modelPrice <= endPrice) {
549
                        List<Integer> instock = floatListEntry.getValue().stream().filter(x->catalogMap.get(x).get("stockColor") != null && (Integer) (catalogMap.get(x).get("stockColor"))>0).collect(Collectors.toList());
34229 vikas.jang 550
                        //logger.info("Entry before - {}, after - {}", floatListEntry.getValue().size(), instock.size());
33570 amit.gupta 551
                        similalarModels.addAll(instock);
552
                    }
553
                    if (modelPrice > endPrice) break;
554
                }
555
                similalarModels.remove(Integer.valueOf(catalogId));
556
            }
34049 vikas.jang 557
            catalogSolrObj.setField("similarModels_ii", similalarModels == null ? Collections.EMPTY_LIST : similalarModels);
33570 amit.gupta 558
 
559
 
33542 amit.gupta 560
            catalogSolrObj.setField("active_b", active);
35365 ranu 561
            if(eolSet.contains(catalogId)){
35366 ranu 562
                catalogSolrObj.setField("eol_no_stock_b", true);
35365 ranu 563
            }else {
35366 ranu 564
                catalogSolrObj.setField("eol_no_stock_b", false);
35365 ranu 565
            }
36971 amit 566
            catalogSolrObj.setField("flagship_b", flagshipSet.contains(catalogId));
33542 amit.gupta 567
            catalogSolrObjs.add(catalogSolrObj);
568
        }
31604 tejbeer 569
 
33542 amit.gupta 570
        String solrPath = "http://" + solrUrl + ":8984/solr/demo";
571
        SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
31604 tejbeer 572
 
33542 amit.gupta 573
        solr.deleteByQuery("*:*");
574
        solr.add(catalogSolrObjs);
575
 
576
        org.apache.solr.client.solrj.response.UpdateResponse updateResponse = solr.commit();
577
        logger.info("solr {}", updateResponse.getStatus());
578
 
579
    }
580
 
581
    public void pushData() throws Exception {
582
        this.populateTagItems();
583
    }
33973 tejus.loha 584
 
35547 amit 585
    /**
586
     * Updates a single catalog in Solr based on catalogId.
587
     * Used for real-time updates when TagListing changes.
588
     *
589
     * @param catalogId The catalog ID to update
590
     */
591
    public void updateSingleCatalog(int catalogId) throws Exception {
592
        logger.info("Updating single catalog in Solr: catalogId={}", catalogId);
593
 
594
        List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
36971 amit 595
        boolean flagship = !modelFlagshipRepository
596
                .selectActiveFlagshipCatalogIds(Collections.singletonList(catalogId)).isEmpty();
35547 amit 597
 
598
        // Get all TagListings for this catalog
599
        List<ItemTagModel> itemTagModels = tagListingRepository.getItemTagByCatalogIdAndStatus(catalogId, statuses);
600
 
601
        if (itemTagModels.isEmpty()) {
602
            logger.warn("No active TagListings found for catalogId={}, removing from Solr", catalogId);
603
            String solrPath = "http://" + solrUrl + ":8984/solr/demo";
604
            SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
605
            solr.deleteById("catalog" + catalogId);
606
            solr.commit();
607
            return;
608
        }
609
 
610
        // Get availability for items in this catalog
611
        Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
612
 
613
        // Get ranking info
614
        List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
615
        List<Integer> rankingList = new ArrayList<>();
616
        Map<Integer, String> featureMap = new HashMap<>();
617
        for (TagRanking tagRanking : tagRankingList) {
618
            rankingList.add(tagRanking.getCatalogItemId());
619
            featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
620
        }
621
 
622
        // Get labels
623
        Map<Integer, List<String>> catalogLabelMap = this.getLabels();
624
 
36971 amit 625
        // Flagship is surfaced as a label (prepended so it shows first, ahead of all other flags)
626
        if (flagship) {
627
            catalogLabelMap.computeIfAbsent(catalogId, k -> new ArrayList<>()).add(0, "flagship");
628
        }
629
 
35547 amit 630
        // Get EOL info
631
        List<Integer> eolWithOutStock = catalogRepository.findAllWithEOLWithOutStock();
632
        List<Integer> eolWithBadQty = catalogRepository.findAllWithNoGoodStock();
633
        Set<Integer> eolSet = new HashSet<>(eolWithOutStock);
634
        eolSet.addAll(eolWithBadQty);
635
 
636
        // Build catalog document
637
        com.spice.profitmandi.dao.entity.catalog.Item firstItem = itemTagModels.get(0).getItem();
638
        TagListing firstTagListing = itemTagModels.get(0).getTagListing();
639
 
640
        Map<Integer, Integer> avColorMap = new HashMap<>();
641
        List<SolrInputDocument> itemObjs = new ArrayList<>();
642
        boolean active = false;
643
        float mop = 0;
644
        float dp = 0;
645
        int stockColor = 0;
646
 
647
        for (ItemTagModel itemTagModel : itemTagModels) {
648
            TagListing tagListing = itemTagModel.getTagListing();
649
            com.spice.profitmandi.dao.entity.catalog.Item item = itemTagModel.getItem();
650
 
651
            active = active || tagListing.isActive();
652
 
653
            // Build item document
654
            SolrInputDocument itemObj = new SolrInputDocument();
655
            itemObj.setField("id", "itemtag-" + item.getId() + "-" + tagListing.getTagId());
656
            itemObj.setField("color_s", item.getColor().replace("f_", ""));
657
            itemObj.setField("itemId_i", item.getId());
658
            itemObj.setField("tagId_i", tagListing.getTagId());
659
            itemObj.setField("mrp_f", tagListing.getMrp());
660
            itemObj.setField("mop_f", tagListing.getMop());
661
            itemObj.setField("sellingPrice_f", tagListing.getSellingPrice());
662
            itemObj.setField("active_b", tagListing.isActive());
663
            itemObj.setField("hot_deal_b", tagListing.isHotDeals());
664
            mop = tagListing.getMop();
665
            dp = tagListing.getSellingPrice();
666
            itemObjs.add(itemObj);
667
 
668
            // Calculate availability color
669
            if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
670
                int itemStockColor = 0;
671
                for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
672
                        .get(String.valueOf(item.getId())).entrySet()) {
673
                    String warehouseId = entry.getKey();
674
                    Map<String, Integer> avMap = entry.getValue();
675
                    if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
676
                        avColorMap.put(Integer.parseInt(warehouseId), 0);
677
                    }
678
                    int color = avColorMap.get(Integer.parseInt(warehouseId));
679
 
680
                    if (avMap.get("netAvailability") > 0) {
681
                        color = 2;
682
                    } else if (avMap.get("netPo") > 0) {
683
                        color = Math.max(color, 1);
684
                    } else {
685
                        color = Math.max(color, 0);
686
                    }
687
                    avColorMap.put(Integer.parseInt(warehouseId), color);
688
 
689
                    if (color > itemStockColor) {
690
                        itemStockColor = color;
691
                    }
692
                }
693
                if (itemStockColor > stockColor) {
694
                    stockColor = itemStockColor;
695
                }
696
            }
697
        }
698
 
699
        // Build catalog Solr document
700
        SolrInputDocument catalogSolrObj = new SolrInputDocument();
701
        catalogSolrObj.setField("id", "catalog" + catalogId);
702
        catalogSolrObj.setField("rank_i", rankingList.indexOf(catalogId));
703
        catalogSolrObj.setField("title_s", String.join(" ", Arrays.asList(
704
                firstItem.getBrand(), firstItem.getModelName(), firstItem.getModelNumber())
705
                .stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
706
        catalogSolrObj.addChildDocuments(itemObjs);
707
        catalogSolrObj.setField("child_b", itemObjs.size() > 0);
708
        catalogSolrObj.setField("catalogId_i", catalogId);
709
 
710
        // Super catalog mapping
711
        List<SuperCatalogModel> superCatalogMappingList = superCatalogMappingRepository.selectJoinedData();
712
        List<SuperCatalogMapping> superCatalogs = superCatalogMappingRepository.selectAll();
713
        Optional<SuperCatalogModel> superCatalogMapping = findMappingByCatalogId(superCatalogMappingList, catalogId, itemTagModels);
714
 
715
        if (superCatalogMapping.isPresent()) {
716
            int superCatalogId = superCatalogMapping.get().getSuperCatalogId();
717
            String superCatalogMappingVariants = findMappingVariantsByCatalogId(superCatalogs, superCatalogId, itemTagModels);
718
            catalogSolrObj.setField("superCatalog_i", superCatalogId);
719
            catalogSolrObj.setField("superCatalog_s", superCatalogMapping.get().getSuperCatalogName());
720
            catalogSolrObj.setField("superCatalogVariants_s", superCatalogMappingVariants);
721
        } else {
722
            catalogSolrObj.setField("superCatalog_i", 0);
723
            catalogSolrObj.setField("superCatalog_s", catalogSolrObj.getFieldValue("title_s"));
724
            catalogSolrObj.setField("superCatalogVariants_s", "[]");
725
        }
726
 
727
        // Image URL
728
        try {
729
            String imageUrl = contentMongoClient.getEntityById(catalogId).getDefaultImageUrl();
730
            if (imageUrl != null) {
731
                catalogSolrObj.setField("imageUrl_s", imageUrl.replace("saholic", "smartdukaan"));
732
            } else {
733
                catalogSolrObj.setField("imageUrl_s",
734
                        "https://images.smartdukaan.com/uploads/campaigns/" + catalogId + ".jpg");
735
            }
736
        } catch (Exception e) {
737
            catalogSolrObj.setField("imageUrl_s",
738
                    "https://images.smartdukaan.com/uploads/campaigns/" + catalogId + ".jpg");
739
        }
740
 
741
        // Feature
742
        if (featureMap.containsKey(catalogId) && featureMap.get(catalogId) != null) {
743
            catalogSolrObj.setField("feature_s", featureMap.get(catalogId));
744
        } else {
745
            catalogSolrObj.setField("feature_s", "");
746
        }
747
 
748
        // Brand
749
        String[] brands = new String[]{firstItem.getBrand()};
750
        if (firstItem.getBrand().equals("Huawei") || firstItem.getBrand().equals("Honor")) {
751
            brands = new String[]{"Huawei", "Honor"};
752
        }
753
        if (firstItem.getBrand().equals("Mi") || firstItem.getBrand().equals("Xiaomi")
754
                || firstItem.getBrand().equals("Redmi")) {
755
            brands = new String[]{"Mi", "Xiaomi", "Redmi"};
756
        }
757
        catalogSolrObj.setField("brand_ss", brands);
758
 
759
        // Category
760
        catalogSolrObj.setField("categoryId_i", CATEGORY_MASTER.contains(firstItem.getCategoryId())
37114 amit 761
                ? ((firstItem.getCategoryId() == 10006 || firstItem.getCategoryId() == 10007) ? 3 : firstItem.getCategoryId()) : 6);
35547 amit 762
        catalogSolrObj.setField("subCategoryId_i", firstItem.getCategoryId());
763
 
764
        // Timestamps and labels
765
        catalogSolrObj.setField("create_s", firstTagListing.getCreatedTimestamp()
766
                .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
767
        if (catalogLabelMap.containsKey(catalogId) && catalogLabelMap.get(catalogId) != null) {
768
            catalogSolrObj.setField("label_ss", catalogLabelMap.get(catalogId));
769
        }
770
 
771
        catalogSolrObj.setField("mop_f", mop);
772
        catalogSolrObj.setField("dp_f", dp);
773
        catalogSolrObj.setField("hsncode_s", firstItem.getHsnCode());
774
        catalogSolrObj.setField("show_default_b", true);
775
 
776
        for (String brand : brands) {
777
            if (brand.equals("FOC") || brand.equals("Live Demo")) {
778
                catalogSolrObj.setField("show_default_b", false);
779
            }
780
        }
781
 
782
        // Warehouse availability
783
        for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
784
            catalogSolrObj.setField("w" + warehouseId + "_i", 0);
785
        }
786
        for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
787
            int whId = avColorEntry.getKey();
788
            int color = avColorEntry.getValue();
789
            catalogSolrObj.setField("w" + whId + "_i", color);
790
        }
791
 
792
        // Similar models - simplified for single update
793
        catalogSolrObj.setField("similarModels_ii", Collections.EMPTY_LIST);
794
 
795
        catalogSolrObj.setField("active_b", active);
796
        catalogSolrObj.setField("eol_no_stock_b", eolSet.contains(catalogId));
36971 amit 797
        catalogSolrObj.setField("flagship_b", flagship);
35547 amit 798
 
799
        // Push to Solr
800
        String solrPath = "http://" + solrUrl + ":8984/solr/demo";
801
        SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
802
 
803
        // Delete existing and add updated document
804
        solr.deleteById("catalog" + catalogId);
805
        solr.add(catalogSolrObj);
806
        solr.commit();
807
 
808
        logger.info("Successfully updated catalogId={} in Solr", catalogId);
809
    }
810
 
34229 vikas.jang 811
    public Optional<SuperCatalogModel> findMappingByCatalogId(List<SuperCatalogModel> superCatalogMappingList, int id, List<ItemTagModel> itemTagModels) {
812
        if (itemTagModels.stream().anyMatch(tag -> tag.getItem().getCatalogItemId() == id && tag.getTagListing().isActive())) {
813
            return superCatalogMappingList.stream().filter(mapping -> mapping.getCatalogId() == id).findFirst();
814
        }
815
        return Optional.empty();
33973 tejus.loha 816
    }
817
 
34229 vikas.jang 818
    public String findMappingVariantsByCatalogId(List<SuperCatalogMapping> superCatalogMappingList, int id, List<ItemTagModel> itemTagModels) throws JsonProcessingException {
33973 tejus.loha 819
        List<Map<String, Object>> variantList = new ArrayList<>();
820
        List<SuperCatalogMapping> matchingVariantNames = superCatalogMappingList.parallelStream()
821
                .filter(mapping -> mapping.getSuperCatalogId() == id)
822
                .collect(Collectors.toList());
823
 
824
        if (!matchingVariantNames.isEmpty()) {
34229 vikas.jang 825
            for (SuperCatalogMapping matchingVariant : matchingVariantNames) {
826
                logger.info("matchingVariantName: "+matchingVariant);
35344 vikas 827
                ItemTagModel itemTagModel = itemTagModels.stream().filter(tag -> tag.getItem().getCatalogItemId() == matchingVariant.getCatalogId()).findFirst().orElse(null);
34229 vikas.jang 828
                   if (matchingVariant != null && matchingVariant.getVariantName() != null && itemTagModels.stream().anyMatch(tag -> tag.getItem().getCatalogItemId() == matchingVariant.getCatalogId() && tag.getTagListing().isActive())) {
33973 tejus.loha 829
                    Map<String, Object> variantObj = new HashMap<>();
34229 vikas.jang 830
                    variantObj.put("catalogId", matchingVariant.getCatalogId());
831
                    variantObj.put("variantName", matchingVariant.getVariantName());
35344 vikas 832
                    variantObj.put("mrp", itemTagModel != null ? itemTagModel.getTagListing().getMrp() : 0.0);
35345 vikas 833
                    variantObj.put("mop", itemTagModel != null ? itemTagModel.getTagListing().getMop() : 0.0);
35344 vikas 834
                    variantObj.put("sellingPrice", itemTagModel != null ? itemTagModel.getTagListing().getSellingPrice() : 0.0);
33973 tejus.loha 835
                    variantList.add(variantObj);
836
                }
837
            }
838
        }
839
 
840
        if (variantList.isEmpty()) {
841
            return "[]";
842
        }
843
 
844
        variantList.sort((v1, v2) -> {
845
            int[] n1 = extractNumbers((String) v1.get("variantName"));
846
            int[] n2 = extractNumbers((String) v2.get("variantName"));
847
            int cmp = Integer.compare(n1[0], n2[0]);
848
            return cmp != 0 ? cmp : Integer.compare(n1[1], n2[1]);
849
        });
850
 
851
        ObjectMapper mapper = new ObjectMapper();
852
        return mapper.writeValueAsString(variantList);
853
    }
33979 ranu 854
//(4GB 64GB)
33973 tejus.loha 855
    private int[] extractNumbers(String input) {
856
        String[] parts = input.split("\\s+");
857
        int[] result = new int[2];
858
 
859
        for (int i = 0; i < Math.min(parts.length, 2); i++) {
33979 ranu 860
            String part = (parts[i].toUpperCase()).replace("(", "").replace(")", "");
33973 tejus.loha 861
            if (part.endsWith("GB")) {
862
                result[i] = Integer.parseInt(part.replace("GB", "").trim());
863
            } else if (part.endsWith("TB")) {
864
                result[i] = Integer.parseInt(part.replace("TB", "").trim()) * 1024;
865
            }
866
        }
867
 
868
        return result;
869
    }
870
 
31604 tejbeer 871
}