Subversion Repositories SmartDukaan

Rev

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

Rev 2105 Rev 2119
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.VendorItemMapping;
6
import in.shop2020.catalog.dashboard.shared.VendorDetails;
7
import in.shop2020.catalog.dashboard.shared.VendorPricings;
7
import in.shop2020.model.v1.catalog.InventoryService;
8
import in.shop2020.model.v1.catalog.InventoryService;
8
import in.shop2020.model.v1.catalog.VendorItemMapping;
-
 
9
import in.shop2020.model.v1.catalog.VendorItemPricing;
-
 
10
import in.shop2020.model.v1.catalog.status;
9
import in.shop2020.model.v1.catalog.status;
11
import in.shop2020.thrift.clients.CatalogServiceClient;
10
import in.shop2020.thrift.clients.CatalogServiceClient;
-
 
11
import in.shop2020.utils.CategoryManager;
12
 
12
 
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Calendar;
14
import java.util.Calendar;
15
import java.util.Collections;
15
import java.util.Collections;
16
import java.util.HashMap;
16
import java.util.HashMap;
17
import java.util.List;
17
import java.util.List;
18
import java.util.Map;
18
import java.util.Map;
19
import java.util.Map.Entry;
-
 
20
 
19
 
21
import com.google.gwt.core.client.GWT;
20
import com.google.gwt.core.client.GWT;
22
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
21
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
23
 
22
 
24
@SuppressWarnings("serial")
23
@SuppressWarnings("serial")
Line 29... Line 28...
29
        
28
        
30
        try {
29
        try {
31
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
30
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
32
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
31
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
33
            
32
            
-
 
33
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(false);
-
 
34
            
-
 
35
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
-
 
36
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
-
 
37
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
-
 
38
            }
-
 
39
        } catch (Exception e) {
-
 
40
            e.printStackTrace();
-
 
41
        }
-
 
42
        Collections.sort(itemList, new ItemsComparator());
-
 
43
        return itemList;
-
 
44
    }
-
 
45
    
-
 
46
    public List<Item> getAllActiveItems(){
-
 
47
        List<Item> itemList = new ArrayList<Item>();
-
 
48
        
-
 
49
        try {
-
 
50
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
51
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
-
 
52
            
34
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
53
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
35
            
54
            
36
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
55
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
37
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
56
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
38
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
57
                itemList.add(getItemFromThriftItem(thriftItem, null, null));
Line 106... Line 125...
106
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
125
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
107
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
126
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
108
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
127
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
109
            
128
            
110
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
129
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
111
            //List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
130
            List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
112
            return getItemFromThriftItem(thriftItem, vip, null);
131
            return getItemFromThriftItem(thriftItem, vip, vim);
113
        }catch(Exception e){
132
        }catch(Exception e){
114
            // Oops! We didn't receive the details. We should let the user know
133
            // Oops! We didn't receive the details. We should let the user know
115
            // that the catalog service is currently unavailable.
134
            // that the catalog service is currently unavailable.
116
            e.printStackTrace();
135
            e.printStackTrace();
117
        }
136
        }
118
        return null;
137
        return null;
119
    }
138
    }
120
    
139
    
121
    public void reduceReservationCount(long itemId, long warehouseId, double quantity){
-
 
122
        GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
-
 
123
        try{
-
 
124
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
125
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
-
 
126
            catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
-
 
127
        }catch(Exception e){
-
 
128
            // TODO: Oops! We couldn't reduce the item reservation count. This will
-
 
129
            // result in underestimation of inventory stock. Should be corrected
-
 
130
            // periodically.
-
 
131
            e.printStackTrace();
-
 
132
        }
-
 
133
    }
-
 
134
    
-
 
135
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
140
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
136
            List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings, 
141
            List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings, 
137
            List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings){
142
            List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings){
138
        
143
        
139
        Map<Long, VendorDetails> vendorDetailsMap = new HashMap<Long, VendorDetails>();
144
        Map<Long, VendorItemMapping> vItemMap = new HashMap<Long, VendorItemMapping>();
140
        VendorDetails vDetails;
145
        VendorItemMapping vItemMapping;
141
        if(tVendorMappings != null) {
146
        if(tVendorMappings != null) {
142
            for(VendorItemMapping vim : tVendorMappings) {
147
            for(in.shop2020.model.v1.catalog.VendorItemMapping vim : tVendorMappings) {
143
                vDetails = vendorDetailsMap.get(vim.getVendorId());
-
 
144
                if(vDetails == null) {
-
 
145
                    vDetails = new VendorDetails();
148
                vItemMapping = new VendorItemMapping();
146
                    vDetails.setVendorId(vim.getVendorId());
-
 
147
                }
-
 
148
                vDetails.setVendorId(vim.getVendorId());
149
                vItemMapping.setVendorId(vim.getVendorId());
149
                vDetails.setItemKey(vim.getItemKey());
150
                vItemMapping.setItemKey(vim.getItemKey());
150
                vendorDetailsMap.put(vDetails.getVendorId(), vDetails);
151
                vItemMap.put(vItemMapping.getVendorId(), vItemMapping);
151
            }
152
            }
152
        }
153
        }
-
 
154
        
-
 
155
        // TODO: For testing. Remove this code before moving to production.
-
 
156
        /* 
-
 
157
        Map<Long, VendorItemMapping> vItemMap = new HashMap<Long, VendorItemMapping>();
-
 
158
        vItemMap.put(1L, new VendorItemMapping(1, "Item Key Test 1"));
-
 
159
        vItemMap.put(1L, new VendorItemMapping(1, "Item Key Test 2"));
-
 
160
        */
-
 
161
        
-
 
162
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
-
 
163
        VendorPricings vPricings;
153
        if(tVendorPricings != null) {
164
        if(tVendorPricings != null) {
154
            for(VendorItemPricing vip : tVendorPricings) {
165
            for(in.shop2020.model.v1.catalog.VendorItemPricing vip : tVendorPricings) {
155
                vDetails = vendorDetailsMap.get(vip.getVendorId());
-
 
156
                if(vDetails == null) {
-
 
157
                    vDetails = new VendorDetails();
166
                vPricings = new VendorPricings();
158
                    vDetails.setVendorId(vip.getVendorId());
167
                vPricings.setVendorId(vip.getVendorId());
159
                }
-
 
160
                vDetails.setMop(vip.getMop());
168
                vPricings.setMop(vip.getMop());
161
                vDetails.setDealerPrice(vip.getDealerPrice());
169
                vPricings.setDealerPrice(vip.getDealerPrice());
162
                vDetails.setTransferPrice(vip.getTransferPrice());
170
                vPricings.setTransferPrice(vip.getTransferPrice());
163
                vendorDetailsMap.put(vDetails.getVendorId(), vDetails);
171
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
164
            }
172
            }
165
        }
173
        }
166
        
174
        
167
        Item item = new Item(thriftItem.getId(),
175
        Item item = new Item(thriftItem.getId(),
168
                thriftItem.getProductGroup(),
176
                thriftItem.getProductGroup(),
169
                thriftItem.getBrand(),
177
                thriftItem.getBrand(),
170
                thriftItem.getModelNumber(),
178
                thriftItem.getModelNumber(),
171
                thriftItem.getModelName(),
179
                thriftItem.getModelName(),
172
                thriftItem.getColor(),
180
                thriftItem.getColor(),
173
                thriftItem.getCategory(),
181
                //thriftItem.getCategory(),
174
                //CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
182
                CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
175
                thriftItem.getComments(),
183
                thriftItem.getComments(),
176
                thriftItem.getCatalogItemId(),
184
                thriftItem.getCatalogItemId(),
177
                thriftItem.getFeatureId(),
185
                thriftItem.getFeatureId(),
178
                thriftItem.getFeatureDescription(),
186
                thriftItem.getFeatureDescription(),
179
                thriftItem.getMrp(),
187
                thriftItem.getMrp(),
Line 190... Line 198...
190
                thriftItem.getBestDealText(),
198
                thriftItem.getBestDealText(),
191
                thriftItem.getBestDealValue(),
199
                thriftItem.getBestDealValue(),
192
                thriftItem.getBestSellingRank(),
200
                thriftItem.getBestSellingRank(),
193
                thriftItem.isDefaultForEntity(),
201
                thriftItem.isDefaultForEntity(),
194
                (thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
202
                (thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
195
                vendorDetailsMap
203
                vendorPricingMap,
-
 
204
                vItemMap
196
                );
205
                );
197
        return item;
206
        return item;
198
    }
207
    }
199
 
208
 
200
    @Override
209
    @Override
Line 240... Line 249...
240
                GWT.log("Error updating item, returned Item Id: " + rItemId);
249
                GWT.log("Error updating item, returned Item Id: " + rItemId);
241
                return false;
250
                return false;
242
            }
251
            }
243
            GWT.log("Item updated successfully, Item Id: " + item.getId());
252
            GWT.log("Item updated successfully, Item Id: " + item.getId());
244
            
253
            
245
            Map<Long, VendorDetails> vendorDetails = item.getVendorDetails();
254
            Map<Long, VendorItemMapping> vendorMappings = item.getVendorMappingsMap();
246
            if(vendorDetails != null && !vendorDetails.isEmpty()) {
255
            if(vendorMappings != null && !vendorMappings.isEmpty()) {
247
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
-
 
248
                in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
256
                in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
-
 
257
                for(VendorItemMapping v : vendorMappings.values()) {
-
 
258
                    tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
-
 
259
                    tVendorMapping.setVendorId(v.getVendorId());
-
 
260
                    tVendorMapping.setItemKey(v.getItemKey());
-
 
261
                    tVendorMapping.setItemId(item.getId());
-
 
262
                    tVendorMapping.setVendorCategory(item.getVendorCategory());
-
 
263
                    catalogClient.addVendorItemMapping(tVendorMapping);
-
 
264
                    GWT.log("VendorItemMapping updated. " + tVendorMapping.getVendorId() + ", " + tVendorMapping.getItemId() + ", " +
-
 
265
                            tVendorMapping.getItemKey() + ", " + tVendorMapping.getVendorCategory());
-
 
266
                }
-
 
267
            }
-
 
268
            
-
 
269
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
-
 
270
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
-
 
271
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
249
                for(VendorDetails v : vendorDetails.values()) {
272
                for(VendorPricings v : vendorPricings.values()) {
250
                    tVendorPricing = new VendorItemPricing();
273
                    tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
251
                    tVendorPricing.setVendorId(v.getVendorId());
274
                    tVendorPricing.setVendorId(v.getVendorId());
252
                    tVendorPricing.setItemId(item.getId());
275
                    tVendorPricing.setItemId(item.getId());
253
                    tVendorPricing.setMop(v.getMop());
276
                    tVendorPricing.setMop(v.getMop());
254
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
277
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
255
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
278
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
256
                    catalogClient.addVendorItemPricing(tVendorPricing);
279
                    catalogClient.addVendorItemPricing(tVendorPricing);
257
                    GWT.log("VendorItemPricing updated. " + tVendorPricing.getVendorId() + ", " + tVendorPricing.getItemId() + ", " +
280
                    GWT.log("VendorItemPricing updated. " + tVendorPricing.getVendorId() + ", " + tVendorPricing.getItemId() + ", " +
258
                            tVendorPricing.getMop() + ", " + tVendorPricing.getTransferPrice() + ", " + tVendorPricing.getDealerPrice());
281
                            tVendorPricing.getMop() + ", " + tVendorPricing.getTransferPrice() + ", " + tVendorPricing.getDealerPrice());
259
                    
-
 
260
                    /*tVendorMapping = new VendorItemMapping();
-
 
261
                    tVendorMapping.setVendorId(v.getVendorId());
-
 
262
                    tVendorMapping.setItemKey(v.getItemKey());
-
 
263
                    tVendorMapping.setItemId(item.getId());
-
 
264
                    tVendorMapping.setVendorCategory(item.getVendorCategory());
-
 
265
                    catalogClient.addVendorItemMapping(tVendorMapping);
-
 
266
                    GWT.log("VendorItemMapping updated. " + tVendorMapping.getVendorId() + ", " + tVendorMapping.getItemId() + ", " +
-
 
267
                            tVendorMapping.getItemKey() + ", " + tVendorMapping.getVendorCategory());*/
-
 
268
                }
282
                }
269
            }
283
            }
270
            
284
            
271
        }catch(Exception e){
285
        }catch(Exception e){
272
            e.printStackTrace();
286
            e.printStackTrace();
Line 390... Line 404...
390
            tItem.setDefaultForEntity(item.isDefaultForEntity());
404
            tItem.setDefaultForEntity(item.isDefaultForEntity());
391
            tItem.setHotspotCategory(item.getVendorCategory());
405
            tItem.setHotspotCategory(item.getVendorCategory());
392
            
406
            
393
            itemId = catalogClient.addItem(tItem);
407
            itemId = catalogClient.addItem(tItem);
394
 
408
 
395
            Map<Long, VendorDetails> vendorDetails = item.getVendorDetails();
409
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
396
            if(vendorDetails != null && !vendorDetails.isEmpty()) {
410
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
397
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
411
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
-
 
412
                for(VendorPricings v : vendorPricings.values()) {
-
 
413
                    tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
-
 
414
                    tVendorPricing.setVendorId(v.getVendorId());
-
 
415
                    tVendorPricing.setItemId(itemId);
-
 
416
                    tVendorPricing.setMop(v.getMop());
-
 
417
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
-
 
418
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
-
 
419
                    catalogClient.addVendorItemPricing(tVendorPricing);
-
 
420
                }
-
 
421
            }
-
 
422
            
-
 
423
            Map<Long, VendorItemMapping> vendorKeysMap = item.getVendorMappingsMap();
-
 
424
            if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
398
                in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
425
                in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
399
                for(VendorDetails v : vendorDetails.values()) {
426
                for(VendorItemMapping v : vendorKeysMap.values()) {
400
                    tVendorMapping = new VendorItemMapping();
427
                    tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
401
                    tVendorMapping.setVendorId(v.getVendorId());
428
                    tVendorMapping.setVendorId(v.getVendorId());
402
                    tVendorMapping.setItemKey(v.getItemKey());
429
                    tVendorMapping.setItemKey(v.getItemKey());
403
                    tVendorMapping.setItemId(itemId);
430
                    tVendorMapping.setItemId(itemId);
404
                    tVendorMapping.setVendorCategory(item.getVendorCategory());
431
                    tVendorMapping.setVendorCategory(item.getVendorCategory());
405
                    catalogClient.addVendorItemMapping(tVendorMapping);
432
                    catalogClient.addVendorItemMapping(tVendorMapping);
406
                    
-
 
407
                    /*tVendorPricing = new VendorItemPricing();
-
 
408
                    tVendorPricing.setVendorId(v.getVendorId());
-
 
409
                    tVendorPricing.setItemId(itemId);
-
 
410
                    tVendorPricing.setMop(v.getMop());
-
 
411
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
-
 
412
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
-
 
413
                    catalogClient.addVendorItemPricing(tVendorPricing);*/
-
 
414
                }
433
                }
415
                
-
 
416
            }
434
            }
-
 
435
            
-
 
436
            
-
 
437
            
417
            /*Map<Long, double[]> vendors = item.getVendorPricings();
438
            /*Map<Long, double[]> vendors = item.getVendorPricings();
418
            List<VendorItemPricing> vPricesList;
439
            List<VendorItemPricing> vPricesList;
419
            if(vendors != null && !vendors.isEmpty()) {
440
            if(vendors != null && !vendors.isEmpty()) {
420
                vPricesList = new ArrayList<VendorItemPricing>();
441
                vPricesList = new ArrayList<VendorItemPricing>();
421
                VendorItemPricing vendorPrices = null;
442
                VendorItemPricing vendorPrices = null;
Line 438... Line 459...
438
        } catch (Exception e) {
459
        } catch (Exception e) {
439
            e.printStackTrace();
460
            e.printStackTrace();
440
        }
461
        }
441
        return itemId;
462
        return itemId;
442
    }
463
    }
-
 
464
 
-
 
465
    @Override
-
 
466
    public long checkSimilarItem(String productGroup, String brand, String modelNumber, String color) {
-
 
467
        
-
 
468
        try {
-
 
469
            CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
470
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
-
 
471
            return catalogClient.checkSimilarItem(productGroup, brand, modelNumber, color);
-
 
472
        } catch (Exception e) {
-
 
473
            // TODO Auto-generated catch block
-
 
474
            e.printStackTrace();
-
 
475
        }
-
 
476
        return 0;
-
 
477
    }
443
}
478
}