Subversion Repositories SmartDukaan

Rev

Rev 6759 | Rev 6813 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1961 ankur.sing 1
package in.shop2020.catalog.dashboard.server;
2
 
3
import in.shop2020.catalog.dashboard.client.CatalogService;
6530 vikram.rag 4
 
1961 ankur.sing 5
import in.shop2020.catalog.dashboard.shared.Item;
4431 phani.kuma 6
import in.shop2020.catalog.dashboard.shared.ItemInventory;
3850 chandransh 7
import in.shop2020.catalog.dashboard.shared.ItemStatus;
2068 ankur.sing 8
import in.shop2020.catalog.dashboard.shared.ItemsComparator;
3558 rajveer 9
import in.shop2020.catalog.dashboard.shared.SourcePricings;
2119 ankur.sing 10
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
11
import in.shop2020.catalog.dashboard.shared.VendorPricings;
5504 phani.kuma 12
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
2378 ankur.sing 13
import in.shop2020.config.ConfigException;
3907 chandransh 14
import in.shop2020.content.ContentService;
15
import in.shop2020.content.ContentServiceException;
5946 rajveer 16
import in.shop2020.model.v1.catalog.CatalogService.Client;
5706 amit.gupta 17
import in.shop2020.model.v1.catalog.ItemType;
2105 ankur.sing 18
import in.shop2020.model.v1.catalog.status;
6096 amit.gupta 19
import in.shop2020.model.v1.inventory.InventoryService;
5504 phani.kuma 20
import in.shop2020.model.v1.user.VoucherType;
3129 rajveer 21
import in.shop2020.thrift.clients.CatalogClient;
3907 chandransh 22
import in.shop2020.thrift.clients.ContentClient;
5946 rajveer 23
import in.shop2020.thrift.clients.InventoryClient;
2378 ankur.sing 24
import in.shop2020.thrift.clients.config.ConfigClient;
2119 ankur.sing 25
import in.shop2020.utils.CategoryManager;
2359 ankur.sing 26
import in.shop2020.utils.ConfigClientKeys;
6530 vikram.rag 27
import in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems;
28
import in.shop2020.catalog.dashboard.shared.ItemWarehouse;
2427 ankur.sing 29
import java.io.BufferedReader;
30
import java.io.FileReader;
2359 ankur.sing 31
import java.io.IOException;
2427 ankur.sing 32
import java.text.DateFormat;
33
import java.text.SimpleDateFormat;
1961 ankur.sing 34
import java.util.ArrayList;
4957 phani.kuma 35
import java.util.Arrays;
2105 ankur.sing 36
import java.util.Calendar;
2068 ankur.sing 37
import java.util.Collections;
2427 ankur.sing 38
import java.util.Date;
1992 ankur.sing 39
import java.util.HashMap;
5118 mandeep.dh 40
import java.util.HashSet;
1961 ankur.sing 41
import java.util.List;
1992 ankur.sing 42
import java.util.Map;
2359 ankur.sing 43
import java.util.Map.Entry;
5118 mandeep.dh 44
import java.util.Set;
1961 ankur.sing 45
 
2427 ankur.sing 46
import org.apache.log4j.Logger;
3907 chandransh 47
import org.apache.thrift.TException;
48
import org.apache.thrift.transport.TTransportException;
2359 ankur.sing 49
 
1961 ankur.sing 50
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
51
 
52
@SuppressWarnings("serial")
53
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
54
 
3354 chandransh 55
    private static Logger logger = Logger.getLogger(CatalogServiceImpl.class);
56
 
3922 chandransh 57
    private static Logger pushToProdLogger = Logger.getLogger("pushToProdLogger");
58
 
2427 ankur.sing 59
    private static Date pushToProdDate;
60
 
3922 chandransh 61
    private static String logFile;
62
 
63
    private static int maxCount;
64
 
65
    static {
66
        try {
67
            logFile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
68
            maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));    
69
        } catch(ConfigException ce) {
70
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
71
            logFile = "/var/log/services/pushToProductionCount/pushToProd.log";
72
            maxCount = 5;
73
        }
74
 
75
    }
76
 
3850 chandransh 77
    @Override
78
    public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
79
        int count = 0;
80
        try{
81
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 82
            Client catalogClient = catalogServiceClient.getClient();
3850 chandransh 83
 
84
            status stat = status.findByValue(itemStatus.getValue());
85
            count = catalogClient.getItemCountByStatus(useStatus, stat);
86
        }catch(Exception e){
87
            logger.error("Error while getting the count of items from the catalog service", e);
88
        }
89
        return count;
90
    }
91
 
92
    @Override
6530 vikram.rag 93
	public List<Item> getInventoryOutofSyncItems(int offset, int limit){
94
        List<Item> itemList = new ArrayList<Item>();
95
 
96
        try {
97
            CatalogClient catalogServiceClient = new CatalogClient();
98
            Client catalogClient = catalogServiceClient.getClient();
99
 
100
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllIgnoredInventoryUpdateItemsList(offset, limit);
101
 
102
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
103
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
104
            }
105
        } catch (Exception e) {
106
            logger.error("Error while getting all items from the catalog service", e);
107
        }
108
        return itemList;
109
    }
110
 
111
    @Override
112
    public int getInventoryOutofSyncItemsCount(){
113
	int count=0;
114
    	try {
115
            InventoryClient inventoryServiceClient = new InventoryClient();
116
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
117
 
118
            count = inventoryClient.getAllIgnoredInventoryupdateItemsCount();
119
 
120
            } catch (Exception e) {
121
            logger.error("Error while getting all items from the catalog service", e);
122
        }
123
    	return count;	
124
    }    
125
 
126
    @Override
3850 chandransh 127
    public List<Item> getAllItems(int start, int limit) {
1961 ankur.sing 128
        List<Item> itemList = new ArrayList<Item>();
2359 ankur.sing 129
 
1961 ankur.sing 130
        try {
3129 rajveer 131
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 132
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 133
 
3850 chandransh 134
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
2359 ankur.sing 135
 
2119 ankur.sing 136
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5504 phani.kuma 137
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
2119 ankur.sing 138
            }
139
        } catch (Exception e) {
3354 chandransh 140
            logger.error("Error while getting all items from the catalog service", e);
2119 ankur.sing 141
        }
142
        return itemList;
143
    }
2208 ankur.sing 144
 
3850 chandransh 145
    public List<Item> getAllActiveItems(int start, int limit){
146
        return getItemsByStatus(status.ACTIVE, start, limit);
2208 ankur.sing 147
    }
2359 ankur.sing 148
 
149
    @Override
3850 chandransh 150
    public List<Item> getAllPhasedOutItems(int start, int limit){
151
        return getItemsByStatus(status.PHASED_OUT, start, limit);
2359 ankur.sing 152
    }
153
 
154
    @Override
3850 chandransh 155
    public List<Item> getAllPausedItems(int start, int limit){
156
        return getItemsByStatus(status.PAUSED, start, limit);
2208 ankur.sing 157
    }
2359 ankur.sing 158
 
159
    @Override
3850 chandransh 160
    public List<Item> getAllInProcessItems(int start, int limit) {
161
        return getItemsByStatus(status.IN_PROCESS, start, limit);
2359 ankur.sing 162
    }
163
 
164
    @Override
3850 chandransh 165
    public List<Item> getAllContentCompleteItems(int start, int limit) {
166
        return getItemsByStatus(status.CONTENT_COMPLETE, start, limit);
2359 ankur.sing 167
    }
168
 
169
    public List<Item> getBestDeals(){
2119 ankur.sing 170
        List<Item> itemList = new ArrayList<Item>();
171
        try {
3129 rajveer 172
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 173
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 174
 
175
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
1992 ankur.sing 176
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5504 phani.kuma 177
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
1992 ankur.sing 178
            }
2359 ankur.sing 179
        } catch(Exception e){
3354 chandransh 180
            logger.error("Error while getting the best deals from the catalog service", e);
1961 ankur.sing 181
        }
2562 chandransh 182
        //Collections.sort(itemList, new ItemsComparator());
1961 ankur.sing 183
        return itemList;
184
    }
185
 
2359 ankur.sing 186
    @Override
187
    public List<Item> getRiskyItems() {
1961 ankur.sing 188
        List<Item> itemList = new ArrayList<Item>();
189
        try {
3129 rajveer 190
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 191
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 192
 
193
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
1992 ankur.sing 194
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5504 phani.kuma 195
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
1992 ankur.sing 196
            }
1961 ankur.sing 197
        } catch(Exception e){
3354 chandransh 198
            logger.error("Error while getting the risky items from the catalog service", e);
1961 ankur.sing 199
        }
2068 ankur.sing 200
        Collections.sort(itemList, new ItemsComparator());
1961 ankur.sing 201
        return itemList;
202
    }
2359 ankur.sing 203
 
1961 ankur.sing 204
    public List<Item> getBestSellers(){
205
        List<Item> itemList = new ArrayList<Item>();
2359 ankur.sing 206
 
1961 ankur.sing 207
        try {
3129 rajveer 208
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 209
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 210
 
1961 ankur.sing 211
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
1992 ankur.sing 212
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5504 phani.kuma 213
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
1992 ankur.sing 214
            }
1961 ankur.sing 215
        } catch(Exception e){
3354 chandransh 216
            logger.error("Error while getting the best sellers from the catalog service", e);
1961 ankur.sing 217
        }
218
        return itemList;        
219
    }
6530 vikram.rag 220
 
221
    @Override
222
    public boolean addtoIgnoredInventoryUpdateItemsIdsWarehouseIds(long itemId,long warehouseId){
223
    	try {
224
				InventoryClient inventoryServiceClient = new InventoryClient();
225
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
226
				return inventoryClient.insertItemtoIgnoreInventoryUpdatelist(itemId, warehouseId);
227
			} catch (Exception e) {
228
            logger.error("Error while inserting item to ignore inventory update list", e);
229
            }
230
			return false;
231
    }
232
 
233
    @Override
234
    public boolean deleteFromIgnoredInventoryUpdateItemsIdsWarehouseIds(long itemId,long warehouseId){
235
    	try {
236
    			InventoryClient inventoryServiceClient = new InventoryClient();
237
    			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
238
    			return inventoryClient.deleteItemFromIgnoredInventoryUpdateList(itemId,warehouseId);
239
 
240
		} catch (Exception e) {
6532 amit.gupta 241
			logger.error("Error while inserting item to ignore inventory update list", e);
6530 vikram.rag 242
        }
243
		return false;
244
}
2359 ankur.sing 245
 
6530 vikram.rag 246
 
247
 
3872 chandransh 248
    @Override
1961 ankur.sing 249
    public List<Item> getLatestArrivals(){
250
        List<Item> itemList = new ArrayList<Item>();
2359 ankur.sing 251
 
1961 ankur.sing 252
        try {
3129 rajveer 253
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 254
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 255
 
1961 ankur.sing 256
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
1992 ankur.sing 257
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5946 rajveer 258
                //List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
5504 phani.kuma 259
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
1992 ankur.sing 260
            }
1961 ankur.sing 261
        } catch(Exception e){
3354 chandransh 262
            logger.error("Error while getting the latest arrivals from the catalog service", e);
1961 ankur.sing 263
        }
264
        return itemList;
265
    }
2359 ankur.sing 266
 
3872 chandransh 267
    @Override
268
    public List<Item> searchItems(int start, int limit, List<String> searchTerms) {
269
        List<Item> itemList = new ArrayList<Item>();
270
 
271
        try {
272
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 273
            Client catalogClient = catalogServiceClient.getClient();
3872 chandransh 274
 
275
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
276
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5504 phani.kuma 277
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
3872 chandransh 278
            }
279
        } catch(Exception e){
280
            logger.error("Error while getting the search results from the catalog service", e);
281
        }
282
        return itemList;
283
    }
284
 
285
    @Override
286
    public int getSearchResultCount(List<String> searchTerms){
287
        int count = 0;
288
        try {
289
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 290
            Client catalogClient = catalogServiceClient.getClient();
3872 chandransh 291
 
292
            count = catalogClient.getSearchResultCount(searchTerms);
293
        } catch(Exception e){
294
            logger.error("Error while getting the search results from the catalog service", e);
295
        }
296
 
297
        return count;
298
    }
299
 
1961 ankur.sing 300
    public Item getItem(long itemId){
301
        try{
3129 rajveer 302
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 303
            Client catalogClient = catalogServiceClient.getClient();
304
            InventoryClient inventoryServiceClient = new InventoryClient();
305
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1961 ankur.sing 306
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
5427 amit.gupta 307
            Long catalogItemId = thriftItem.getCatalogItemId();
308
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByCatalogId(catalogItemId);
309
            List <Long> sameItemsWithDifferentColors = new ArrayList<Long>();
310
            if(thriftItems.size()>1){
311
	            for(in.shop2020.model.v1.catalog.Item tItem : thriftItems ){
312
	            	Long id = tItem.getId();
313
		        	if(!id.equals(itemId)){
314
		        		sameItemsWithDifferentColors.add(id); 
315
		        	}
316
	            }
317
            }
5946 rajveer 318
            List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
319
            List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
3558 rajveer 320
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
4423 phani.kuma 321
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
5946 rajveer 322
            in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
5504 phani.kuma 323
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
324
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers);
5427 amit.gupta 325
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
326
            return it;
1961 ankur.sing 327
        }catch(Exception e){
3354 chandransh 328
            logger.error("Error while getting the item from the catalog service", e);
1961 ankur.sing 329
        }
330
        return null;
331
    }
2359 ankur.sing 332
 
1961 ankur.sing 333
    @Override
1992 ankur.sing 334
    public boolean updateItem(Item item) {
3354 chandransh 335
        logger.info("Updating item with Id: " + item.getId());
1961 ankur.sing 336
        try{
3129 rajveer 337
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 338
            Client catalogClient = catalogServiceClient.getClient();
339
            InventoryClient inventoryServiceClient = new InventoryClient();
340
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
341
 
1992 ankur.sing 342
            in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
2126 ankur.sing 343
            setThriftItemParams(tItem, item);
2359 ankur.sing 344
 
2105 ankur.sing 345
            long rItemId;
346
            if((rItemId = catalogClient.updateItem(tItem)) != item.getId()) {
3354 chandransh 347
                logger.error("Error updating item, returned Item Id: " + rItemId);
2105 ankur.sing 348
                return false;
349
            }
3354 chandransh 350
            logger.info("Successfully updated item with id: " + item.getId());
2359 ankur.sing 351
 
352
            Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();
2119 ankur.sing 353
            if(vendorMappings != null && !vendorMappings.isEmpty()) {
5946 rajveer 354
                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
2359 ankur.sing 355
 
356
                for(Entry<String, VendorItemMapping> e : vendorMappings.entrySet()) {
5946 rajveer 357
                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
2359 ankur.sing 358
                    VendorItemMapping v = e.getValue();
2119 ankur.sing 359
                    tVendorMapping.setVendorId(v.getVendorId());
360
                    tVendorMapping.setItemKey(v.getItemKey());
361
                    tVendorMapping.setItemId(item.getId());
5946 rajveer 362
                    inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
3354 chandransh 363
                    logger.info("Updates VendorItemMapping: " + tVendorMapping.toString());
2119 ankur.sing 364
                }
365
            }
2359 ankur.sing 366
 
2119 ankur.sing 367
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
368
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
5946 rajveer 369
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
2119 ankur.sing 370
                for(VendorPricings v : vendorPricings.values()) {
5946 rajveer 371
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
2105 ankur.sing 372
                    tVendorPricing.setVendorId(v.getVendorId());
373
                    tVendorPricing.setItemId(item.getId());
374
                    tVendorPricing.setMop(v.getMop());
375
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
376
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
6759 amar.kumar 377
                    tVendorPricing.setNlc(v.getNlc());
5946 rajveer 378
                    inventoryClient.addVendorItemPricing(tVendorPricing);
3354 chandransh 379
                    logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
2105 ankur.sing 380
                }
381
            }
3558 rajveer 382
 
383
            Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
384
            if(sourcePricings != null && !sourcePricings.isEmpty()) {
385
                in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricings;
386
                for(SourcePricings s : sourcePricings.values()) {
387
                	tSourcePricings = new in.shop2020.model.v1.catalog.SourceItemPricing();
388
                	tSourcePricings.setSourceId(s.getSourceId());
389
                    tSourcePricings.setItemId(item.getId());
390
                    tSourcePricings.setMrp(s.getMrp());
391
                    tSourcePricings.setSellingPrice(s.getSellingPrice());
392
                    catalogClient.addSourceItemPricing(tSourcePricings);
393
                    logger.info("Updated SourceItemPricing: " + tSourcePricings.toString());
394
                }
395
            }
396
 
2105 ankur.sing 397
        }catch(Exception e){
3354 chandransh 398
            logger.error("Error while updating item: ", e);
2427 ankur.sing 399
            return false;
2105 ankur.sing 400
        }
401
        return true;
1961 ankur.sing 402
    }
2359 ankur.sing 403
 
6530 vikram.rag 404
    @Override
405
    public List<Long> getMonitoredWarehouseIdsForVendors(List<Long> vendorIds){
406
    	List<Long> monitoredWarehouseids=null;
407
    	 try {
408
			InventoryClient inventoryServiceClient = new InventoryClient();
409
			 in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
410
			 monitoredWarehouseids = inventoryClient.getMonitoredWarehouseForVendors(vendorIds);
411
		} catch (Exception e) {
412
			logger.error("Error while getting Monitored warehouse for vendor: ", e);
413
		}
414
		return monitoredWarehouseids;
415
 
416
    }
417
 
418
    @Override
419
    public List<ItemWarehouse> getignoredInventoryUpdateItemsIdsWarehouseIds(){
420
		List<ItemWarehouse> ignoredItemIdwarehouseIdList = new ArrayList<ItemWarehouse>();
421
    	try {
2359 ankur.sing 422
 
6530 vikram.rag 423
			InventoryClient inventoryServiceClient = new InventoryClient();
424
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
425
			List<IgnoredInventoryUpdateItems> ignoredInventoryUpdateItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
426
			for(IgnoredInventoryUpdateItems ignoredInventoryUpdateItem:ignoredInventoryUpdateItems){
427
				ignoredItemIdwarehouseIdList.add(new ItemWarehouse(ignoredInventoryUpdateItem.getItemId(),ignoredInventoryUpdateItem.getWarehouseId()));
428
			}
429
 
430
 
431
		} catch (Exception e) {
432
			logger.error("Error while getting Monitored warehouseid and itemid : ", e);
433
		}
434
		return ignoredItemIdwarehouseIdList;
435
 
436
    }
2066 ankur.sing 437
    @Override
438
    public Map<Long, String> getAllVendors() {
439
        Map<Long, String> vendorMap = new HashMap<Long, String>();
440
        try {
5946 rajveer 441
            InventoryClient inventoryServiceClient = new InventoryClient();
442
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
443
 
444
            List<in.shop2020.model.v1.inventory.Vendor> vendors = inventoryClient.getAllVendors();
2359 ankur.sing 445
 
5946 rajveer 446
            for(in.shop2020.model.v1.inventory.Vendor v : vendors) {
2066 ankur.sing 447
                vendorMap.put(v.getId(), v.getName());
448
            }
449
        } catch (Exception e) {
3354 chandransh 450
            logger.error("Error while getting all the vendors: ", e);
2066 ankur.sing 451
        }
452
        return vendorMap;
453
    }
454
 
455
    @Override
3558 rajveer 456
    public Map<Long, String> getAllSources() {
457
        Map<Long, String> sourceMap = new HashMap<Long, String>();
458
        try {
459
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 460
            Client catalogClient = catalogServiceClient.getClient();
3558 rajveer 461
 
462
            List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
463
 
464
            for(in.shop2020.model.v1.catalog.Source s : sources) {
465
            	sourceMap.put(s.getId(), s.getName());
466
            }
467
        } catch (Exception e) {
468
            logger.error("Error while getting all the vendors: ", e);
469
        }
470
        return sourceMap;
471
    }
472
 
473
    @Override
5118 mandeep.dh 474
    public Map<Long, String> getShippingWarehouses() {
475
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
476
        Set<Long> shippingLocations = new HashSet<Long>();
477
        try {
5946 rajveer 478
            InventoryClient inventoryServiceClient = new InventoryClient();
479
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
480
 
481
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
5118 mandeep.dh 482
 
5946 rajveer 483
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
5118 mandeep.dh 484
                shippingLocations.add(warehouse.getShippingWarehouseId());
485
            }
486
 
5946 rajveer 487
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
5118 mandeep.dh 488
                if (shippingLocations.contains(warehouse.getId())) {
489
                    warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
490
                }                
491
            }
492
        } catch (Exception e) {
493
            logger.error("Error while getting all the warehouses:", e );
494
        }
495
        return warehouseMap;
496
    }
497
 
498
    @Override
2066 ankur.sing 499
    public Map<Long, String> getAllWarehouses() {
500
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
501
        try {
5946 rajveer 502
        	InventoryClient inventoryServiceClient = new InventoryClient();
503
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
2359 ankur.sing 504
 
5946 rajveer 505
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
2359 ankur.sing 506
 
5946 rajveer 507
            for(in.shop2020.model.v1.inventory.Warehouse w : warehouses) {
2066 ankur.sing 508
                warehouseMap.put(w.getId(), w.getDisplayName());
509
            }
510
        } catch (Exception e) {
3354 chandransh 511
            logger.error("Error while getting all the warehouses:", e );
2066 ankur.sing 512
        }
513
        return warehouseMap;
514
    }
2105 ankur.sing 515
 
516
    @Override
517
    public long addItem(Item item) {
518
        long itemId = 0;
519
        try {
3129 rajveer 520
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 521
            Client catalogClient = catalogServiceClient.getClient();
522
            InventoryClient inventoryServiceClient = new InventoryClient();
523
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
2126 ankur.sing 524
 
2105 ankur.sing 525
            in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
2126 ankur.sing 526
            setThriftItemParams(tItem, item);
2105 ankur.sing 527
            itemId = catalogClient.addItem(tItem);
528
 
2119 ankur.sing 529
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
530
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
5946 rajveer 531
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
2119 ankur.sing 532
                for(VendorPricings v : vendorPricings.values()) {
5946 rajveer 533
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
2119 ankur.sing 534
                    tVendorPricing.setVendorId(v.getVendorId());
535
                    tVendorPricing.setItemId(itemId);
536
                    tVendorPricing.setMop(v.getMop());
537
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
6759 amar.kumar 538
                    tVendorPricing.setNlc(v.getNlc());
2119 ankur.sing 539
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
5946 rajveer 540
                    inventoryClient.addVendorItemPricing(tVendorPricing);
2119 ankur.sing 541
                }
542
            }
2359 ankur.sing 543
 
544
            Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();
2119 ankur.sing 545
            if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
5946 rajveer 546
                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
2359 ankur.sing 547
                for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {
5946 rajveer 548
                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
2359 ankur.sing 549
                    VendorItemMapping v = e.getValue();
2105 ankur.sing 550
                    tVendorMapping.setVendorId(v.getVendorId());
551
                    tVendorMapping.setItemKey(v.getItemKey());
552
                    tVendorMapping.setItemId(itemId);
5946 rajveer 553
                    inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
2105 ankur.sing 554
                }
555
            }
556
        } catch (Exception e) {
3354 chandransh 557
            logger.error("Error while adding an item: ", e);
2105 ankur.sing 558
        }
559
        return itemId;
560
    }
2119 ankur.sing 561
 
562
    @Override
4725 phani.kuma 563
    public long checkSimilarItem(String brand, String modelNumber, String modelName, String color) {
2359 ankur.sing 564
 
2119 ankur.sing 565
        try {
3129 rajveer 566
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 567
            Client catalogClient = catalogServiceClient.getClient();
4725 phani.kuma 568
            return catalogClient.checkSimilarItem(brand, modelNumber, modelName, color);
2119 ankur.sing 569
        } catch (Exception e) {
3354 chandransh 570
            logger.error("Error while checking for a similar item: ", e);
2119 ankur.sing 571
        }
572
        return 0;
573
    }
2359 ankur.sing 574
 
2126 ankur.sing 575
    private void setThriftItemParams(in.shop2020.model.v1.catalog.Item tItem, Item item) {
576
        tItem.setId(tItem.getId());
577
        tItem.setProductGroup(item.getProductGroup());
578
        tItem.setBrand(item.getBrand());
579
        tItem.setModelName(item.getModelName());
580
        tItem.setModelNumber(item.getModelNumber());
581
        tItem.setColor(item.getColor());
6241 amit.gupta 582
        tItem.setShowSellingPrice(item.isShowSellingPrice());
2359 ankur.sing 583
        tItem.setStatus_description(item.getItemStatusDesc());
2126 ankur.sing 584
        tItem.setComments(item.getComments());
2359 ankur.sing 585
 
2489 ankur.sing 586
        if(item.getMrp() != null) {
2126 ankur.sing 587
            tItem.setMrp(item.getMrp());
588
        }
3354 chandransh 589
 
5586 phani.kuma 590
        if(item.getCatalogItemId() != null) {
591
            tItem.setCatalogItemId(item.getCatalogItemId());
592
        }
593
 
2489 ankur.sing 594
        if(item.getSellingPrice() != null) {
2126 ankur.sing 595
            tItem.setSellingPrice(item.getSellingPrice());
596
        }
3354 chandransh 597
 
2489 ankur.sing 598
        if(item.getWeight() != null) {
2126 ankur.sing 599
            tItem.setWeight(item.getWeight());
600
        }
3354 chandransh 601
 
3359 chandransh 602
        if(item.getExpectedDelay() != null) {
603
            tItem.setExpectedDelay(item.getExpectedDelay());
2489 ankur.sing 604
        }
3354 chandransh 605
 
4413 anupam.sin 606
        tItem.setIsWarehousePreferenceSticky(item.isWarehouseStickiness());
607
 
4506 phani.kuma 608
        if(item.getPreferredVendor() != null) {
609
            tItem.setPreferredVendor(item.getPreferredVendor());
610
        }
611
 
2126 ankur.sing 612
        tItem.setBestDealText(item.getBestDealsText());
6777 vikram.rag 613
        tItem.setBestDealsDetailsText(item.getBestDealsDetailsText());
614
        tItem.setBestDealsDetailsLink(item.getBestDealsDetailsLink());
2489 ankur.sing 615
        if(item.getBestDealsValue() != null) {
2126 ankur.sing 616
            tItem.setBestDealValue(item.getBestDealsValue());
617
        }
3354 chandransh 618
 
2489 ankur.sing 619
        if(item.getBestSellingRank() != null) {
2126 ankur.sing 620
            tItem.setBestSellingRank(item.getBestSellingRank());
621
        }
3354 chandransh 622
 
2126 ankur.sing 623
        tItem.setDefaultForEntity(item.isDefaultForEntity());
2252 ankur.sing 624
        tItem.setRisky(item.isRisky());
5384 phani.kuma 625
        tItem.setHasItemNo(item.isHasItemNo());
5460 phani.kuma 626
        tItem.setClearance(item.isClearance());
5384 phani.kuma 627
 
628
        if(item.isItemType()) {
629
        	tItem.setType(ItemType.SERIALIZED);
630
        }
631
        else {
632
        	tItem.setType(ItemType.NON_SERIALIZED);
633
        }
634
 
2489 ankur.sing 635
        if(item.getStartDate() != null) {
636
            tItem.setStartDate(item.getStartDate());
637
        }
3354 chandransh 638
 
5217 amit.gupta 639
        if(item.getExpectedArrivalDate() != null) {
640
        	tItem.setExpectedArrivalDate(item.getExpectedArrivalDate());
641
        } else {
642
        	tItem.unsetComingSoonStartDate();
643
        	tItem.unsetExpectedArrivalDate();
644
        	if(status.COMING_SOON.equals(tItem.getItemStatus())){
6277 amit.gupta 645
        		tItem.setItemStatus(status.CONTENT_COMPLETE);
646
        		tItem.setStatus_description("Content generation completed");
5217 amit.gupta 647
        	}
648
        }
649
 
650
        if(item.getComingSoonStartDate() != null) {
651
        	tItem.setComingSoonStartDate(item.getComingSoonStartDate());
652
        } else {
653
        	tItem.unsetComingSoonStartDate();
654
        }
655
 
2489 ankur.sing 656
        if(item.getRetireDate() != null) {
657
            tItem.setRetireDate(item.getRetireDate());
658
        }
3354 chandransh 659
 
2126 ankur.sing 660
        tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());
661
    }
662
 
663
    @Override
664
    public void pauseItem(long itemId) {
665
        try {
3129 rajveer 666
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 667
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 668
 
2126 ankur.sing 669
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
670
        } catch (Exception e) {
3354 chandransh 671
            logger.error("Error while pausing the item: " + itemId, e);
2126 ankur.sing 672
        }
2359 ankur.sing 673
 
2126 ankur.sing 674
    }
675
 
676
    @Override
677
    public void markInProcess(long itemId) {
678
        try {
3129 rajveer 679
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 680
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 681
 
2126 ankur.sing 682
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
683
        } catch (Exception e) {
3354 chandransh 684
            logger.error("Error while marking in-process the item: " + itemId, e);
2126 ankur.sing 685
        }
686
    }
2359 ankur.sing 687
 
2126 ankur.sing 688
    @Override
689
    public void phaseoutItem(long itemId) {
690
        try {
3129 rajveer 691
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 692
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 693
 
2126 ankur.sing 694
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
695
        } catch (Exception e) {
3354 chandransh 696
            logger.error("Error while phasing out the item: " + itemId, e);
2126 ankur.sing 697
        }
698
    }
2359 ankur.sing 699
 
2126 ankur.sing 700
    @Override
701
    public void activateItem(long itemId) {
702
        try {
3129 rajveer 703
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 704
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 705
 
2126 ankur.sing 706
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
707
        } catch (Exception e) {
3354 chandransh 708
            logger.error("Error while activating the item: " + itemId, e);
2126 ankur.sing 709
        }
710
    }
2359 ankur.sing 711
 
712
    @Override
713
    public boolean changeItemRiskyFlag(long itemId, boolean risky) {
714
        try {
4354 mandeep.dh 715
            logger.info("Updating risky flag for item id: " + itemId + " to " + risky);
2359 ankur.sing 716
            // Initialize client for staging server
3129 rajveer 717
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 718
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 719
 
720
            // Initialize client for production server
3165 chandransh 721
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
2359 ankur.sing 722
                    ConfigClientKeys.catalog_service_server_port.toString());
5946 rajveer 723
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
2359 ankur.sing 724
            catalogClient.changeItemRiskyFlag(itemId, risky);
725
 
726
            try{
727
                catalogClient_Prod.changeItemRiskyFlag(itemId, risky);
728
            }catch(Exception e){
3354 chandransh 729
                logger.error("Error while updating item's risky flag on production", e);
2359 ankur.sing 730
                // If not able to change risky flag on production, revert on staging and return false (to show error to user).
731
                catalogClient.changeItemRiskyFlag(itemId, !risky);        
732
                return false;
733
            }
734
        } catch (Exception e) {
3354 chandransh 735
            logger.error("Error while updating item's risky flag on staging", e);
2359 ankur.sing 736
            return false;
737
        }
738
        return true;
739
    }
740
 
2427 ankur.sing 741
 
742
    /**
4762 phani.kuma 743
     * Retuns list of Items filtered by category (column is product_group in catalog.item table)
2427 ankur.sing 744
     * This list is used to generate master sheet (excel sheet)
745
     * @param category
4957 phani.kuma 746
     * @param brand
2427 ankur.sing 747
     * @return
748
     */
4957 phani.kuma 749
    public List<Item> getItemsForMasterSheet(String category, String brand) {
2359 ankur.sing 750
        List<Item> itemList = new ArrayList<Item>();
751
        try {
3129 rajveer 752
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 753
            Client catalogClient = catalogServiceClient.getClient();
754
            InventoryClient inventoryServiceClient = new InventoryClient();
755
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
2359 ankur.sing 756
 
4957 phani.kuma 757
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsForMasterSheet(category, brand);
2359 ankur.sing 758
 
759
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5946 rajveer 760
                List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
761
                List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
3558 rajveer 762
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
5504 phani.kuma 763
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
2359 ankur.sing 764
            }
765
        } catch (Exception e) {
4762 phani.kuma 766
            logger.error("Error while getting items by category: " + category, e);
2359 ankur.sing 767
        }
768
        Collections.sort(itemList, new ItemsComparator());
769
        return itemList;
770
    }
771
 
772
    @Override
2427 ankur.sing 773
    public String updateItemOnProduction(Item item) {
5706 amit.gupta 774
    	if(!canPushToProduction()) {
775
    		// If we can't push to production, then return that message to user
776
    		// else move forward with update.
777
    		return "Maximum push to production count reached for today";
778
    	}
779
    	List<Long> itemIds = item.getSameItemsWithDifferentColors();
780
    	List<Item> items = new ArrayList<Item>();
781
    	items.add(item);
782
    	for(Long itemId : itemIds) {
783
    		try {
784
    			CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 785
    			Client catalogClient = catalogServiceClient.getClient();
786
    			InventoryClient inventoryServiceClient = new InventoryClient();
787
                in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
788
 
5706 amit.gupta 789
    			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
5946 rajveer 790
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
791
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
5706 amit.gupta 792
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
793
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
794
    		} catch (Exception e) {
795
    			logger.error("Could not fetch item for : " + itemId, e);
796
    			return "Could not push to production. No item got pushed.";
797
    		}
798
    	}
799
    	for (Item it : items) {
800
	        logger.info("Update item on production call, Item Id: " + it.getId());
801
 
802
	        try{
803
	            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
804
	                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
805
	                    ConfigClientKeys.catalog_service_server_port.toString());
806
 
5946 rajveer 807
	            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
5706 amit.gupta 808
 
809
	            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(it.getId());
810
 
5946 rajveer 811
	            InventoryClient inventoryServiceClient = new InventoryClient();
812
	            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
813
 
5706 amit.gupta 814
	            if(it.getMrp() != null) {
815
	                tItem.setMrp(it.getMrp());
816
	            }
817
 
818
	            if(it.getSellingPrice() != null) {
819
	                tItem.setSellingPrice(it.getSellingPrice());
820
	            }
821
 
822
	            long rItemId;
823
	            if((rItemId = catalogClient_Prod.updateItem(tItem)) != it.getId()) {
824
	                logger.error("Error updating item on production, returned Item Id: " + rItemId);
825
	                return "Error updating item prices on production";
826
	            }
827
	            logger.info("Successfully updated item: " + it.getId());
828
 
829
	            StringBuilder sb = new StringBuilder();
830
 
831
	            Map<Long, VendorPricings> vendorPricings = it.getVendorPricesMap();
832
	            if(vendorPricings != null && !vendorPricings.isEmpty()) {
5946 rajveer 833
	                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
5706 amit.gupta 834
	                for(VendorPricings v : vendorPricings.values()) {
5946 rajveer 835
	                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
5706 amit.gupta 836
	                    tVendorPricing.setVendorId(v.getVendorId());
837
	                    tVendorPricing.setItemId(it.getId());
838
	                    tVendorPricing.setMop(v.getMop());
839
	                    tVendorPricing.setTransferPrice(v.getTransferPrice());
6759 amar.kumar 840
	                    tVendorPricing.setNlc(v.getNlc());
5706 amit.gupta 841
	                    tVendorPricing.setDealerPrice(v.getDealerPrice());
5946 rajveer 842
	                    inventoryClient.addVendorItemPricing(tVendorPricing);
5706 amit.gupta 843
	                    logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
6759 amar.kumar 844
	                    sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",NLC= " +v.getNlc() + ",DP=" + v.getDealerPrice() + "], ");
5706 amit.gupta 845
	                }
846
	            }
847
 
848
	            Map<String, VendorItemMapping> vendorMappings = it.getVendorKeysMap();
849
	            if(vendorMappings != null && !vendorMappings.isEmpty()) {
5946 rajveer 850
	                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
5706 amit.gupta 851
	                for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
5946 rajveer 852
	                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
5706 amit.gupta 853
	                    tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
854
	                    tVendorMapping.setItemId(it.getId());
855
	                    tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
5946 rajveer 856
	                    inventoryClient.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
5706 amit.gupta 857
	                    logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
858
	                    sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
859
	                }
860
	            }
861
 
862
	            Map<Long, SourcePricings> sourcePricings = it.getSourcePricesMap();
863
	            if(sourcePricings != null && !sourcePricings.isEmpty()){
864
	                in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricing;
865
	                for(SourcePricings s : sourcePricings.values()){
866
	                    tSourcePricing = new in.shop2020.model.v1.catalog.SourceItemPricing();
867
	                    tSourcePricing.setSourceId(s.getSourceId());
868
	                    tSourcePricing.setItemId(it.getId());
869
	                    tSourcePricing.setMrp(s.getMrp());
870
	                    tSourcePricing.setSellingPrice(s.getSellingPrice());
871
	                    catalogClient_Prod.addSourceItemPricing(tSourcePricing);
872
	                    logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
873
	                    sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
874
	                }
875
	            }
876
 
877
	            pushToProdLogger.info("Id=" + it.getId() + ",MRP=" + it.getMrp() + ",SP=" + " " + it.getSellingPrice() + sb.toString());
878
	        } catch (Exception e) {
879
	            logger.error("Error while updating prices on production", e);
880
	            return "Error while updating all prices on production. Some of the prices may not have been  updated";
881
	        }
882
    	}
2427 ankur.sing 883
 
3907 chandransh 884
        try {
885
            ContentClient contentServiceClient = new ContentClient();
886
            ContentService.Client contentClient = contentServiceClient.getClient();
887
 
5706 amit.gupta 888
            contentClient.pushContentToProduction(items.get(0).getCatalogItemId());
3907 chandransh 889
        } catch (TTransportException e) {
890
            logger.error("Error while establishing connection to the content server", e);
891
            return "Error generating content. Prices updated successfully.";
892
        } catch (TException e) {
893
            logger.error("Error while pushing content to production", e);
894
            return "Error generating content. Prices updated successfully.";
895
        } catch (ContentServiceException e) {
896
            logger.error("Error while pushing content to production", e);
897
            return "Error generating content. Prices updated successfully.";
898
        }
899
 
2427 ankur.sing 900
        return "Prices updated and content generated successfully";
2359 ankur.sing 901
    }
2427 ankur.sing 902
 
2489 ankur.sing 903
    /**
3354 chandransh 904
     * Returns list of items with a particular status.
905
     * @param st
906
     * @return
907
     */
3850 chandransh 908
    private List<Item> getItemsByStatus(status st, int start, int limit) {
3354 chandransh 909
        List<Item> itemList = new ArrayList<Item>();
910
        try {
911
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 912
            Client catalogClient = catalogServiceClient.getClient();
3354 chandransh 913
 
3850 chandransh 914
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
3354 chandransh 915
 
916
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5504 phani.kuma 917
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
3354 chandransh 918
            }
919
        } catch (Exception e) {
920
            logger.error("Error while getting items by status: " + st, e);
921
        }
922
        return itemList;
923
    }
924
 
925
    /**
926
     * Creates a new Item object and populates its attributes from thrift item passed as parameter.
4423 phani.kuma 927
     * Also creates a Map each for VendorItemPricing, VendorItemMapping, SourceItemPricing and SimilarItems and adds these maps to the
3354 chandransh 928
     * new Item object.
929
     * @param thriftItem
930
     * @param tVendorPricings
931
     * @param tVendorMappings
4423 phani.kuma 932
     * @param tSourceMappings
933
     * @param tSimilarItems
5504 phani.kuma 934
     * @param tVoucherMappings
3354 chandransh 935
     * @return item object with attributes copied from thrift item object.
936
     */
937
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
5946 rajveer 938
            List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
939
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
4423 phani.kuma 940
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
5946 rajveer 941
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, in.shop2020.model.v1.inventory.ItemInventory tItemInventory, List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings){
3354 chandransh 942
 
943
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
944
        VendorItemMapping vItemMapping;
945
        if(tVendorMappings != null) {
5946 rajveer 946
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
3354 chandransh 947
                vItemMapping = new VendorItemMapping();
948
                vItemMapping.setVendorId(vim.getVendorId());
949
                vItemMapping.setItemKey(vim.getItemKey());
950
                vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
951
            }
952
        }
953
 
954
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
955
        VendorPricings vPricings;
956
        if(tVendorPricings != null) {
5946 rajveer 957
            for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
3354 chandransh 958
                vPricings = new VendorPricings();
959
                vPricings.setVendorId(vip.getVendorId());
960
                vPricings.setMop(vip.getMop());
961
                vPricings.setDealerPrice(vip.getDealerPrice());
962
                vPricings.setTransferPrice(vip.getTransferPrice());
6759 amar.kumar 963
                vPricings.setNlc(vip.getNlc());
3354 chandransh 964
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
965
            }
966
        }
967
 
3558 rajveer 968
        Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
969
        SourcePricings sPricings;
970
        if(tSourceMappings != null) {
971
            for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
972
                sPricings = new SourcePricings();
973
                sPricings.setSourceId(sip.getSourceId());
974
                sPricings.setMrp(sip.getMrp());
975
                sPricings.setSellingPrice(sip.getSellingPrice());
976
                sourcePricingMap.put(sPricings.getSourceId(), sPricings);
977
            }
978
        }
4423 phani.kuma 979
 
980
        Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
981
        Item sItems;
982
        if(tSimilarItems != null) {
983
            for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
984
            	sItems = new Item();
985
            	sItems.setCatalogItemId(sit.getCatalogItemId());
986
            	sItems.setProductGroup(sit.getProductGroup());
987
            	sItems.setBrand(sit.getBrand());
988
            	sItems.setModelNumber(sit.getModelNumber());
989
            	sItems.setModelName(sit.getModelName());
990
            	sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
991
            	SimilarItemslist.put(sit.getCatalogItemId(), sItems);
992
            }
993
        }
3558 rajveer 994
 
4431 phani.kuma 995
        Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
996
        ItemInventory warehousedata;
5309 rajveer 997
        if(tItemInventory != null) {
998
        	Map<Long, Long> availabilityMap = tItemInventory.getAvailability();
999
        	Map<Long, Long> reservedMap = tItemInventory.getReserved();
4431 phani.kuma 1000
            for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1001
            	warehousedata = new ItemInventory();
1002
            	warehousedata.setWarehouseId(availability.getKey());
1003
            	warehousedata.setAvailability(availability.getValue());
1004
            	warehousedata.setReserved(reservedMap.get(availability.getKey()));
1005
            	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1006
            }
1007
        }
1008
        else {
1009
        	itemInventoryMap = null;
1010
        }
5504 phani.kuma 1011
 
1012
        Map<String, VoucherItemMapping> voucherMap = new HashMap<String, VoucherItemMapping>();
1013
        VoucherItemMapping voucher;
1014
        if(tVoucherMappings != null) {
1015
            for(in.shop2020.model.v1.catalog.VoucherItemMapping tvoucher : tVoucherMappings) {
5516 phani.kuma 1016
            	voucher = new VoucherItemMapping(tvoucher.getAmount(), VoucherType.findByValue((int) tvoucher.getVoucherType()).name());
1017
            	voucherMap.put(VoucherType.findByValue((int) tvoucher.getVoucherType()).name(), voucher);
5504 phani.kuma 1018
            }
1019
        }
4431 phani.kuma 1020
 
3354 chandransh 1021
        Item item = new Item(thriftItem.getId(),
1022
                thriftItem.getProductGroup(),
1023
                thriftItem.getBrand(),
1024
                thriftItem.getModelNumber(),
1025
                thriftItem.getModelName(),
1026
                thriftItem.getColor(),
1027
                CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
1028
                thriftItem.getCategory(),
1029
                thriftItem.getComments(),
1030
                thriftItem.getCatalogItemId(),
1031
                thriftItem.getFeatureId(),
1032
                thriftItem.getFeatureDescription(),
1033
                thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
1034
                thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
1035
                thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
1036
                thriftItem.getAddedOn(),
1037
                thriftItem.getStartDate(),
5217 amit.gupta 1038
                thriftItem.isSetComingSoonStartDate() ? thriftItem.getComingSoonStartDate() : null ,
1039
                thriftItem.isSetExpectedArrivalDate() ? thriftItem.getExpectedArrivalDate() : null ,
3354 chandransh 1040
                thriftItem.getRetireDate(),
1041
                thriftItem.getUpdatedOn(),
1042
                thriftItem.getItemStatus().name(),
1043
                thriftItem.getItemStatus().getValue(),
1044
                thriftItem.getStatus_description(),
1045
                thriftItem.getBestDealText(),
6777 vikram.rag 1046
                thriftItem.getBestDealsDetailsText(),
1047
                thriftItem.getBestDealsDetailsLink(),
3354 chandransh 1048
                thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
1049
                thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
1050
                thriftItem.isDefaultForEntity(),
1051
                thriftItem.isRisky(),
3359 chandransh 1052
                thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
4506 phani.kuma 1053
                thriftItem.isIsWarehousePreferenceSticky(),
5384 phani.kuma 1054
                thriftItem.isHasItemNo(),
1055
                ItemType.SERIALIZED.equals(thriftItem.getType()),
5460 phani.kuma 1056
                thriftItem.isClearance(),
6241 amit.gupta 1057
                thriftItem.isSetShowSellingPrice() ? thriftItem.isShowSellingPrice() : false,
4506 phani.kuma 1058
                thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
4431 phani.kuma 1059
                itemInventoryMap,
3354 chandransh 1060
                vendorPricingMap,
3558 rajveer 1061
                vItemMap,
4423 phani.kuma 1062
                sourcePricingMap,
5504 phani.kuma 1063
                SimilarItemslist,
1064
                voucherMap);
3354 chandransh 1065
        return item;
1066
    }
1067
 
1068
    /**
2489 ankur.sing 1069
     * 
3922 chandransh 1070
     * @return True if push to production count is less than maximum allowed.
2489 ankur.sing 1071
     */
3922 chandransh 1072
    private boolean canPushToProduction() {
1073
        int count = getPushToProdCount(logFile);
1074
        return count < maxCount;
2427 ankur.sing 1075
    }
3922 chandransh 1076
 
2489 ankur.sing 1077
    /**
1078
     * If this is the first attempt to push to production for current date, returns 0
1079
     * else reads number of lines from daily rolling log file to get the count.
1080
     * @return push to production count for current date
1081
     */
2498 ankur.sing 1082
    private int getPushToProdCount(String logfile) {
1083
        // logfile is "/var/log/services/pushToProductionCount/pushToProd.log"
1084
        // this should also be set in log4j.properties
2427 ankur.sing 1085
        int lineCount = 0;
2498 ankur.sing 1086
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
2427 ankur.sing 1087
        Date currentDate = Calendar.getInstance().getTime();
1088
        if(pushToProdDate == null ||  !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {
1089
            pushToProdDate = currentDate;
1090
            return lineCount;
1091
        }
1092
        try {
2498 ankur.sing 1093
            BufferedReader br = new BufferedReader(new FileReader(logfile));
2427 ankur.sing 1094
            while (br.readLine() != null) {
1095
                lineCount++;
1096
            }
1097
        } catch (IOException e) {
3354 chandransh 1098
            logger.error("Error while reading the log file", e);
2427 ankur.sing 1099
        }
1100
        return lineCount;
1101
    }
4423 phani.kuma 1102
 
1103
	@Override
1104
	public boolean deleteSimilarItem(long itemId, long catalogItemId) {
1105
		try{
1106
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1107
            Client catalogClient = catalogServiceClient.getClient();
4423 phani.kuma 1108
 
1109
            return catalogClient.deleteSimilarItem(itemId, catalogItemId);
1110
 
1111
        }catch(Exception e){
1112
            logger.error("Error while deleting the SimilarItems for: " + itemId, e);
1113
        }
1114
        return false;
1115
	}
1116
 
1117
	@Override
1118
	public Item addSimilarItem(long itemId, long catalogItemId) {
1119
		try{
1120
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1121
            Client catalogClient = catalogServiceClient.getClient();
4423 phani.kuma 1122
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1123
 
5504 phani.kuma 1124
            return getItemFromThriftItem(thriftItem, null, null, null, null, null, null);
4423 phani.kuma 1125
        }catch(Exception e){
1126
            logger.error("Error while adding the SimilarItems for: " + itemId, e);
1127
        }
1128
        return null;
1129
	}
4431 phani.kuma 1130
 
1131
	@Override
1132
	public Map<Long, ItemInventory> getProdItemInventory(long itemId) {
1133
		try {
1134
            // Initialize client for production server
1135
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
1136
                    ConfigClientKeys.catalog_service_server_port.toString());
5946 rajveer 1137
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1138
            InventoryClient inventoryServiceClient = new InventoryClient();
1139
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1140
            in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(itemId);
4431 phani.kuma 1141
 
1142
            Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1143
            ItemInventory warehousedata;
1144
            if(thriftItemInventory != null) {
1145
            	Map<Long, Long> availabilityMap = thriftItemInventory.getAvailability();
1146
            	Map<Long, Long> reservedMap = thriftItemInventory.getReserved();
1147
                for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1148
                	warehousedata = new ItemInventory();
1149
                	warehousedata.setWarehouseId(availability.getKey());
1150
                	warehousedata.setAvailability(availability.getValue());
1151
                	warehousedata.setReserved(reservedMap.get(availability.getKey()));
1152
                	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1153
                }
1154
            }
1155
            else {
1156
            	itemInventoryMap = null;
1157
            }
1158
            return itemInventoryMap;
1159
        } catch (Exception e) {
1160
            logger.error("Error while updating item's risky flag on staging", e);
1161
        }
1162
		return null;
1163
	}
4649 phani.kuma 1164
 
1165
	@Override
1166
	public boolean addAuthorizationLog(long itemId, String username, String message) {
1167
		try{
1168
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1169
            Client catalogClient = catalogServiceClient.getClient();
4649 phani.kuma 1170
 
1171
            return catalogClient.addAuthorizationLog(itemId, username, message);
1172
 
1173
        }catch(Exception e){
1174
            logger.error("Error while adding the event for: " + itemId, e);
1175
        }
1176
		return false;
1177
	}
1178
 
1179
	@Override
1180
	public Map<String, String> getConfigdataforPriceCompare() {
1181
		Map<String, String> ConfigMap = new HashMap<String, String>();
1182
		try {
1183
			ConfigMap.put("courier_cost_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_cost_factor.toString()));
1184
            ConfigMap.put("courier_weight_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_weight_factor.toString()));
1185
            ConfigMap.put("breakeven_divisor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_divisor.toString()));
1186
            ConfigMap.put("breakeven_additon_factor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_additon_factor.toString()));
1187
            ConfigMap.put("transfer_price_percentage", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_percentage.toString()));
1188
            ConfigMap.put("transfer_price_factor", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_factor.toString()));
1189
        } catch(ConfigException ce) {
1190
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1191
            ConfigMap.put("courier_cost_factor", "60");
1192
            ConfigMap.put("courier_weight_factor", "500");
1193
            ConfigMap.put("breakeven_divisor", "0.98");
1194
            ConfigMap.put("breakeven_additon_factor", "50");
1195
            ConfigMap.put("transfer_price_percentage", "2");
1196
            ConfigMap.put("transfer_price_factor", "50");
1197
        }
1198
		return ConfigMap;
1199
	}
4957 phani.kuma 1200
 
1201
	@Override
1202
	public List<String> getAllCategories() {
1203
		List<String> categoryList = new ArrayList<String>();
1204
		List<Long> parentCategoryIDs = Arrays.asList(new Long[] {(long) 0,(long) 10001,(long) 10009,(long) 10049});
1205
        try {
1206
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1207
            Client catalogClient = catalogServiceClient.getClient();
4957 phani.kuma 1208
 
1209
            List<in.shop2020.model.v1.catalog.Category> categories = catalogClient.getAllCategories();
1210
 
1211
            for(in.shop2020.model.v1.catalog.Category category : categories) {
1212
            	if(!parentCategoryIDs.contains(category.getParent_category_id())){
1213
            		categoryList.add(category.getDisplay_name());
1214
            	}
1215
            	else{
1216
            		continue;
1217
            	}
1218
            }
1219
        } catch (Exception e) {
1220
            logger.error("Error while getting all the categories: ", e);
1221
        }
1222
        return categoryList;
1223
	}
1224
 
1225
	@Override
1226
	public List<String> getAllBrands() {
1227
		List<String> brandsList = new ArrayList<String>();
1228
        try {
1229
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1230
            Client catalogClient = catalogServiceClient.getClient();
4957 phani.kuma 1231
 
1232
            brandsList = catalogClient.getAllBrands();
1233
        } catch (Exception e) {
1234
            logger.error("Error while getting all the categories: ", e);
1235
        }
1236
        return brandsList;
1237
	}
5427 amit.gupta 1238
 
5504 phani.kuma 1239
	@Override
5516 phani.kuma 1240
	public boolean deleteVoucher(Long catalogItemId, Long voucherType) {
5504 phani.kuma 1241
		try{
1242
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1243
            Client catalogClient = catalogServiceClient.getClient();
5504 phani.kuma 1244
 
1245
            return catalogClient.deleteVoucherForItem(catalogItemId, voucherType);
1246
 
1247
        }catch(Exception e){
1248
            logger.error("Error while deleting the Voucher for: " + catalogItemId, e);
1249
        }
1250
        return false;
1251
	}
1252
 
1253
	@Override
5516 phani.kuma 1254
	public boolean addVoucher(Long catalogItemId, Long voucherType, long voucherAmount) {
5504 phani.kuma 1255
		try{
1256
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1257
            Client catalogClient = catalogServiceClient.getClient();
5504 phani.kuma 1258
 
1259
            return catalogClient.addupdateVoucherForItem(catalogItemId, voucherType, voucherAmount);
1260
 
1261
        }catch(Exception e){
1262
            logger.error("Error while adding the Voucher for: " + catalogItemId, e);
1263
        }
1264
		return false;
1265
	}
1266
	@Override
5516 phani.kuma 1267
	public Map<Long, String> getvoucherTypes() {
1268
		Map<Long, String> voucherType = new HashMap<Long, String>();
5504 phani.kuma 1269
		for(VoucherType voucher : VoucherType.values())
1270
		{
5516 phani.kuma 1271
			voucherType.put((long) voucher.getValue(), voucher.name());
5504 phani.kuma 1272
		}
1273
		return voucherType;
1274
	}
1275
 
5586 phani.kuma 1276
	@Override
1277
	public boolean getConfigforentityIdMandatory() {
1278
		try {
1279
			String entityId_mandatory = ConfigClient.getClient().get(ConfigClientKeys.entityId_mandatory.toString());
1280
			if (entityId_mandatory.equals("TRUE")) {
1281
				return true;
1282
			}
1283
        } catch(ConfigException ce) {
1284
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1285
        }
1286
		return false;
1287
	}
1288
 
1289
	@Override
1290
	public boolean checkEntityId(long entityId) {
1291
		try {
1292
            CatalogClient catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_master.toString(), ConfigClientKeys.catalog_service_server_port.toString());
5946 rajveer 1293
            Client catalogClient = catalogServiceClient.getClient();
5586 phani.kuma 1294
            return catalogClient.isValidCatalogItemId(entityId);
1295
        } catch (Exception e) {
1296
            logger.error("Error while checking for a Catalog Item Id: ", e);
1297
        }
1298
		return false;
1299
	}
1300
 
6096 amit.gupta 1301
	@Override
1302
	public String updateExpectedDelayOnProd(Item item) {
1303
		try{
1304
            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
1305
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
1306
                    ConfigClientKeys.catalog_service_server_port.toString());
1307
 
1308
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1309
 
1310
 
1311
            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
1312
            if(item.getExpectedDelay() != null) {
1313
            	tItem.setExpectedDelay(item.getExpectedDelay());
1314
 
1315
	            long rItemId;
1316
	            if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
1317
	                logger.error("Error updating item on production, returned Item Id: " + rItemId);
1318
	                return "Error updating expected delay on production";
1319
	            }
6241 amit.gupta 1320
	            InventoryClient inventoryServiceClient= new InventoryClient();
1321
	            InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
6096 amit.gupta 1322
	            inventoryClient.clearItemAvailabilityCacheForItem(rItemId);
1323
	            logger.info("Successfully updated item: " + item.getId());
1324
	            return "Expected delay successfully updated on prod"; 
1325
            } else {
1326
            	return "Error:expected delay should not be null";
1327
            }
1328
        } catch (Exception e) {
6098 amit.gupta 1329
            logger.error("Error while updating expected delay on production", e);
1330
            return "Error while updating expected delay on production";
6096 amit.gupta 1331
        }
1332
	}
1333
 
1334
 
1335
 
1336
 
1337
 
6530 vikram.rag 1338
}