Subversion Repositories SmartDukaan

Rev

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

Rev 2562 Rev 3129
Line 6... Line 6...
6
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
6
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
7
import in.shop2020.catalog.dashboard.shared.VendorPricings;
7
import in.shop2020.catalog.dashboard.shared.VendorPricings;
8
import in.shop2020.config.ConfigException;
8
import in.shop2020.config.ConfigException;
9
import in.shop2020.model.v1.catalog.InventoryService;
9
import in.shop2020.model.v1.catalog.InventoryService;
10
import in.shop2020.model.v1.catalog.status;
10
import in.shop2020.model.v1.catalog.status;
11
import in.shop2020.thrift.clients.CatalogServiceClient;
11
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.thrift.clients.config.ConfigClient;
12
import in.shop2020.thrift.clients.config.ConfigClient;
13
import in.shop2020.utils.CategoryManager;
13
import in.shop2020.utils.CategoryManager;
14
import in.shop2020.utils.ConfigClientKeys;
14
import in.shop2020.utils.ConfigClientKeys;
15
 
15
 
16
import java.io.BufferedReader;
16
import java.io.BufferedReader;
Line 39... Line 39...
39
    
39
    
40
    public List<Item> getAllItems(){
40
    public List<Item> getAllItems(){
41
        List<Item> itemList = new ArrayList<Item>();
41
        List<Item> itemList = new ArrayList<Item>();
42
 
42
 
43
        try {
43
        try {
44
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
44
            CatalogClient catalogServiceClient = new CatalogClient();
45
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
45
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
46
 
46
 
47
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(false);
47
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(false);
48
 
48
 
49
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
49
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
Line 58... Line 58...
58
 
58
 
59
    public List<Item> getAllActiveItems(){
59
    public List<Item> getAllActiveItems(){
60
        List<Item> itemList = new ArrayList<Item>();
60
        List<Item> itemList = new ArrayList<Item>();
61
 
61
 
62
        try {
62
        try {
63
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
63
            CatalogClient catalogServiceClient = new CatalogClient();
64
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
64
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
65
 
65
 
66
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
66
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
67
 
67
 
68
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
68
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
Line 96... Line 96...
96
    }
96
    }
97
 
97
 
98
    public List<Item> getBestDeals(){
98
    public List<Item> getBestDeals(){
99
        List<Item> itemList = new ArrayList<Item>();
99
        List<Item> itemList = new ArrayList<Item>();
100
        try {
100
        try {
101
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
101
            CatalogClient catalogServiceClient = new CatalogClient();
102
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
102
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
103
 
103
 
104
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
104
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
105
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
105
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
106
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
106
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
Line 114... Line 114...
114
    
114
    
115
    @Override
115
    @Override
116
    public List<Item> getRiskyItems() {
116
    public List<Item> getRiskyItems() {
117
        List<Item> itemList = new ArrayList<Item>();
117
        List<Item> itemList = new ArrayList<Item>();
118
        try {
118
        try {
119
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
119
            CatalogClient catalogServiceClient = new CatalogClient();
120
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
120
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
121
 
121
 
122
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
122
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
123
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
123
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
124
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
124
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
Line 132... Line 132...
132
 
132
 
133
    public List<Item> getBestSellers(){
133
    public List<Item> getBestSellers(){
134
        List<Item> itemList = new ArrayList<Item>();
134
        List<Item> itemList = new ArrayList<Item>();
135
 
135
 
136
        try {
136
        try {
137
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
137
            CatalogClient catalogServiceClient = new CatalogClient();
138
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
138
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
139
 
139
 
140
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
140
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
141
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
141
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
142
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
142
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
Line 150... Line 150...
150
 
150
 
151
    public List<Item> getLatestArrivals(){
151
    public List<Item> getLatestArrivals(){
152
        List<Item> itemList = new ArrayList<Item>();
152
        List<Item> itemList = new ArrayList<Item>();
153
 
153
 
154
        try {
154
        try {
155
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
155
            CatalogClient catalogServiceClient = new CatalogClient();
156
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
156
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
157
 
157
 
158
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
158
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
159
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
159
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
160
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
160
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
Line 167... Line 167...
167
        return itemList;
167
        return itemList;
168
    }
168
    }
169
 
169
 
170
    public Item getItem(long itemId){
170
    public Item getItem(long itemId){
171
        try{
171
        try{
172
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
172
            CatalogClient catalogServiceClient = new CatalogClient();
173
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
173
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
174
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
174
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
175
 
175
 
176
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
176
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
177
            List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
177
            List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
Line 265... Line 265...
265
 
265
 
266
    @Override
266
    @Override
267
    public boolean updateItem(Item item) {
267
    public boolean updateItem(Item item) {
268
        GWT.log("Got a call to update item, Item Id: " + item.getId());
268
        GWT.log("Got a call to update item, Item Id: " + item.getId());
269
        try{
269
        try{
270
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
270
            CatalogClient catalogServiceClient = new CatalogClient();
271
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
271
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
272
 
272
 
273
            in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
273
            in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
274
            setThriftItemParams(tItem, item);
274
            setThriftItemParams(tItem, item);
275
 
275
 
Line 323... Line 323...
323
 
323
 
324
    @Override
324
    @Override
325
    public Map<Long, String> getAllVendors() {
325
    public Map<Long, String> getAllVendors() {
326
        Map<Long, String> vendorMap = new HashMap<Long, String>();
326
        Map<Long, String> vendorMap = new HashMap<Long, String>();
327
        try {
327
        try {
328
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
328
            CatalogClient catalogServiceClient = new CatalogClient();
329
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
329
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
330
 
330
 
331
            List<in.shop2020.model.v1.catalog.Vendor> vendors = catalogClient.getAllVendors();
331
            List<in.shop2020.model.v1.catalog.Vendor> vendors = catalogClient.getAllVendors();
332
 
332
 
333
            for(in.shop2020.model.v1.catalog.Vendor v : vendors) {
333
            for(in.shop2020.model.v1.catalog.Vendor v : vendors) {
Line 341... Line 341...
341
 
341
 
342
    @Override
342
    @Override
343
    public Map<Long, String> getAllWarehouses() {
343
    public Map<Long, String> getAllWarehouses() {
344
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
344
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
345
        try {
345
        try {
346
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
346
            CatalogClient catalogServiceClient = new CatalogClient();
347
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
347
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
348
 
348
 
349
            List<in.shop2020.model.v1.catalog.Warehouse> warehouses = catalogClient.getAllWarehouses(true);
349
            List<in.shop2020.model.v1.catalog.Warehouse> warehouses = catalogClient.getAllWarehouses(true);
350
 
350
 
351
            for(in.shop2020.model.v1.catalog.Warehouse w : warehouses) {
351
            for(in.shop2020.model.v1.catalog.Warehouse w : warehouses) {
Line 359... Line 359...
359
 
359
 
360
    @Override
360
    @Override
361
    public long addItem(Item item) {
361
    public long addItem(Item item) {
362
        long itemId = 0;
362
        long itemId = 0;
363
        try {
363
        try {
364
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
364
            CatalogClient catalogServiceClient = new CatalogClient();
365
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
365
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
366
 
366
 
367
 
367
 
368
            in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
368
            in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
369
            setThriftItemParams(tItem, item);
369
            setThriftItemParams(tItem, item);
Line 404... Line 404...
404
 
404
 
405
    @Override
405
    @Override
406
    public long checkSimilarItem(String productGroup, String brand, String modelNumber, String color) {
406
    public long checkSimilarItem(String productGroup, String brand, String modelNumber, String color) {
407
 
407
 
408
        try {
408
        try {
409
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
409
            CatalogClient catalogServiceClient = new CatalogClient();
410
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
410
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
411
            return catalogClient.checkSimilarItem(productGroup, brand, modelNumber, color);
411
            return catalogClient.checkSimilarItem(productGroup, brand, modelNumber, color);
412
        } catch (Exception e) {
412
        } catch (Exception e) {
413
            e.printStackTrace();
413
            e.printStackTrace();
414
        }
414
        }
Line 486... Line 486...
486
    }
486
    }
487
 
487
 
488
    @Override
488
    @Override
489
    public void pauseItem(long itemId) {
489
    public void pauseItem(long itemId) {
490
        try {
490
        try {
491
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
491
            CatalogClient catalogServiceClient = new CatalogClient();
492
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
492
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
493
 
493
 
494
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
494
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
495
        } catch (Exception e) {
495
        } catch (Exception e) {
496
            e.printStackTrace();
496
            e.printStackTrace();
Line 499... Line 499...
499
    }
499
    }
500
 
500
 
501
    @Override
501
    @Override
502
    public void markInProcess(long itemId) {
502
    public void markInProcess(long itemId) {
503
        try {
503
        try {
504
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
504
            CatalogClient catalogServiceClient = new CatalogClient();
505
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
505
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
506
 
506
 
507
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
507
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
508
        } catch (Exception e) {
508
        } catch (Exception e) {
509
            e.printStackTrace();
509
            e.printStackTrace();
Line 511... Line 511...
511
    }
511
    }
512
 
512
 
513
    @Override
513
    @Override
514
    public void phaseoutItem(long itemId) {
514
    public void phaseoutItem(long itemId) {
515
        try {
515
        try {
516
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
516
            CatalogClient catalogServiceClient = new CatalogClient();
517
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
517
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
518
 
518
 
519
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
519
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
520
        } catch (Exception e) {
520
        } catch (Exception e) {
521
            e.printStackTrace();
521
            e.printStackTrace();
Line 523... Line 523...
523
    }
523
    }
524
 
524
 
525
    @Override
525
    @Override
526
    public void activateItem(long itemId) {
526
    public void activateItem(long itemId) {
527
        try {
527
        try {
528
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
528
            CatalogClient catalogServiceClient = new CatalogClient();
529
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
529
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
530
 
530
 
531
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
531
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
532
        } catch (Exception e) {
532
        } catch (Exception e) {
533
            e.printStackTrace();
533
            e.printStackTrace();
Line 536... Line 536...
536
 
536
 
537
    @Override
537
    @Override
538
    public boolean changeItemRiskyFlag(long itemId, boolean risky) {
538
    public boolean changeItemRiskyFlag(long itemId, boolean risky) {
539
        try {
539
        try {
540
            // Initialize client for staging server
540
            // Initialize client for staging server
541
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
541
            CatalogClient catalogServiceClient = new CatalogClient();
542
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
542
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
543
 
543
 
544
            // Initialize client for production server
544
            // Initialize client for production server
545
            CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(), 
545
            CatalogClient catalogServiceClient_Prod = new CatalogClient(CatalogClient.class.getSimpleName(), 
546
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
546
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
547
                    ConfigClientKeys.catalog_service_server_port.toString());
547
                    ConfigClientKeys.catalog_service_server_port.toString());
548
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
548
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
549
            catalogClient.changeItemRiskyFlag(itemId, risky);
549
            catalogClient.changeItemRiskyFlag(itemId, risky);
550
 
550
 
Line 571... Line 571...
571
     * @return
571
     * @return
572
     */
572
     */
573
    List<Item> getItemsByVendorCategory(String category) {
573
    List<Item> getItemsByVendorCategory(String category) {
574
        List<Item> itemList = new ArrayList<Item>();
574
        List<Item> itemList = new ArrayList<Item>();
575
        try {
575
        try {
576
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
576
            CatalogClient catalogServiceClient = new CatalogClient();
577
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
577
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
578
            
578
            
579
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByVendorCategory(category);
579
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByVendorCategory(category);
580
            
580
            
581
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
581
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
Line 596... Line 596...
596
     * @return
596
     * @return
597
     */
597
     */
598
    List<Item> getItemsByStatus(status st) {
598
    List<Item> getItemsByStatus(status st) {
599
        List<Item> itemList = new ArrayList<Item>();
599
        List<Item> itemList = new ArrayList<Item>();
600
        try {
600
        try {
601
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
601
            CatalogClient catalogServiceClient = new CatalogClient();
602
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
602
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
603
 
603
 
604
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatus(st);
604
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatus(st);
605
 
605
 
606
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
606
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
Line 622... Line 622...
622
        // else move forward with update.
622
        // else move forward with update.
623
        if(errMsg != null) {
623
        if(errMsg != null) {
624
            return errMsg;
624
            return errMsg;
625
        }
625
        }
626
        try{
626
        try{
627
            CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(), 
627
            CatalogClient catalogServiceClient_Prod = new CatalogClient(CatalogClient.class.getSimpleName(), 
628
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
628
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
629
                    ConfigClientKeys.catalog_service_server_port.toString());
629
                    ConfigClientKeys.catalog_service_server_port.toString());
630
            
630
            
631
            //for testing, put catalog_service_server_port_test in shop2020.cfg
631
            //for testing, put catalog_service_server_port_test in shop2020.cfg
632
            /*CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(), 
632
            /*CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(),