Subversion Repositories SmartDukaan

Rev

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

Rev 5706 Rev 5946
Line 10... Line 10...
10
import in.shop2020.catalog.dashboard.shared.VendorPricings;
10
import in.shop2020.catalog.dashboard.shared.VendorPricings;
11
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
11
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
12
import in.shop2020.config.ConfigException;
12
import in.shop2020.config.ConfigException;
13
import in.shop2020.content.ContentService;
13
import in.shop2020.content.ContentService;
14
import in.shop2020.content.ContentServiceException;
14
import in.shop2020.content.ContentServiceException;
15
import in.shop2020.model.v1.catalog.InventoryService;
15
import in.shop2020.model.v1.inventory.InventoryService;
-
 
16
import in.shop2020.model.v1.catalog.CatalogService.Client;
16
import in.shop2020.model.v1.catalog.ItemType;
17
import in.shop2020.model.v1.catalog.ItemType;
17
import in.shop2020.model.v1.catalog.status;
18
import in.shop2020.model.v1.catalog.status;
18
import in.shop2020.model.v1.user.VoucherType;
19
import in.shop2020.model.v1.user.VoucherType;
19
import in.shop2020.thrift.clients.CatalogClient;
20
import in.shop2020.thrift.clients.CatalogClient;
20
import in.shop2020.thrift.clients.ContentClient;
21
import in.shop2020.thrift.clients.ContentClient;
-
 
22
import in.shop2020.thrift.clients.InventoryClient;
21
import in.shop2020.thrift.clients.config.ConfigClient;
23
import in.shop2020.thrift.clients.config.ConfigClient;
22
import in.shop2020.utils.CategoryManager;
24
import in.shop2020.utils.CategoryManager;
23
import in.shop2020.utils.ConfigClientKeys;
25
import in.shop2020.utils.ConfigClientKeys;
24
 
26
 
25
import java.io.BufferedReader;
27
import java.io.BufferedReader;
Line 73... Line 75...
73
    @Override
75
    @Override
74
    public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
76
    public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
75
        int count = 0;
77
        int count = 0;
76
        try{
78
        try{
77
            CatalogClient catalogServiceClient = new CatalogClient();
79
            CatalogClient catalogServiceClient = new CatalogClient();
78
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
80
            Client catalogClient = catalogServiceClient.getClient();
79
            
81
            
80
            status stat = status.findByValue(itemStatus.getValue());
82
            status stat = status.findByValue(itemStatus.getValue());
81
            count = catalogClient.getItemCountByStatus(useStatus, stat);
83
            count = catalogClient.getItemCountByStatus(useStatus, stat);
82
        }catch(Exception e){
84
        }catch(Exception e){
83
            logger.error("Error while getting the count of items from the catalog service", e);
85
            logger.error("Error while getting the count of items from the catalog service", e);
Line 89... Line 91...
89
    public List<Item> getAllItems(int start, int limit) {
91
    public List<Item> getAllItems(int start, int limit) {
90
        List<Item> itemList = new ArrayList<Item>();
92
        List<Item> itemList = new ArrayList<Item>();
91
 
93
 
92
        try {
94
        try {
93
            CatalogClient catalogServiceClient = new CatalogClient();
95
            CatalogClient catalogServiceClient = new CatalogClient();
94
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
96
            Client catalogClient = catalogServiceClient.getClient();
95
 
97
 
96
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
98
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
97
 
99
 
98
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
100
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
99
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
101
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
Line 130... Line 132...
130
 
132
 
131
    public List<Item> getBestDeals(){
133
    public List<Item> getBestDeals(){
132
        List<Item> itemList = new ArrayList<Item>();
134
        List<Item> itemList = new ArrayList<Item>();
133
        try {
135
        try {
134
            CatalogClient catalogServiceClient = new CatalogClient();
136
            CatalogClient catalogServiceClient = new CatalogClient();
135
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
137
            Client catalogClient = catalogServiceClient.getClient();
136
 
138
 
137
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
139
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
138
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
140
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
139
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
141
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
140
            }
142
            }
Line 148... Line 150...
148
    @Override
150
    @Override
149
    public List<Item> getRiskyItems() {
151
    public List<Item> getRiskyItems() {
150
        List<Item> itemList = new ArrayList<Item>();
152
        List<Item> itemList = new ArrayList<Item>();
151
        try {
153
        try {
152
            CatalogClient catalogServiceClient = new CatalogClient();
154
            CatalogClient catalogServiceClient = new CatalogClient();
153
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
155
            Client catalogClient = catalogServiceClient.getClient();
154
 
156
 
155
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
157
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
156
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
158
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
157
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
159
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
158
            }
160
            }
Line 166... Line 168...
166
    public List<Item> getBestSellers(){
168
    public List<Item> getBestSellers(){
167
        List<Item> itemList = new ArrayList<Item>();
169
        List<Item> itemList = new ArrayList<Item>();
168
 
170
 
169
        try {
171
        try {
170
            CatalogClient catalogServiceClient = new CatalogClient();
172
            CatalogClient catalogServiceClient = new CatalogClient();
171
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
173
            Client catalogClient = catalogServiceClient.getClient();
172
 
174
 
173
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
175
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
174
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
176
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
175
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
177
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
176
            }
178
            }
Line 184... Line 186...
184
    public List<Item> getLatestArrivals(){
186
    public List<Item> getLatestArrivals(){
185
        List<Item> itemList = new ArrayList<Item>();
187
        List<Item> itemList = new ArrayList<Item>();
186
 
188
 
187
        try {
189
        try {
188
            CatalogClient catalogServiceClient = new CatalogClient();
190
            CatalogClient catalogServiceClient = new CatalogClient();
189
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
191
            Client catalogClient = catalogServiceClient.getClient();
190
 
192
 
191
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
193
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
192
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
194
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
193
                //List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
195
                //List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
194
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
196
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
195
            }
197
            }
196
        } catch(Exception e){
198
        } catch(Exception e){
197
            logger.error("Error while getting the latest arrivals from the catalog service", e);
199
            logger.error("Error while getting the latest arrivals from the catalog service", e);
198
        }
200
        }
Line 203... Line 205...
203
    public List<Item> searchItems(int start, int limit, List<String> searchTerms) {
205
    public List<Item> searchItems(int start, int limit, List<String> searchTerms) {
204
        List<Item> itemList = new ArrayList<Item>();
206
        List<Item> itemList = new ArrayList<Item>();
205
 
207
 
206
        try {
208
        try {
207
            CatalogClient catalogServiceClient = new CatalogClient();
209
            CatalogClient catalogServiceClient = new CatalogClient();
208
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
210
            Client catalogClient = catalogServiceClient.getClient();
209
 
211
 
210
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
212
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
211
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
213
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
212
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
214
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
213
            }
215
            }
Line 220... Line 222...
220
    @Override
222
    @Override
221
    public int getSearchResultCount(List<String> searchTerms){
223
    public int getSearchResultCount(List<String> searchTerms){
222
        int count = 0;
224
        int count = 0;
223
        try {
225
        try {
224
            CatalogClient catalogServiceClient = new CatalogClient();
226
            CatalogClient catalogServiceClient = new CatalogClient();
225
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
227
            Client catalogClient = catalogServiceClient.getClient();
226
 
228
 
227
            count = catalogClient.getSearchResultCount(searchTerms);
229
            count = catalogClient.getSearchResultCount(searchTerms);
228
        } catch(Exception e){
230
        } catch(Exception e){
229
            logger.error("Error while getting the search results from the catalog service", e);
231
            logger.error("Error while getting the search results from the catalog service", e);
230
        }
232
        }
Line 233... Line 235...
233
    }
235
    }
234
    
236
    
235
    public Item getItem(long itemId){
237
    public Item getItem(long itemId){
236
        try{
238
        try{
237
            CatalogClient catalogServiceClient = new CatalogClient();
239
            CatalogClient catalogServiceClient = new CatalogClient();
238
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
240
            Client catalogClient = catalogServiceClient.getClient();
-
 
241
            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
242
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
239
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
243
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
240
            Long catalogItemId = thriftItem.getCatalogItemId();
244
            Long catalogItemId = thriftItem.getCatalogItemId();
241
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByCatalogId(catalogItemId);
245
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByCatalogId(catalogItemId);
242
            List <Long> sameItemsWithDifferentColors = new ArrayList<Long>();
246
            List <Long> sameItemsWithDifferentColors = new ArrayList<Long>();
243
            if(thriftItems.size()>1){
247
            if(thriftItems.size()>1){
Line 246... Line 250...
246
		        	if(!id.equals(itemId)){
250
		        	if(!id.equals(itemId)){
247
		        		sameItemsWithDifferentColors.add(id); 
251
		        		sameItemsWithDifferentColors.add(id); 
248
		        	}
252
		        	}
249
	            }
253
	            }
250
            }
254
            }
251
            List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
255
            List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
252
            List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
256
            List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
253
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
257
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
254
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
258
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
255
            in.shop2020.model.v1.catalog.ItemInventory itemInventory = catalogClient.getItemInventoryByItemId(thriftItem.getId());
259
            in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
256
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
260
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
257
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers);
261
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers);
258
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
262
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
259
            return it;
263
            return it;
260
        }catch(Exception e){
264
        }catch(Exception e){
Line 266... Line 270...
266
    @Override
270
    @Override
267
    public boolean updateItem(Item item) {
271
    public boolean updateItem(Item item) {
268
        logger.info("Updating item with Id: " + item.getId());
272
        logger.info("Updating item with Id: " + item.getId());
269
        try{
273
        try{
270
            CatalogClient catalogServiceClient = new CatalogClient();
274
            CatalogClient catalogServiceClient = new CatalogClient();
271
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
275
            Client catalogClient = catalogServiceClient.getClient();
-
 
276
            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
277
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
272
 
278
            
273
            in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
279
            in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
274
            setThriftItemParams(tItem, item);
280
            setThriftItemParams(tItem, item);
275
 
281
 
276
            long rItemId;
282
            long rItemId;
277
            if((rItemId = catalogClient.updateItem(tItem)) != item.getId()) {
283
            if((rItemId = catalogClient.updateItem(tItem)) != item.getId()) {
Line 280... Line 286...
280
            }
286
            }
281
            logger.info("Successfully updated item with id: " + item.getId());
287
            logger.info("Successfully updated item with id: " + item.getId());
282
 
288
 
283
            Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();
289
            Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();
284
            if(vendorMappings != null && !vendorMappings.isEmpty()) {
290
            if(vendorMappings != null && !vendorMappings.isEmpty()) {
285
                in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
291
                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
286
 
292
 
287
                for(Entry<String, VendorItemMapping> e : vendorMappings.entrySet()) {
293
                for(Entry<String, VendorItemMapping> e : vendorMappings.entrySet()) {
288
                    tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
294
                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
289
                    VendorItemMapping v = e.getValue();
295
                    VendorItemMapping v = e.getValue();
290
                    tVendorMapping.setVendorId(v.getVendorId());
296
                    tVendorMapping.setVendorId(v.getVendorId());
291
                    tVendorMapping.setItemKey(v.getItemKey());
297
                    tVendorMapping.setItemKey(v.getItemKey());
292
                    tVendorMapping.setItemId(item.getId());
298
                    tVendorMapping.setItemId(item.getId());
293
                    catalogClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
299
                    inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
294
                    logger.info("Updates VendorItemMapping: " + tVendorMapping.toString());
300
                    logger.info("Updates VendorItemMapping: " + tVendorMapping.toString());
295
                }
301
                }
296
            }
302
            }
297
 
303
 
298
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
304
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
299
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
305
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
300
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
306
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
301
                for(VendorPricings v : vendorPricings.values()) {
307
                for(VendorPricings v : vendorPricings.values()) {
302
                    tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
308
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
303
                    tVendorPricing.setVendorId(v.getVendorId());
309
                    tVendorPricing.setVendorId(v.getVendorId());
304
                    tVendorPricing.setItemId(item.getId());
310
                    tVendorPricing.setItemId(item.getId());
305
                    tVendorPricing.setMop(v.getMop());
311
                    tVendorPricing.setMop(v.getMop());
306
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
312
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
307
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
313
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
308
                    catalogClient.addVendorItemPricing(tVendorPricing);
314
                    inventoryClient.addVendorItemPricing(tVendorPricing);
309
                    logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
315
                    logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
310
                }
316
                }
311
            }
317
            }
312
            
318
            
313
            Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
319
            Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
Line 334... Line 340...
334
 
340
 
335
    @Override
341
    @Override
336
    public Map<Long, String> getAllVendors() {
342
    public Map<Long, String> getAllVendors() {
337
        Map<Long, String> vendorMap = new HashMap<Long, String>();
343
        Map<Long, String> vendorMap = new HashMap<Long, String>();
338
        try {
344
        try {
339
            CatalogClient catalogServiceClient = new CatalogClient();
345
            InventoryClient inventoryServiceClient = new InventoryClient();
340
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
346
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
341
 
347
            
342
            List<in.shop2020.model.v1.catalog.Vendor> vendors = catalogClient.getAllVendors();
348
            List<in.shop2020.model.v1.inventory.Vendor> vendors = inventoryClient.getAllVendors();
343
 
349
 
344
            for(in.shop2020.model.v1.catalog.Vendor v : vendors) {
350
            for(in.shop2020.model.v1.inventory.Vendor v : vendors) {
345
                vendorMap.put(v.getId(), v.getName());
351
                vendorMap.put(v.getId(), v.getName());
346
            }
352
            }
347
        } catch (Exception e) {
353
        } catch (Exception e) {
348
            logger.error("Error while getting all the vendors: ", e);
354
            logger.error("Error while getting all the vendors: ", e);
349
        }
355
        }
Line 353... Line 359...
353
    @Override
359
    @Override
354
    public Map<Long, String> getAllSources() {
360
    public Map<Long, String> getAllSources() {
355
        Map<Long, String> sourceMap = new HashMap<Long, String>();
361
        Map<Long, String> sourceMap = new HashMap<Long, String>();
356
        try {
362
        try {
357
            CatalogClient catalogServiceClient = new CatalogClient();
363
            CatalogClient catalogServiceClient = new CatalogClient();
358
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
364
            Client catalogClient = catalogServiceClient.getClient();
359
 
365
 
360
            List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
366
            List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
361
 
367
 
362
            for(in.shop2020.model.v1.catalog.Source s : sources) {
368
            for(in.shop2020.model.v1.catalog.Source s : sources) {
363
            	sourceMap.put(s.getId(), s.getName());
369
            	sourceMap.put(s.getId(), s.getName());
Line 371... Line 377...
371
    @Override
377
    @Override
372
    public Map<Long, String> getShippingWarehouses() {
378
    public Map<Long, String> getShippingWarehouses() {
373
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
379
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
374
        Set<Long> shippingLocations = new HashSet<Long>();
380
        Set<Long> shippingLocations = new HashSet<Long>();
375
        try {
381
        try {
376
            CatalogClient catalogServiceClient = new CatalogClient();
382
            InventoryClient inventoryServiceClient = new InventoryClient();
377
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
383
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
378
 
384
            
379
            List<in.shop2020.model.v1.catalog.Warehouse> warehouses = catalogClient.getAllWarehouses(true);
385
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
380
 
386
 
381
            for(in.shop2020.model.v1.catalog.Warehouse warehouse : warehouses) {
387
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
382
                shippingLocations.add(warehouse.getShippingWarehouseId());
388
                shippingLocations.add(warehouse.getShippingWarehouseId());
383
            }
389
            }
384
            
390
            
385
            for(in.shop2020.model.v1.catalog.Warehouse warehouse : warehouses) {
391
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
386
                if (shippingLocations.contains(warehouse.getId())) {
392
                if (shippingLocations.contains(warehouse.getId())) {
387
                    warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
393
                    warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
388
                }                
394
                }                
389
            }
395
            }
390
        } catch (Exception e) {
396
        } catch (Exception e) {
Line 395... Line 401...
395
 
401
 
396
    @Override
402
    @Override
397
    public Map<Long, String> getAllWarehouses() {
403
    public Map<Long, String> getAllWarehouses() {
398
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
404
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
399
        try {
405
        try {
400
            CatalogClient catalogServiceClient = new CatalogClient();
406
        	InventoryClient inventoryServiceClient = new InventoryClient();
401
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
407
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
402
 
408
 
403
            List<in.shop2020.model.v1.catalog.Warehouse> warehouses = catalogClient.getAllWarehouses(true);
409
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
404
 
410
 
405
            for(in.shop2020.model.v1.catalog.Warehouse w : warehouses) {
411
            for(in.shop2020.model.v1.inventory.Warehouse w : warehouses) {
406
                warehouseMap.put(w.getId(), w.getDisplayName());
412
                warehouseMap.put(w.getId(), w.getDisplayName());
407
            }
413
            }
408
        } catch (Exception e) {
414
        } catch (Exception e) {
409
            logger.error("Error while getting all the warehouses:", e );
415
            logger.error("Error while getting all the warehouses:", e );
410
        }
416
        }
Line 414... Line 420...
414
    @Override
420
    @Override
415
    public long addItem(Item item) {
421
    public long addItem(Item item) {
416
        long itemId = 0;
422
        long itemId = 0;
417
        try {
423
        try {
418
            CatalogClient catalogServiceClient = new CatalogClient();
424
            CatalogClient catalogServiceClient = new CatalogClient();
419
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
425
            Client catalogClient = catalogServiceClient.getClient();
420
 
-
 
-
 
426
            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
427
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
421
 
428
 
422
            in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
429
            in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
423
            setThriftItemParams(tItem, item);
430
            setThriftItemParams(tItem, item);
424
            itemId = catalogClient.addItem(tItem);
431
            itemId = catalogClient.addItem(tItem);
425
 
432
 
426
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
433
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
427
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
434
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
428
                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
435
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
429
                for(VendorPricings v : vendorPricings.values()) {
436
                for(VendorPricings v : vendorPricings.values()) {
430
                    tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
437
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
431
                    tVendorPricing.setVendorId(v.getVendorId());
438
                    tVendorPricing.setVendorId(v.getVendorId());
432
                    tVendorPricing.setItemId(itemId);
439
                    tVendorPricing.setItemId(itemId);
433
                    tVendorPricing.setMop(v.getMop());
440
                    tVendorPricing.setMop(v.getMop());
434
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
441
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
435
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
442
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
436
                    catalogClient.addVendorItemPricing(tVendorPricing);
443
                    inventoryClient.addVendorItemPricing(tVendorPricing);
437
                }
444
                }
438
            }
445
            }
439
 
446
 
440
            Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();
447
            Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();
441
            if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
448
            if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
442
                in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
449
                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
443
                for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {
450
                for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {
444
                    tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
451
                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
445
                    VendorItemMapping v = e.getValue();
452
                    VendorItemMapping v = e.getValue();
446
                    tVendorMapping.setVendorId(v.getVendorId());
453
                    tVendorMapping.setVendorId(v.getVendorId());
447
                    tVendorMapping.setItemKey(v.getItemKey());
454
                    tVendorMapping.setItemKey(v.getItemKey());
448
                    tVendorMapping.setItemId(itemId);
455
                    tVendorMapping.setItemId(itemId);
449
                    catalogClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
456
                    inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
450
                }
457
                }
451
            }
458
            }
452
        } catch (Exception e) {
459
        } catch (Exception e) {
453
            logger.error("Error while adding an item: ", e);
460
            logger.error("Error while adding an item: ", e);
454
        }
461
        }
Line 458... Line 465...
458
    @Override
465
    @Override
459
    public long checkSimilarItem(String brand, String modelNumber, String modelName, String color) {
466
    public long checkSimilarItem(String brand, String modelNumber, String modelName, String color) {
460
 
467
 
461
        try {
468
        try {
462
            CatalogClient catalogServiceClient = new CatalogClient();
469
            CatalogClient catalogServiceClient = new CatalogClient();
463
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
470
            Client catalogClient = catalogServiceClient.getClient();
464
            return catalogClient.checkSimilarItem(brand, modelNumber, modelName, color);
471
            return catalogClient.checkSimilarItem(brand, modelNumber, modelName, color);
465
        } catch (Exception e) {
472
        } catch (Exception e) {
466
            logger.error("Error while checking for a similar item: ", e);
473
            logger.error("Error while checking for a similar item: ", e);
467
        }
474
        }
468
        return 0;
475
        return 0;
Line 555... Line 562...
555
 
562
 
556
    @Override
563
    @Override
557
    public void pauseItem(long itemId) {
564
    public void pauseItem(long itemId) {
558
        try {
565
        try {
559
            CatalogClient catalogServiceClient = new CatalogClient();
566
            CatalogClient catalogServiceClient = new CatalogClient();
560
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
567
            Client catalogClient = catalogServiceClient.getClient();
561
 
568
 
562
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
569
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
563
        } catch (Exception e) {
570
        } catch (Exception e) {
564
            logger.error("Error while pausing the item: " + itemId, e);
571
            logger.error("Error while pausing the item: " + itemId, e);
565
        }
572
        }
Line 568... Line 575...
568
 
575
 
569
    @Override
576
    @Override
570
    public void markInProcess(long itemId) {
577
    public void markInProcess(long itemId) {
571
        try {
578
        try {
572
            CatalogClient catalogServiceClient = new CatalogClient();
579
            CatalogClient catalogServiceClient = new CatalogClient();
573
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
580
            Client catalogClient = catalogServiceClient.getClient();
574
 
581
 
575
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
582
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
576
        } catch (Exception e) {
583
        } catch (Exception e) {
577
            logger.error("Error while marking in-process the item: " + itemId, e);
584
            logger.error("Error while marking in-process the item: " + itemId, e);
578
        }
585
        }
Line 580... Line 587...
580
 
587
 
581
    @Override
588
    @Override
582
    public void phaseoutItem(long itemId) {
589
    public void phaseoutItem(long itemId) {
583
        try {
590
        try {
584
            CatalogClient catalogServiceClient = new CatalogClient();
591
            CatalogClient catalogServiceClient = new CatalogClient();
585
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
592
            Client catalogClient = catalogServiceClient.getClient();
586
 
593
 
587
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
594
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
588
        } catch (Exception e) {
595
        } catch (Exception e) {
589
            logger.error("Error while phasing out the item: " + itemId, e);
596
            logger.error("Error while phasing out the item: " + itemId, e);
590
        }
597
        }
Line 592... Line 599...
592
 
599
 
593
    @Override
600
    @Override
594
    public void activateItem(long itemId) {
601
    public void activateItem(long itemId) {
595
        try {
602
        try {
596
            CatalogClient catalogServiceClient = new CatalogClient();
603
            CatalogClient catalogServiceClient = new CatalogClient();
597
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
604
            Client catalogClient = catalogServiceClient.getClient();
598
 
605
 
599
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
606
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
600
        } catch (Exception e) {
607
        } catch (Exception e) {
601
            logger.error("Error while activating the item: " + itemId, e);
608
            logger.error("Error while activating the item: " + itemId, e);
602
        }
609
        }
Line 606... Line 613...
606
    public boolean changeItemRiskyFlag(long itemId, boolean risky) {
613
    public boolean changeItemRiskyFlag(long itemId, boolean risky) {
607
        try {
614
        try {
608
            logger.info("Updating risky flag for item id: " + itemId + " to " + risky);
615
            logger.info("Updating risky flag for item id: " + itemId + " to " + risky);
609
            // Initialize client for staging server
616
            // Initialize client for staging server
610
            CatalogClient catalogServiceClient = new CatalogClient();
617
            CatalogClient catalogServiceClient = new CatalogClient();
611
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
618
            Client catalogClient = catalogServiceClient.getClient();
612
 
619
 
613
            // Initialize client for production server
620
            // Initialize client for production server
614
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
621
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
615
                    ConfigClientKeys.catalog_service_server_port.toString());
622
                    ConfigClientKeys.catalog_service_server_port.toString());
616
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
623
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
617
            catalogClient.changeItemRiskyFlag(itemId, risky);
624
            catalogClient.changeItemRiskyFlag(itemId, risky);
618
 
625
 
619
            try{
626
            try{
620
                catalogClient_Prod.changeItemRiskyFlag(itemId, risky);
627
                catalogClient_Prod.changeItemRiskyFlag(itemId, risky);
621
            }catch(Exception e){
628
            }catch(Exception e){
Line 641... Line 648...
641
     */
648
     */
642
    public List<Item> getItemsForMasterSheet(String category, String brand) {
649
    public List<Item> getItemsForMasterSheet(String category, String brand) {
643
        List<Item> itemList = new ArrayList<Item>();
650
        List<Item> itemList = new ArrayList<Item>();
644
        try {
651
        try {
645
            CatalogClient catalogServiceClient = new CatalogClient();
652
            CatalogClient catalogServiceClient = new CatalogClient();
646
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
653
            Client catalogClient = catalogServiceClient.getClient();
-
 
654
            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
655
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
647
            
656
            
648
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsForMasterSheet(category, brand);
657
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsForMasterSheet(category, brand);
649
            
658
            
650
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
659
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
651
                List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
660
                List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
652
                List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
661
                List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
653
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
662
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
654
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
663
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
655
            }
664
            }
656
        } catch (Exception e) {
665
        } catch (Exception e) {
657
            logger.error("Error while getting items by category: " + category, e);
666
            logger.error("Error while getting items by category: " + category, e);
Line 671... Line 680...
671
    	List<Item> items = new ArrayList<Item>();
680
    	List<Item> items = new ArrayList<Item>();
672
    	items.add(item);
681
    	items.add(item);
673
    	for(Long itemId : itemIds) {
682
    	for(Long itemId : itemIds) {
674
    		try {
683
    		try {
675
    			CatalogClient catalogServiceClient = new CatalogClient();
684
    			CatalogClient catalogServiceClient = new CatalogClient();
676
    			InventoryService.Client catalogClient = catalogServiceClient.getClient();
685
    			Client catalogClient = catalogServiceClient.getClient();
-
 
686
    			InventoryClient inventoryServiceClient = new InventoryClient();
-
 
687
                in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
688
                
677
    			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
689
    			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
678
				List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
690
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
679
				List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
691
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
680
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
692
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
681
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
693
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
682
    		} catch (Exception e) {
694
    		} catch (Exception e) {
683
    			logger.error("Could not fetch item for : " + itemId, e);
695
    			logger.error("Could not fetch item for : " + itemId, e);
684
    			return "Could not push to production. No item got pushed.";
696
    			return "Could not push to production. No item got pushed.";
Line 690... Line 702...
690
	        try{
702
	        try{
691
	            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
703
	            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
692
	                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
704
	                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
693
	                    ConfigClientKeys.catalog_service_server_port.toString());
705
	                    ConfigClientKeys.catalog_service_server_port.toString());
694
	            
706
	            
695
	            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
707
	            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
696
	
708
	
697
	            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(it.getId());
709
	            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(it.getId());
698
	            
710
	            
-
 
711
	            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
712
	            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
713
	            
699
	            if(it.getMrp() != null) {
714
	            if(it.getMrp() != null) {
700
	                tItem.setMrp(it.getMrp());
715
	                tItem.setMrp(it.getMrp());
701
	            }
716
	            }
702
	            
717
	            
703
	            if(it.getSellingPrice() != null) {
718
	            if(it.getSellingPrice() != null) {
Line 713... Line 728...
713
	
728
	
714
	            StringBuilder sb = new StringBuilder();
729
	            StringBuilder sb = new StringBuilder();
715
	            
730
	            
716
	            Map<Long, VendorPricings> vendorPricings = it.getVendorPricesMap();
731
	            Map<Long, VendorPricings> vendorPricings = it.getVendorPricesMap();
717
	            if(vendorPricings != null && !vendorPricings.isEmpty()) {
732
	            if(vendorPricings != null && !vendorPricings.isEmpty()) {
718
	                in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
733
	                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
719
	                for(VendorPricings v : vendorPricings.values()) {
734
	                for(VendorPricings v : vendorPricings.values()) {
720
	                    tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
735
	                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
721
	                    tVendorPricing.setVendorId(v.getVendorId());
736
	                    tVendorPricing.setVendorId(v.getVendorId());
722
	                    tVendorPricing.setItemId(it.getId());
737
	                    tVendorPricing.setItemId(it.getId());
723
	                    tVendorPricing.setMop(v.getMop());
738
	                    tVendorPricing.setMop(v.getMop());
724
	                    tVendorPricing.setTransferPrice(v.getTransferPrice());
739
	                    tVendorPricing.setTransferPrice(v.getTransferPrice());
725
	                    tVendorPricing.setDealerPrice(v.getDealerPrice());
740
	                    tVendorPricing.setDealerPrice(v.getDealerPrice());
726
	                    catalogClient_Prod.addVendorItemPricing(tVendorPricing);
741
	                    inventoryClient.addVendorItemPricing(tVendorPricing);
727
	                    logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
742
	                    logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
728
	                    sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");
743
	                    sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");
729
	                }
744
	                }
730
	            }
745
	            }
731
	            
746
	            
732
	            Map<String, VendorItemMapping> vendorMappings = it.getVendorKeysMap();
747
	            Map<String, VendorItemMapping> vendorMappings = it.getVendorKeysMap();
733
	            if(vendorMappings != null && !vendorMappings.isEmpty()) {
748
	            if(vendorMappings != null && !vendorMappings.isEmpty()) {
734
	                in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
749
	                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
735
	                for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
750
	                for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
736
	                    tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
751
	                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
737
	                    tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
752
	                    tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
738
	                    tVendorMapping.setItemId(it.getId());
753
	                    tVendorMapping.setItemId(it.getId());
739
	                    tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
754
	                    tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
740
	                    catalogClient_Prod.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
755
	                    inventoryClient.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
741
	                    logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
756
	                    logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
742
	                    sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
757
	                    sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
743
	                }
758
	                }
744
	            }
759
	            }
745
	
760
	
Line 791... Line 806...
791
     */
806
     */
792
    private List<Item> getItemsByStatus(status st, int start, int limit) {
807
    private List<Item> getItemsByStatus(status st, int start, int limit) {
793
        List<Item> itemList = new ArrayList<Item>();
808
        List<Item> itemList = new ArrayList<Item>();
794
        try {
809
        try {
795
            CatalogClient catalogServiceClient = new CatalogClient();
810
            CatalogClient catalogServiceClient = new CatalogClient();
796
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
811
            Client catalogClient = catalogServiceClient.getClient();
797
 
812
 
798
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
813
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
799
 
814
 
800
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
815
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
801
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
816
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
Line 817... Line 832...
817
     * @param tSimilarItems
832
     * @param tSimilarItems
818
     * @param tVoucherMappings
833
     * @param tVoucherMappings
819
     * @return item object with attributes copied from thrift item object.
834
     * @return item object with attributes copied from thrift item object.
820
     */
835
     */
821
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
836
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
822
            List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings, 
837
            List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
823
            List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings,
838
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
824
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
839
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
825
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, in.shop2020.model.v1.catalog.ItemInventory tItemInventory, List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings){
840
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, in.shop2020.model.v1.inventory.ItemInventory tItemInventory, List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings){
826
 
841
 
827
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
842
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
828
        VendorItemMapping vItemMapping;
843
        VendorItemMapping vItemMapping;
829
        if(tVendorMappings != null) {
844
        if(tVendorMappings != null) {
830
            for(in.shop2020.model.v1.catalog.VendorItemMapping vim : tVendorMappings) {
845
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
831
                vItemMapping = new VendorItemMapping();
846
                vItemMapping = new VendorItemMapping();
832
                vItemMapping.setVendorId(vim.getVendorId());
847
                vItemMapping.setVendorId(vim.getVendorId());
833
                vItemMapping.setItemKey(vim.getItemKey());
848
                vItemMapping.setItemKey(vim.getItemKey());
834
                vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
849
                vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
835
            }
850
            }
836
        }
851
        }
837
 
852
 
838
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
853
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
839
        VendorPricings vPricings;
854
        VendorPricings vPricings;
840
        if(tVendorPricings != null) {
855
        if(tVendorPricings != null) {
841
            for(in.shop2020.model.v1.catalog.VendorItemPricing vip : tVendorPricings) {
856
            for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
842
                vPricings = new VendorPricings();
857
                vPricings = new VendorPricings();
843
                vPricings.setVendorId(vip.getVendorId());
858
                vPricings.setVendorId(vip.getVendorId());
844
                vPricings.setMop(vip.getMop());
859
                vPricings.setMop(vip.getMop());
845
                vPricings.setDealerPrice(vip.getDealerPrice());
860
                vPricings.setDealerPrice(vip.getDealerPrice());
846
                vPricings.setTransferPrice(vip.getTransferPrice());
861
                vPricings.setTransferPrice(vip.getTransferPrice());
Line 982... Line 997...
982
 
997
 
983
	@Override
998
	@Override
984
	public boolean deleteSimilarItem(long itemId, long catalogItemId) {
999
	public boolean deleteSimilarItem(long itemId, long catalogItemId) {
985
		try{
1000
		try{
986
            CatalogClient catalogServiceClient = new CatalogClient();
1001
            CatalogClient catalogServiceClient = new CatalogClient();
987
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1002
            Client catalogClient = catalogServiceClient.getClient();
988
 
1003
 
989
            return catalogClient.deleteSimilarItem(itemId, catalogItemId);
1004
            return catalogClient.deleteSimilarItem(itemId, catalogItemId);
990
 
1005
 
991
        }catch(Exception e){
1006
        }catch(Exception e){
992
            logger.error("Error while deleting the SimilarItems for: " + itemId, e);
1007
            logger.error("Error while deleting the SimilarItems for: " + itemId, e);
Line 996... Line 1011...
996
 
1011
 
997
	@Override
1012
	@Override
998
	public Item addSimilarItem(long itemId, long catalogItemId) {
1013
	public Item addSimilarItem(long itemId, long catalogItemId) {
999
		try{
1014
		try{
1000
            CatalogClient catalogServiceClient = new CatalogClient();
1015
            CatalogClient catalogServiceClient = new CatalogClient();
1001
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1016
            Client catalogClient = catalogServiceClient.getClient();
1002
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1017
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1003
 
1018
 
1004
            return getItemFromThriftItem(thriftItem, null, null, null, null, null, null);
1019
            return getItemFromThriftItem(thriftItem, null, null, null, null, null, null);
1005
        }catch(Exception e){
1020
        }catch(Exception e){
1006
            logger.error("Error while adding the SimilarItems for: " + itemId, e);
1021
            logger.error("Error while adding the SimilarItems for: " + itemId, e);
Line 1012... Line 1027...
1012
	public Map<Long, ItemInventory> getProdItemInventory(long itemId) {
1027
	public Map<Long, ItemInventory> getProdItemInventory(long itemId) {
1013
		try {
1028
		try {
1014
            // Initialize client for production server
1029
            // Initialize client for production server
1015
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
1030
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
1016
                    ConfigClientKeys.catalog_service_server_port.toString());
1031
                    ConfigClientKeys.catalog_service_server_port.toString());
1017
            InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1032
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
-
 
1033
            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
1034
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1018
            in.shop2020.model.v1.catalog.ItemInventory thriftItemInventory = catalogClient_Prod.getItemInventoryByItemId(itemId);
1035
            in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(itemId);
1019
            
1036
            
1020
            Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1037
            Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1021
            ItemInventory warehousedata;
1038
            ItemInventory warehousedata;
1022
            if(thriftItemInventory != null) {
1039
            if(thriftItemInventory != null) {
1023
            	Map<Long, Long> availabilityMap = thriftItemInventory.getAvailability();
1040
            	Map<Long, Long> availabilityMap = thriftItemInventory.getAvailability();
Line 1042... Line 1059...
1042
 
1059
 
1043
	@Override
1060
	@Override
1044
	public boolean addAuthorizationLog(long itemId, String username, String message) {
1061
	public boolean addAuthorizationLog(long itemId, String username, String message) {
1045
		try{
1062
		try{
1046
            CatalogClient catalogServiceClient = new CatalogClient();
1063
            CatalogClient catalogServiceClient = new CatalogClient();
1047
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1064
            Client catalogClient = catalogServiceClient.getClient();
1048
 
1065
 
1049
            return catalogClient.addAuthorizationLog(itemId, username, message);
1066
            return catalogClient.addAuthorizationLog(itemId, username, message);
1050
 
1067
 
1051
        }catch(Exception e){
1068
        }catch(Exception e){
1052
            logger.error("Error while adding the event for: " + itemId, e);
1069
            logger.error("Error while adding the event for: " + itemId, e);
Line 1080... Line 1097...
1080
	public List<String> getAllCategories() {
1097
	public List<String> getAllCategories() {
1081
		List<String> categoryList = new ArrayList<String>();
1098
		List<String> categoryList = new ArrayList<String>();
1082
		List<Long> parentCategoryIDs = Arrays.asList(new Long[] {(long) 0,(long) 10001,(long) 10009,(long) 10049});
1099
		List<Long> parentCategoryIDs = Arrays.asList(new Long[] {(long) 0,(long) 10001,(long) 10009,(long) 10049});
1083
        try {
1100
        try {
1084
            CatalogClient catalogServiceClient = new CatalogClient();
1101
            CatalogClient catalogServiceClient = new CatalogClient();
1085
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1102
            Client catalogClient = catalogServiceClient.getClient();
1086
 
1103
 
1087
            List<in.shop2020.model.v1.catalog.Category> categories = catalogClient.getAllCategories();
1104
            List<in.shop2020.model.v1.catalog.Category> categories = catalogClient.getAllCategories();
1088
 
1105
 
1089
            for(in.shop2020.model.v1.catalog.Category category : categories) {
1106
            for(in.shop2020.model.v1.catalog.Category category : categories) {
1090
            	if(!parentCategoryIDs.contains(category.getParent_category_id())){
1107
            	if(!parentCategoryIDs.contains(category.getParent_category_id())){
Line 1103... Line 1120...
1103
	@Override
1120
	@Override
1104
	public List<String> getAllBrands() {
1121
	public List<String> getAllBrands() {
1105
		List<String> brandsList = new ArrayList<String>();
1122
		List<String> brandsList = new ArrayList<String>();
1106
        try {
1123
        try {
1107
            CatalogClient catalogServiceClient = new CatalogClient();
1124
            CatalogClient catalogServiceClient = new CatalogClient();
1108
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1125
            Client catalogClient = catalogServiceClient.getClient();
1109
 
1126
 
1110
            brandsList = catalogClient.getAllBrands();
1127
            brandsList = catalogClient.getAllBrands();
1111
        } catch (Exception e) {
1128
        } catch (Exception e) {
1112
            logger.error("Error while getting all the categories: ", e);
1129
            logger.error("Error while getting all the categories: ", e);
1113
        }
1130
        }
Line 1116... Line 1133...
1116
 
1133
 
1117
	@Override
1134
	@Override
1118
	public boolean deleteVoucher(Long catalogItemId, Long voucherType) {
1135
	public boolean deleteVoucher(Long catalogItemId, Long voucherType) {
1119
		try{
1136
		try{
1120
            CatalogClient catalogServiceClient = new CatalogClient();
1137
            CatalogClient catalogServiceClient = new CatalogClient();
1121
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1138
            Client catalogClient = catalogServiceClient.getClient();
1122
 
1139
 
1123
            return catalogClient.deleteVoucherForItem(catalogItemId, voucherType);
1140
            return catalogClient.deleteVoucherForItem(catalogItemId, voucherType);
1124
 
1141
 
1125
        }catch(Exception e){
1142
        }catch(Exception e){
1126
            logger.error("Error while deleting the Voucher for: " + catalogItemId, e);
1143
            logger.error("Error while deleting the Voucher for: " + catalogItemId, e);
Line 1130... Line 1147...
1130
 
1147
 
1131
	@Override
1148
	@Override
1132
	public boolean addVoucher(Long catalogItemId, Long voucherType, long voucherAmount) {
1149
	public boolean addVoucher(Long catalogItemId, Long voucherType, long voucherAmount) {
1133
		try{
1150
		try{
1134
            CatalogClient catalogServiceClient = new CatalogClient();
1151
            CatalogClient catalogServiceClient = new CatalogClient();
1135
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1152
            Client catalogClient = catalogServiceClient.getClient();
1136
 
1153
 
1137
            return catalogClient.addupdateVoucherForItem(catalogItemId, voucherType, voucherAmount);
1154
            return catalogClient.addupdateVoucherForItem(catalogItemId, voucherType, voucherAmount);
1138
 
1155
 
1139
        }catch(Exception e){
1156
        }catch(Exception e){
1140
            logger.error("Error while adding the Voucher for: " + catalogItemId, e);
1157
            logger.error("Error while adding the Voucher for: " + catalogItemId, e);
Line 1167... Line 1184...
1167
 
1184
 
1168
	@Override
1185
	@Override
1169
	public boolean checkEntityId(long entityId) {
1186
	public boolean checkEntityId(long entityId) {
1170
		try {
1187
		try {
1171
            CatalogClient catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_master.toString(), ConfigClientKeys.catalog_service_server_port.toString());
1188
            CatalogClient catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_master.toString(), ConfigClientKeys.catalog_service_server_port.toString());
1172
            InventoryService.Client catalogClient = catalogServiceClient.getClient();
1189
            Client catalogClient = catalogServiceClient.getClient();
1173
            return catalogClient.isValidCatalogItemId(entityId);
1190
            return catalogClient.isValidCatalogItemId(entityId);
1174
        } catch (Exception e) {
1191
        } catch (Exception e) {
1175
            logger.error("Error while checking for a Catalog Item Id: ", e);
1192
            logger.error("Error while checking for a Catalog Item Id: ", e);
1176
        }
1193
        }
1177
		return false;
1194
		return false;