Subversion Repositories SmartDukaan

Rev

Rev 3359 | Rev 3850 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3359 Rev 3558
Line 1... Line 1...
1
package in.shop2020.catalog.dashboard.server;
1
package in.shop2020.catalog.dashboard.server;
2
 
2
 
3
import in.shop2020.catalog.dashboard.client.CatalogService;
3
import in.shop2020.catalog.dashboard.client.CatalogService;
4
import in.shop2020.catalog.dashboard.shared.Item;
4
import in.shop2020.catalog.dashboard.shared.Item;
5
import in.shop2020.catalog.dashboard.shared.ItemsComparator;
5
import in.shop2020.catalog.dashboard.shared.ItemsComparator;
-
 
6
import in.shop2020.catalog.dashboard.shared.SourcePricings;
6
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
7
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
7
import in.shop2020.catalog.dashboard.shared.VendorPricings;
8
import in.shop2020.catalog.dashboard.shared.VendorPricings;
8
import in.shop2020.config.ConfigException;
9
import in.shop2020.config.ConfigException;
9
import in.shop2020.model.v1.catalog.InventoryService;
10
import in.shop2020.model.v1.catalog.InventoryService;
10
import in.shop2020.model.v1.catalog.status;
11
import in.shop2020.model.v1.catalog.status;
Line 46... Line 47...
46
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
47
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
47
 
48
 
48
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(false);
49
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(false);
49
 
50
 
50
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
51
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
51
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
52
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null));
52
            }
53
            }
53
        } catch (Exception e) {
54
        } catch (Exception e) {
54
            logger.error("Error while getting all items from the catalog service", e);
55
            logger.error("Error while getting all items from the catalog service", e);
55
        }
56
        }
56
        Collections.sort(itemList, new ItemsComparator());
57
        Collections.sort(itemList, new ItemsComparator());
Line 87... Line 88...
87
            CatalogClient catalogServiceClient = new CatalogClient();
88
            CatalogClient catalogServiceClient = new CatalogClient();
88
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
89
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
89
 
90
 
90
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
91
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
91
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
92
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
92
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
93
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null));
93
            }
94
            }
94
        } catch(Exception e){
95
        } catch(Exception e){
95
            logger.error("Error while getting the best deals from the catalog service", e);
96
            logger.error("Error while getting the best deals from the catalog service", e);
96
        }
97
        }
97
        //Collections.sort(itemList, new ItemsComparator());
98
        //Collections.sort(itemList, new ItemsComparator());
Line 105... Line 106...
105
            CatalogClient catalogServiceClient = new CatalogClient();
106
            CatalogClient catalogServiceClient = new CatalogClient();
106
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
107
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
107
 
108
 
108
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
109
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
109
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
110
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
110
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
111
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null));
111
            }
112
            }
112
        } catch(Exception e){
113
        } catch(Exception e){
113
            logger.error("Error while getting the risky items from the catalog service", e);
114
            logger.error("Error while getting the risky items from the catalog service", e);
114
        }
115
        }
115
        Collections.sort(itemList, new ItemsComparator());
116
        Collections.sort(itemList, new ItemsComparator());
Line 123... Line 124...
123
            CatalogClient catalogServiceClient = new CatalogClient();
124
            CatalogClient catalogServiceClient = new CatalogClient();
124
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
125
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
125
 
126
 
126
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
127
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
127
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
128
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
128
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
129
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null));
129
            }
130
            }
130
        } catch(Exception e){
131
        } catch(Exception e){
131
            logger.error("Error while getting the best sellers from the catalog service", e);
132
            logger.error("Error while getting the best sellers from the catalog service", e);
132
        }
133
        }
133
        return itemList;        
134
        return itemList;        
Line 141... Line 142...
141
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
142
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
142
 
143
 
143
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
144
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
144
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
145
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
145
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
146
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
146
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
147
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null));
147
            }
148
            }
148
        } catch(Exception e){
149
        } catch(Exception e){
149
            logger.error("Error while getting the latest arrivals from the catalog service", e);
150
            logger.error("Error while getting the latest arrivals from the catalog service", e);
150
        }
151
        }
151
        return itemList;
152
        return itemList;
Line 157... Line 158...
157
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
158
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
158
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
159
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
159
 
160
 
160
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
161
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
161
            List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
162
            List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
-
 
163
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
162
            return getItemFromThriftItem(thriftItem, vip, vim);
164
            return getItemFromThriftItem(thriftItem, vip, vim, sip);
163
        }catch(Exception e){
165
        }catch(Exception e){
164
            logger.error("Error while getting the item from the catalog service", e);
166
            logger.error("Error while getting the item from the catalog service", e);
165
        }
167
        }
166
        return null;
168
        return null;
167
    }
169
    }
Line 211... Line 213...
211
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
213
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
212
                    catalogClient.addVendorItemPricing(tVendorPricing);
214
                    catalogClient.addVendorItemPricing(tVendorPricing);
213
                    logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
215
                    logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
214
                }
216
                }
215
            }
217
            }
-
 
218
            
-
 
219
            Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
-
 
220
            if(sourcePricings != null && !sourcePricings.isEmpty()) {
-
 
221
                in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricings;
-
 
222
                for(SourcePricings s : sourcePricings.values()) {
-
 
223
                	tSourcePricings = new in.shop2020.model.v1.catalog.SourceItemPricing();
-
 
224
                	tSourcePricings.setSourceId(s.getSourceId());
-
 
225
                    tSourcePricings.setItemId(item.getId());
-
 
226
                    tSourcePricings.setMrp(s.getMrp());
-
 
227
                    tSourcePricings.setSellingPrice(s.getSellingPrice());
-
 
228
                    catalogClient.addSourceItemPricing(tSourcePricings);
-
 
229
                    logger.info("Updated SourceItemPricing: " + tSourcePricings.toString());
-
 
230
                }
-
 
231
            }
-
 
232
            
216
        }catch(Exception e){
233
        }catch(Exception e){
217
            logger.error("Error while updating item: ", e);
234
            logger.error("Error while updating item: ", e);
218
            return false;
235
            return false;
219
        }
236
        }
220
        return true;
237
        return true;
Line 238... Line 255...
238
        }
255
        }
239
        return vendorMap;
256
        return vendorMap;
240
    }
257
    }
241
 
258
 
242
    @Override
259
    @Override
-
 
260
    public Map<Long, String> getAllSources() {
-
 
261
        Map<Long, String> sourceMap = new HashMap<Long, String>();
-
 
262
        try {
-
 
263
            CatalogClient catalogServiceClient = new CatalogClient();
-
 
264
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
-
 
265
 
-
 
266
            List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
-
 
267
 
-
 
268
            for(in.shop2020.model.v1.catalog.Source s : sources) {
-
 
269
            	sourceMap.put(s.getId(), s.getName());
-
 
270
            }
-
 
271
        } catch (Exception e) {
-
 
272
            logger.error("Error while getting all the vendors: ", e);
-
 
273
        }
-
 
274
        return sourceMap;
-
 
275
    }
-
 
276
 
-
 
277
    @Override
243
    public Map<Long, String> getAllWarehouses() {
278
    public Map<Long, String> getAllWarehouses() {
244
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
279
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
245
        try {
280
        try {
246
            CatalogClient catalogServiceClient = new CatalogClient();
281
            CatalogClient catalogServiceClient = new CatalogClient();
247
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
282
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
Line 464... Line 499...
464
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByVendorCategory(category);
499
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByVendorCategory(category);
465
            
500
            
466
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
501
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
467
                List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
502
                List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
468
                List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
503
                List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
-
 
504
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
469
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim));
505
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip));
470
            }
506
            }
471
        } catch (Exception e) {
507
        } catch (Exception e) {
472
            logger.error("Error while getting items by vendor category: " + category, e);
508
            logger.error("Error while getting items by vendor category: " + category, e);
473
        }
509
        }
474
        Collections.sort(itemList, new ItemsComparator());
510
        Collections.sort(itemList, new ItemsComparator());
Line 569... Line 605...
569
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
605
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
570
 
606
 
571
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatus(st);
607
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatus(st);
572
 
608
 
573
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
609
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
574
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
610
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null));
575
            }
611
            }
576
        } catch (Exception e) {
612
        } catch (Exception e) {
577
            logger.error("Error while getting items by status: " + st, e);
613
            logger.error("Error while getting items by status: " + st, e);
578
        }
614
        }
579
        Collections.sort(itemList, new ItemsComparator());
615
        Collections.sort(itemList, new ItemsComparator());
Line 589... Line 625...
589
     * @param tVendorMappings
625
     * @param tVendorMappings
590
     * @return item object with attributes copied from thrift item object.
626
     * @return item object with attributes copied from thrift item object.
591
     */
627
     */
592
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
628
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
593
            List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings, 
629
            List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings, 
594
            List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings){
630
            List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings,
-
 
631
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings){
595
 
632
 
596
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
633
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
597
        VendorItemMapping vItemMapping;
634
        VendorItemMapping vItemMapping;
598
        if(tVendorMappings != null) {
635
        if(tVendorMappings != null) {
599
            for(in.shop2020.model.v1.catalog.VendorItemMapping vim : tVendorMappings) {
636
            for(in.shop2020.model.v1.catalog.VendorItemMapping vim : tVendorMappings) {
Line 615... Line 652...
615
                vPricings.setTransferPrice(vip.getTransferPrice());
652
                vPricings.setTransferPrice(vip.getTransferPrice());
616
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
653
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
617
            }
654
            }
618
        }
655
        }
619
 
656
 
-
 
657
        Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
-
 
658
        SourcePricings sPricings;
-
 
659
        if(tSourceMappings != null) {
-
 
660
            for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
-
 
661
                sPricings = new SourcePricings();
-
 
662
                sPricings.setSourceId(sip.getSourceId());
-
 
663
                sPricings.setMrp(sip.getMrp());
-
 
664
                sPricings.setSellingPrice(sip.getSellingPrice());
-
 
665
                sourcePricingMap.put(sPricings.getSourceId(), sPricings);
-
 
666
            }
-
 
667
        }
-
 
668
 
620
        Item item = new Item(thriftItem.getId(),
669
        Item item = new Item(thriftItem.getId(),
621
                thriftItem.getHotspotCategory(),
670
                thriftItem.getHotspotCategory(),
622
                thriftItem.getProductGroup(),
671
                thriftItem.getProductGroup(),
623
                thriftItem.getBrand(),
672
                thriftItem.getBrand(),
624
                thriftItem.getModelNumber(),
673
                thriftItem.getModelNumber(),
Line 648... Line 697...
648
                thriftItem.isRisky(),
697
                thriftItem.isRisky(),
649
                thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
698
                thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
650
                thriftItem.isSetPreferredWarehouse() ? thriftItem.getPreferredWarehouse() : null,
699
                thriftItem.isSetPreferredWarehouse() ? thriftItem.getPreferredWarehouse() : null,
651
                (thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
700
                (thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
652
                vendorPricingMap,
701
                vendorPricingMap,
653
                vItemMap);
702
                vItemMap,
-
 
703
                sourcePricingMap);
654
        return item;
704
        return item;
655
    }
705
    }
656
    
706
    
657
    /**
707
    /**
658
     * 
708
     *