Subversion Repositories SmartDukaan

Rev

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

Rev 7182 Rev 7190
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
 
4
 
-
 
5
import in.shop2020.catalog.dashboard.shared.FreebieItem;
5
import in.shop2020.catalog.dashboard.shared.Item;
6
import in.shop2020.catalog.dashboard.shared.Item;
6
import in.shop2020.catalog.dashboard.shared.ItemInventory;
7
import in.shop2020.catalog.dashboard.shared.ItemInventory;
7
import in.shop2020.catalog.dashboard.shared.ItemStatus;
8
import in.shop2020.catalog.dashboard.shared.ItemStatus;
8
import in.shop2020.catalog.dashboard.shared.ItemsComparator;
9
import in.shop2020.catalog.dashboard.shared.ItemsComparator;
9
import in.shop2020.catalog.dashboard.shared.SourcePricings;
10
import in.shop2020.catalog.dashboard.shared.SourcePricings;
Line 100... Line 101...
100
            Client catalogClient = catalogServiceClient.getClient();
101
            Client catalogClient = catalogServiceClient.getClient();
101
 
102
 
102
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllIgnoredInventoryUpdateItemsList(offset, limit);
103
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllIgnoredInventoryUpdateItemsList(offset, limit);
103
 
104
 
104
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
105
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
105
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
106
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
106
            }
107
            }
107
        } catch (Exception e) {
108
        } catch (Exception e) {
108
            logger.error("Error while getting all items from the catalog service", e);
109
            logger.error("Error while getting all items from the catalog service", e);
109
        }
110
        }
110
        return itemList;
111
        return itemList;
Line 134... Line 135...
134
            Client catalogClient = catalogServiceClient.getClient();
135
            Client catalogClient = catalogServiceClient.getClient();
135
 
136
 
136
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
137
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
137
 
138
 
138
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
139
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
139
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
140
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
140
            }
141
            }
141
        } catch (Exception e) {
142
        } catch (Exception e) {
142
            logger.error("Error while getting all items from the catalog service", e);
143
            logger.error("Error while getting all items from the catalog service", e);
143
        }
144
        }
144
        return itemList;
145
        return itemList;
Line 174... Line 175...
174
            CatalogClient catalogServiceClient = new CatalogClient();
175
            CatalogClient catalogServiceClient = new CatalogClient();
175
            Client catalogClient = catalogServiceClient.getClient();
176
            Client catalogClient = catalogServiceClient.getClient();
176
 
177
 
177
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
178
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
178
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
179
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
179
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
180
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
180
            }
181
            }
181
        } catch(Exception e){
182
        } catch(Exception e){
182
            logger.error("Error while getting the best deals from the catalog service", e);
183
            logger.error("Error while getting the best deals from the catalog service", e);
183
        }
184
        }
184
        //Collections.sort(itemList, new ItemsComparator());
185
        //Collections.sort(itemList, new ItemsComparator());
Line 192... Line 193...
192
            CatalogClient catalogServiceClient = new CatalogClient();
193
            CatalogClient catalogServiceClient = new CatalogClient();
193
            Client catalogClient = catalogServiceClient.getClient();
194
            Client catalogClient = catalogServiceClient.getClient();
194
 
195
 
195
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
196
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
196
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
197
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
197
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
198
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
198
            }
199
            }
199
        } catch(Exception e){
200
        } catch(Exception e){
200
            logger.error("Error while getting the risky items from the catalog service", e);
201
            logger.error("Error while getting the risky items from the catalog service", e);
201
        }
202
        }
202
        Collections.sort(itemList, new ItemsComparator());
203
        Collections.sort(itemList, new ItemsComparator());
Line 210... Line 211...
210
            CatalogClient catalogServiceClient = new CatalogClient();
211
            CatalogClient catalogServiceClient = new CatalogClient();
211
            Client catalogClient = catalogServiceClient.getClient();
212
            Client catalogClient = catalogServiceClient.getClient();
212
 
213
 
213
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
214
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
214
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
215
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
215
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
216
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
216
            }
217
            }
217
        } catch(Exception e){
218
        } catch(Exception e){
218
            logger.error("Error while getting the best sellers from the catalog service", e);
219
            logger.error("Error while getting the best sellers from the catalog service", e);
219
        }
220
        }
220
        return itemList;        
221
        return itemList;        
Line 256... Line 257...
256
            Client catalogClient = catalogServiceClient.getClient();
257
            Client catalogClient = catalogServiceClient.getClient();
257
 
258
 
258
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
259
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
259
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
260
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
260
                //List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
261
                //List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
261
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
262
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
262
            }
263
            }
263
        } catch(Exception e){
264
        } catch(Exception e){
264
            logger.error("Error while getting the latest arrivals from the catalog service", e);
265
            logger.error("Error while getting the latest arrivals from the catalog service", e);
265
        }
266
        }
266
        return itemList;
267
        return itemList;
Line 274... Line 275...
274
            CatalogClient catalogServiceClient = new CatalogClient();
275
            CatalogClient catalogServiceClient = new CatalogClient();
275
            Client catalogClient = catalogServiceClient.getClient();
276
            Client catalogClient = catalogServiceClient.getClient();
276
 
277
 
277
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
278
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
278
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
279
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
279
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
280
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
280
            }
281
            }
281
        } catch(Exception e){
282
        } catch(Exception e){
282
            logger.error("Error while getting the search results from the catalog service", e);
283
            logger.error("Error while getting the search results from the catalog service", e);
283
        }
284
        }
284
        return itemList;
285
        return itemList;
Line 321... Line 322...
321
            List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
322
            List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
322
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
323
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
323
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
324
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
324
            in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
325
            in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
325
            ItemStockPurchaseParams stockPurchaseParams = inventoryClient.getItemStockPurchaseParams(thriftItem.getId());
326
            ItemStockPurchaseParams stockPurchaseParams = inventoryClient.getItemStockPurchaseParams(thriftItem.getId());
-
 
327
            Long freebieItemId = catalogClient.getFreebieForItem(thriftItem.getId());
326
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
328
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
327
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers, stockPurchaseParams);
329
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers, stockPurchaseParams, freebieItemId);
328
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
330
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
329
            return it;
331
            return it;
330
        }catch(Exception e){
332
        }catch(Exception e){
331
            logger.error("Error while getting the item from the catalog service", e);
333
            logger.error("Error while getting the item from the catalog service", e);
332
        }
334
        }
Line 370... Line 372...
370
            if(item.getMinStockLevel()!=0 || item.getNumOfDaysStock()!=0) {
372
            if(item.getMinStockLevel()!=0 || item.getNumOfDaysStock()!=0) {
371
            	inventoryClient.updateItemStockPurchaseParams(item.getId(), item.getNumOfDaysStock(),
373
            	inventoryClient.updateItemStockPurchaseParams(item.getId(), item.getNumOfDaysStock(),
372
            			item.getMinStockLevel());
374
            			item.getMinStockLevel());
373
            }
375
            }
374
            
376
            
-
 
377
            if(item.getFreebieItemId()!=0) {
-
 
378
            	in.shop2020.model.v1.catalog.FreebieItem freebieItem = new in.shop2020.model.v1.catalog.FreebieItem();
-
 
379
            	freebieItem.setItemId(item.getId());
-
 
380
            	freebieItem.setFreebieItemId(item.getFreebieItemId());
-
 
381
            	catalogClient.addOrUpdateFreebieForItem(freebieItem);
-
 
382
            }
-
 
383
            
375
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
384
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
376
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
385
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
377
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
386
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
378
                for(VendorPricings v : vendorPricings.values()) {
387
                for(VendorPricings v : vendorPricings.values()) {
379
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
388
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
Line 562... Line 571...
562
                }
571
                }
563
            }
572
            }
564
            
573
            
565
        	inventoryClient.updateItemStockPurchaseParams(itemId, item.getNumOfDaysStock(),
574
        	inventoryClient.updateItemStockPurchaseParams(itemId, item.getNumOfDaysStock(),
566
        			item.getMinStockLevel());
575
        			item.getMinStockLevel());
-
 
576
        	
-
 
577
        	if(item.getFreebieItemId()!=null && item.getFreebieItemId()!=0) {
-
 
578
        		in.shop2020.model.v1.catalog.FreebieItem freebieItem = 
-
 
579
        			new in.shop2020.model.v1.catalog.FreebieItem();
-
 
580
        		freebieItem.setItemId(itemId);
-
 
581
        		freebieItem.setFreebieItemId(item.getFreebieItemId());
-
 
582
        		catalogClient.addOrUpdateFreebieForItem(freebieItem);
-
 
583
        	}
-
 
584
        	
567
        } catch (Exception e) {
585
        } catch (Exception e) {
568
            logger.error("Error while adding an item: ", e);
586
            logger.error("Error while adding an item: ", e);
569
        }
587
        }
570
        return itemId;
588
        return itemId;
571
    }
589
    }
Line 770... Line 788...
770
            
788
            
771
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
789
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
772
                List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
790
                List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
773
                List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
791
                List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
774
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
792
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
775
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null));
793
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null, null));
776
            }
794
            }
777
        } catch (Exception e) {
795
        } catch (Exception e) {
778
            logger.error("Error while getting items by category: " + category, e);
796
            logger.error("Error while getting items by category: " + category, e);
779
        }
797
        }
780
        Collections.sort(itemList, new ItemsComparator());
798
        Collections.sort(itemList, new ItemsComparator());
Line 800... Line 818...
800
                
818
                
801
    			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
819
    			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
802
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
820
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
803
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
821
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
804
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
822
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
805
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null));
823
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null, null));
806
    		} catch (Exception e) {
824
    		} catch (Exception e) {
807
    			logger.error("Could not fetch item for : " + itemId, e);
825
    			logger.error("Could not fetch item for : " + itemId, e);
808
    			return "Could not push to production. No item got pushed.";
826
    			return "Could not push to production. No item got pushed.";
809
    		}
827
    		}
810
    	}
828
    	}
Line 928... Line 946...
928
            Client catalogClient = catalogServiceClient.getClient();
946
            Client catalogClient = catalogServiceClient.getClient();
929
 
947
 
930
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
948
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
931
 
949
 
932
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
950
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
933
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null));
951
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null));
934
            }
952
            }
935
        } catch (Exception e) {
953
        } catch (Exception e) {
936
            logger.error("Error while getting items by status: " + st, e);
954
            logger.error("Error while getting items by status: " + st, e);
937
        }
955
        }
938
        return itemList;
956
        return itemList;
Line 956... Line 974...
956
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
974
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
957
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
975
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
958
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, 
976
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, 
959
            in.shop2020.model.v1.inventory.ItemInventory tItemInventory, 
977
            in.shop2020.model.v1.inventory.ItemInventory tItemInventory, 
960
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings, 
978
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings, 
961
            ItemStockPurchaseParams tStockPurchaseParams){
979
            ItemStockPurchaseParams tStockPurchaseParams, Long freebieItemId){
962
 
980
 
963
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
981
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
964
        VendorItemMapping vItemMapping;
982
        VendorItemMapping vItemMapping;
965
        if(tVendorMappings != null) {
983
        if(tVendorMappings != null) {
966
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
984
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
Line 1089... Line 1107...
1089
                vendorPricingMap,
1107
                vendorPricingMap,
1090
                vItemMap,
1108
                vItemMap,
1091
                sourcePricingMap,
1109
                sourcePricingMap,
1092
                SimilarItemslist,
1110
                SimilarItemslist,
1093
                voucherMap, stockPurchaseParams.getNumOfDaysStock(), 
1111
                voucherMap, stockPurchaseParams.getNumOfDaysStock(), 
1094
                stockPurchaseParams.getMinStockLevel());
1112
                stockPurchaseParams.getMinStockLevel(), freebieItemId);
1095
        return item;
1113
        return item;
1096
    }
1114
    }
1097
    
1115
    
1098
    /**
1116
    /**
1099
     * 
1117
     * 
Line 1149... Line 1167...
1149
		try{
1167
		try{
1150
            CatalogClient catalogServiceClient = new CatalogClient();
1168
            CatalogClient catalogServiceClient = new CatalogClient();
1151
            Client catalogClient = catalogServiceClient.getClient();
1169
            Client catalogClient = catalogServiceClient.getClient();
1152
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1170
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1153
 
1171
 
1154
            return getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null);
1172
            return getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null);
1155
        }catch(Exception e){
1173
        }catch(Exception e){
1156
            logger.error("Error while adding the SimilarItems for: " + itemId, e);
1174
            logger.error("Error while adding the SimilarItems for: " + itemId, e);
1157
        }
1175
        }
1158
        return null;
1176
        return null;
1159
	}
1177
	}