Subversion Repositories SmartDukaan

Rev

Rev 6530 | Rev 6759 | 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());
5946 rajveer 377
                    inventoryClient.addVendorItemPricing(tVendorPricing);
3354 chandransh 378
                    logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
2105 ankur.sing 379
                }
380
            }
3558 rajveer 381
 
382
            Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
383
            if(sourcePricings != null && !sourcePricings.isEmpty()) {
384
                in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricings;
385
                for(SourcePricings s : sourcePricings.values()) {
386
                	tSourcePricings = new in.shop2020.model.v1.catalog.SourceItemPricing();
387
                	tSourcePricings.setSourceId(s.getSourceId());
388
                    tSourcePricings.setItemId(item.getId());
389
                    tSourcePricings.setMrp(s.getMrp());
390
                    tSourcePricings.setSellingPrice(s.getSellingPrice());
391
                    catalogClient.addSourceItemPricing(tSourcePricings);
392
                    logger.info("Updated SourceItemPricing: " + tSourcePricings.toString());
393
                }
394
            }
395
 
2105 ankur.sing 396
        }catch(Exception e){
3354 chandransh 397
            logger.error("Error while updating item: ", e);
2427 ankur.sing 398
            return false;
2105 ankur.sing 399
        }
400
        return true;
1961 ankur.sing 401
    }
2359 ankur.sing 402
 
6530 vikram.rag 403
    @Override
404
    public List<Long> getMonitoredWarehouseIdsForVendors(List<Long> vendorIds){
405
    	List<Long> monitoredWarehouseids=null;
406
    	 try {
407
			InventoryClient inventoryServiceClient = new InventoryClient();
408
			 in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
409
			 monitoredWarehouseids = inventoryClient.getMonitoredWarehouseForVendors(vendorIds);
410
		} catch (Exception e) {
411
			logger.error("Error while getting Monitored warehouse for vendor: ", e);
412
		}
413
		return monitoredWarehouseids;
414
 
415
    }
416
 
417
    @Override
418
    public List<ItemWarehouse> getignoredInventoryUpdateItemsIdsWarehouseIds(){
419
		List<ItemWarehouse> ignoredItemIdwarehouseIdList = new ArrayList<ItemWarehouse>();
420
    	try {
2359 ankur.sing 421
 
6530 vikram.rag 422
			InventoryClient inventoryServiceClient = new InventoryClient();
423
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
424
			List<IgnoredInventoryUpdateItems> ignoredInventoryUpdateItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
425
			for(IgnoredInventoryUpdateItems ignoredInventoryUpdateItem:ignoredInventoryUpdateItems){
426
				ignoredItemIdwarehouseIdList.add(new ItemWarehouse(ignoredInventoryUpdateItem.getItemId(),ignoredInventoryUpdateItem.getWarehouseId()));
427
			}
428
 
429
 
430
		} catch (Exception e) {
431
			logger.error("Error while getting Monitored warehouseid and itemid : ", e);
432
		}
433
		return ignoredItemIdwarehouseIdList;
434
 
435
    }
2066 ankur.sing 436
    @Override
437
    public Map<Long, String> getAllVendors() {
438
        Map<Long, String> vendorMap = new HashMap<Long, String>();
439
        try {
5946 rajveer 440
            InventoryClient inventoryServiceClient = new InventoryClient();
441
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
442
 
443
            List<in.shop2020.model.v1.inventory.Vendor> vendors = inventoryClient.getAllVendors();
2359 ankur.sing 444
 
5946 rajveer 445
            for(in.shop2020.model.v1.inventory.Vendor v : vendors) {
2066 ankur.sing 446
                vendorMap.put(v.getId(), v.getName());
447
            }
448
        } catch (Exception e) {
3354 chandransh 449
            logger.error("Error while getting all the vendors: ", e);
2066 ankur.sing 450
        }
451
        return vendorMap;
452
    }
453
 
454
    @Override
3558 rajveer 455
    public Map<Long, String> getAllSources() {
456
        Map<Long, String> sourceMap = new HashMap<Long, String>();
457
        try {
458
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 459
            Client catalogClient = catalogServiceClient.getClient();
3558 rajveer 460
 
461
            List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
462
 
463
            for(in.shop2020.model.v1.catalog.Source s : sources) {
464
            	sourceMap.put(s.getId(), s.getName());
465
            }
466
        } catch (Exception e) {
467
            logger.error("Error while getting all the vendors: ", e);
468
        }
469
        return sourceMap;
470
    }
471
 
472
    @Override
5118 mandeep.dh 473
    public Map<Long, String> getShippingWarehouses() {
474
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
475
        Set<Long> shippingLocations = new HashSet<Long>();
476
        try {
5946 rajveer 477
            InventoryClient inventoryServiceClient = new InventoryClient();
478
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
479
 
480
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
5118 mandeep.dh 481
 
5946 rajveer 482
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
5118 mandeep.dh 483
                shippingLocations.add(warehouse.getShippingWarehouseId());
484
            }
485
 
5946 rajveer 486
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
5118 mandeep.dh 487
                if (shippingLocations.contains(warehouse.getId())) {
488
                    warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
489
                }                
490
            }
491
        } catch (Exception e) {
492
            logger.error("Error while getting all the warehouses:", e );
493
        }
494
        return warehouseMap;
495
    }
496
 
497
    @Override
2066 ankur.sing 498
    public Map<Long, String> getAllWarehouses() {
499
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
500
        try {
5946 rajveer 501
        	InventoryClient inventoryServiceClient = new InventoryClient();
502
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
2359 ankur.sing 503
 
5946 rajveer 504
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
2359 ankur.sing 505
 
5946 rajveer 506
            for(in.shop2020.model.v1.inventory.Warehouse w : warehouses) {
2066 ankur.sing 507
                warehouseMap.put(w.getId(), w.getDisplayName());
508
            }
509
        } catch (Exception e) {
3354 chandransh 510
            logger.error("Error while getting all the warehouses:", e );
2066 ankur.sing 511
        }
512
        return warehouseMap;
513
    }
2105 ankur.sing 514
 
515
    @Override
516
    public long addItem(Item item) {
517
        long itemId = 0;
518
        try {
3129 rajveer 519
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 520
            Client catalogClient = catalogServiceClient.getClient();
521
            InventoryClient inventoryServiceClient = new InventoryClient();
522
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
2126 ankur.sing 523
 
2105 ankur.sing 524
            in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
2126 ankur.sing 525
            setThriftItemParams(tItem, item);
2105 ankur.sing 526
            itemId = catalogClient.addItem(tItem);
527
 
2119 ankur.sing 528
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
529
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
5946 rajveer 530
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
2119 ankur.sing 531
                for(VendorPricings v : vendorPricings.values()) {
5946 rajveer 532
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
2119 ankur.sing 533
                    tVendorPricing.setVendorId(v.getVendorId());
534
                    tVendorPricing.setItemId(itemId);
535
                    tVendorPricing.setMop(v.getMop());
536
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
537
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
5946 rajveer 538
                    inventoryClient.addVendorItemPricing(tVendorPricing);
2119 ankur.sing 539
                }
540
            }
2359 ankur.sing 541
 
542
            Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();
2119 ankur.sing 543
            if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
5946 rajveer 544
                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
2359 ankur.sing 545
                for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {
5946 rajveer 546
                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
2359 ankur.sing 547
                    VendorItemMapping v = e.getValue();
2105 ankur.sing 548
                    tVendorMapping.setVendorId(v.getVendorId());
549
                    tVendorMapping.setItemKey(v.getItemKey());
550
                    tVendorMapping.setItemId(itemId);
5946 rajveer 551
                    inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
2105 ankur.sing 552
                }
553
            }
554
        } catch (Exception e) {
3354 chandransh 555
            logger.error("Error while adding an item: ", e);
2105 ankur.sing 556
        }
557
        return itemId;
558
    }
2119 ankur.sing 559
 
560
    @Override
4725 phani.kuma 561
    public long checkSimilarItem(String brand, String modelNumber, String modelName, String color) {
2359 ankur.sing 562
 
2119 ankur.sing 563
        try {
3129 rajveer 564
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 565
            Client catalogClient = catalogServiceClient.getClient();
4725 phani.kuma 566
            return catalogClient.checkSimilarItem(brand, modelNumber, modelName, color);
2119 ankur.sing 567
        } catch (Exception e) {
3354 chandransh 568
            logger.error("Error while checking for a similar item: ", e);
2119 ankur.sing 569
        }
570
        return 0;
571
    }
2359 ankur.sing 572
 
2126 ankur.sing 573
    private void setThriftItemParams(in.shop2020.model.v1.catalog.Item tItem, Item item) {
574
        tItem.setId(tItem.getId());
575
        tItem.setProductGroup(item.getProductGroup());
576
        tItem.setBrand(item.getBrand());
577
        tItem.setModelName(item.getModelName());
578
        tItem.setModelNumber(item.getModelNumber());
579
        tItem.setColor(item.getColor());
6241 amit.gupta 580
        tItem.setShowSellingPrice(item.isShowSellingPrice());
2359 ankur.sing 581
        tItem.setStatus_description(item.getItemStatusDesc());
2126 ankur.sing 582
        tItem.setComments(item.getComments());
2359 ankur.sing 583
 
2489 ankur.sing 584
        if(item.getMrp() != null) {
2126 ankur.sing 585
            tItem.setMrp(item.getMrp());
586
        }
3354 chandransh 587
 
5586 phani.kuma 588
        if(item.getCatalogItemId() != null) {
589
            tItem.setCatalogItemId(item.getCatalogItemId());
590
        }
591
 
2489 ankur.sing 592
        if(item.getSellingPrice() != null) {
2126 ankur.sing 593
            tItem.setSellingPrice(item.getSellingPrice());
594
        }
3354 chandransh 595
 
2489 ankur.sing 596
        if(item.getWeight() != null) {
2126 ankur.sing 597
            tItem.setWeight(item.getWeight());
598
        }
3354 chandransh 599
 
3359 chandransh 600
        if(item.getExpectedDelay() != null) {
601
            tItem.setExpectedDelay(item.getExpectedDelay());
2489 ankur.sing 602
        }
3354 chandransh 603
 
4413 anupam.sin 604
        tItem.setIsWarehousePreferenceSticky(item.isWarehouseStickiness());
605
 
4506 phani.kuma 606
        if(item.getPreferredVendor() != null) {
607
            tItem.setPreferredVendor(item.getPreferredVendor());
608
        }
609
 
2126 ankur.sing 610
        tItem.setBestDealText(item.getBestDealsText());
2489 ankur.sing 611
        if(item.getBestDealsValue() != null) {
2126 ankur.sing 612
            tItem.setBestDealValue(item.getBestDealsValue());
613
        }
3354 chandransh 614
 
2489 ankur.sing 615
        if(item.getBestSellingRank() != null) {
2126 ankur.sing 616
            tItem.setBestSellingRank(item.getBestSellingRank());
617
        }
3354 chandransh 618
 
2126 ankur.sing 619
        tItem.setDefaultForEntity(item.isDefaultForEntity());
2252 ankur.sing 620
        tItem.setRisky(item.isRisky());
5384 phani.kuma 621
        tItem.setHasItemNo(item.isHasItemNo());
5460 phani.kuma 622
        tItem.setClearance(item.isClearance());
5384 phani.kuma 623
 
624
        if(item.isItemType()) {
625
        	tItem.setType(ItemType.SERIALIZED);
626
        }
627
        else {
628
        	tItem.setType(ItemType.NON_SERIALIZED);
629
        }
630
 
2489 ankur.sing 631
        if(item.getStartDate() != null) {
632
            tItem.setStartDate(item.getStartDate());
633
        }
3354 chandransh 634
 
5217 amit.gupta 635
        if(item.getExpectedArrivalDate() != null) {
636
        	tItem.setExpectedArrivalDate(item.getExpectedArrivalDate());
637
        } else {
638
        	tItem.unsetComingSoonStartDate();
639
        	tItem.unsetExpectedArrivalDate();
640
        	if(status.COMING_SOON.equals(tItem.getItemStatus())){
6277 amit.gupta 641
        		tItem.setItemStatus(status.CONTENT_COMPLETE);
642
        		tItem.setStatus_description("Content generation completed");
5217 amit.gupta 643
        	}
644
        }
645
 
646
        if(item.getComingSoonStartDate() != null) {
647
        	tItem.setComingSoonStartDate(item.getComingSoonStartDate());
648
        } else {
649
        	tItem.unsetComingSoonStartDate();
650
        }
651
 
2489 ankur.sing 652
        if(item.getRetireDate() != null) {
653
            tItem.setRetireDate(item.getRetireDate());
654
        }
3354 chandransh 655
 
2126 ankur.sing 656
        tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());
657
    }
658
 
659
    @Override
660
    public void pauseItem(long itemId) {
661
        try {
3129 rajveer 662
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 663
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 664
 
2126 ankur.sing 665
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
666
        } catch (Exception e) {
3354 chandransh 667
            logger.error("Error while pausing the item: " + itemId, e);
2126 ankur.sing 668
        }
2359 ankur.sing 669
 
2126 ankur.sing 670
    }
671
 
672
    @Override
673
    public void markInProcess(long itemId) {
674
        try {
3129 rajveer 675
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 676
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 677
 
2126 ankur.sing 678
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
679
        } catch (Exception e) {
3354 chandransh 680
            logger.error("Error while marking in-process the item: " + itemId, e);
2126 ankur.sing 681
        }
682
    }
2359 ankur.sing 683
 
2126 ankur.sing 684
    @Override
685
    public void phaseoutItem(long itemId) {
686
        try {
3129 rajveer 687
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 688
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 689
 
2126 ankur.sing 690
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
691
        } catch (Exception e) {
3354 chandransh 692
            logger.error("Error while phasing out the item: " + itemId, e);
2126 ankur.sing 693
        }
694
    }
2359 ankur.sing 695
 
2126 ankur.sing 696
    @Override
697
    public void activateItem(long itemId) {
698
        try {
3129 rajveer 699
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 700
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 701
 
2126 ankur.sing 702
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
703
        } catch (Exception e) {
3354 chandransh 704
            logger.error("Error while activating the item: " + itemId, e);
2126 ankur.sing 705
        }
706
    }
2359 ankur.sing 707
 
708
    @Override
709
    public boolean changeItemRiskyFlag(long itemId, boolean risky) {
710
        try {
4354 mandeep.dh 711
            logger.info("Updating risky flag for item id: " + itemId + " to " + risky);
2359 ankur.sing 712
            // Initialize client for staging server
3129 rajveer 713
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 714
            Client catalogClient = catalogServiceClient.getClient();
2359 ankur.sing 715
 
716
            // Initialize client for production server
3165 chandransh 717
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
2359 ankur.sing 718
                    ConfigClientKeys.catalog_service_server_port.toString());
5946 rajveer 719
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
2359 ankur.sing 720
            catalogClient.changeItemRiskyFlag(itemId, risky);
721
 
722
            try{
723
                catalogClient_Prod.changeItemRiskyFlag(itemId, risky);
724
            }catch(Exception e){
3354 chandransh 725
                logger.error("Error while updating item's risky flag on production", e);
2359 ankur.sing 726
                // If not able to change risky flag on production, revert on staging and return false (to show error to user).
727
                catalogClient.changeItemRiskyFlag(itemId, !risky);        
728
                return false;
729
            }
730
        } catch (Exception e) {
3354 chandransh 731
            logger.error("Error while updating item's risky flag on staging", e);
2359 ankur.sing 732
            return false;
733
        }
734
        return true;
735
    }
736
 
2427 ankur.sing 737
 
738
    /**
4762 phani.kuma 739
     * Retuns list of Items filtered by category (column is product_group in catalog.item table)
2427 ankur.sing 740
     * This list is used to generate master sheet (excel sheet)
741
     * @param category
4957 phani.kuma 742
     * @param brand
2427 ankur.sing 743
     * @return
744
     */
4957 phani.kuma 745
    public List<Item> getItemsForMasterSheet(String category, String brand) {
2359 ankur.sing 746
        List<Item> itemList = new ArrayList<Item>();
747
        try {
3129 rajveer 748
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 749
            Client catalogClient = catalogServiceClient.getClient();
750
            InventoryClient inventoryServiceClient = new InventoryClient();
751
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
2359 ankur.sing 752
 
4957 phani.kuma 753
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsForMasterSheet(category, brand);
2359 ankur.sing 754
 
755
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5946 rajveer 756
                List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
757
                List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
3558 rajveer 758
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
5504 phani.kuma 759
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
2359 ankur.sing 760
            }
761
        } catch (Exception e) {
4762 phani.kuma 762
            logger.error("Error while getting items by category: " + category, e);
2359 ankur.sing 763
        }
764
        Collections.sort(itemList, new ItemsComparator());
765
        return itemList;
766
    }
767
 
768
    @Override
2427 ankur.sing 769
    public String updateItemOnProduction(Item item) {
5706 amit.gupta 770
    	if(!canPushToProduction()) {
771
    		// If we can't push to production, then return that message to user
772
    		// else move forward with update.
773
    		return "Maximum push to production count reached for today";
774
    	}
775
    	List<Long> itemIds = item.getSameItemsWithDifferentColors();
776
    	List<Item> items = new ArrayList<Item>();
777
    	items.add(item);
778
    	for(Long itemId : itemIds) {
779
    		try {
780
    			CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 781
    			Client catalogClient = catalogServiceClient.getClient();
782
    			InventoryClient inventoryServiceClient = new InventoryClient();
783
                in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
784
 
5706 amit.gupta 785
    			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
5946 rajveer 786
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
787
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
5706 amit.gupta 788
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
789
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
790
    		} catch (Exception e) {
791
    			logger.error("Could not fetch item for : " + itemId, e);
792
    			return "Could not push to production. No item got pushed.";
793
    		}
794
    	}
795
    	for (Item it : items) {
796
	        logger.info("Update item on production call, Item Id: " + it.getId());
797
 
798
	        try{
799
	            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
800
	                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
801
	                    ConfigClientKeys.catalog_service_server_port.toString());
802
 
5946 rajveer 803
	            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
5706 amit.gupta 804
 
805
	            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(it.getId());
806
 
5946 rajveer 807
	            InventoryClient inventoryServiceClient = new InventoryClient();
808
	            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
809
 
5706 amit.gupta 810
	            if(it.getMrp() != null) {
811
	                tItem.setMrp(it.getMrp());
812
	            }
813
 
814
	            if(it.getSellingPrice() != null) {
815
	                tItem.setSellingPrice(it.getSellingPrice());
816
	            }
817
 
818
	            long rItemId;
819
	            if((rItemId = catalogClient_Prod.updateItem(tItem)) != it.getId()) {
820
	                logger.error("Error updating item on production, returned Item Id: " + rItemId);
821
	                return "Error updating item prices on production";
822
	            }
823
	            logger.info("Successfully updated item: " + it.getId());
824
 
825
	            StringBuilder sb = new StringBuilder();
826
 
827
	            Map<Long, VendorPricings> vendorPricings = it.getVendorPricesMap();
828
	            if(vendorPricings != null && !vendorPricings.isEmpty()) {
5946 rajveer 829
	                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
5706 amit.gupta 830
	                for(VendorPricings v : vendorPricings.values()) {
5946 rajveer 831
	                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
5706 amit.gupta 832
	                    tVendorPricing.setVendorId(v.getVendorId());
833
	                    tVendorPricing.setItemId(it.getId());
834
	                    tVendorPricing.setMop(v.getMop());
835
	                    tVendorPricing.setTransferPrice(v.getTransferPrice());
836
	                    tVendorPricing.setDealerPrice(v.getDealerPrice());
5946 rajveer 837
	                    inventoryClient.addVendorItemPricing(tVendorPricing);
5706 amit.gupta 838
	                    logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
839
	                    sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");
840
	                }
841
	            }
842
 
843
	            Map<String, VendorItemMapping> vendorMappings = it.getVendorKeysMap();
844
	            if(vendorMappings != null && !vendorMappings.isEmpty()) {
5946 rajveer 845
	                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
5706 amit.gupta 846
	                for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
5946 rajveer 847
	                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
5706 amit.gupta 848
	                    tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
849
	                    tVendorMapping.setItemId(it.getId());
850
	                    tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
5946 rajveer 851
	                    inventoryClient.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
5706 amit.gupta 852
	                    logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
853
	                    sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
854
	                }
855
	            }
856
 
857
	            Map<Long, SourcePricings> sourcePricings = it.getSourcePricesMap();
858
	            if(sourcePricings != null && !sourcePricings.isEmpty()){
859
	                in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricing;
860
	                for(SourcePricings s : sourcePricings.values()){
861
	                    tSourcePricing = new in.shop2020.model.v1.catalog.SourceItemPricing();
862
	                    tSourcePricing.setSourceId(s.getSourceId());
863
	                    tSourcePricing.setItemId(it.getId());
864
	                    tSourcePricing.setMrp(s.getMrp());
865
	                    tSourcePricing.setSellingPrice(s.getSellingPrice());
866
	                    catalogClient_Prod.addSourceItemPricing(tSourcePricing);
867
	                    logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
868
	                    sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
869
	                }
870
	            }
871
 
872
	            pushToProdLogger.info("Id=" + it.getId() + ",MRP=" + it.getMrp() + ",SP=" + " " + it.getSellingPrice() + sb.toString());
873
	        } catch (Exception e) {
874
	            logger.error("Error while updating prices on production", e);
875
	            return "Error while updating all prices on production. Some of the prices may not have been  updated";
876
	        }
877
    	}
2427 ankur.sing 878
 
3907 chandransh 879
        try {
880
            ContentClient contentServiceClient = new ContentClient();
881
            ContentService.Client contentClient = contentServiceClient.getClient();
882
 
5706 amit.gupta 883
            contentClient.pushContentToProduction(items.get(0).getCatalogItemId());
3907 chandransh 884
        } catch (TTransportException e) {
885
            logger.error("Error while establishing connection to the content server", e);
886
            return "Error generating content. Prices updated successfully.";
887
        } catch (TException e) {
888
            logger.error("Error while pushing content to production", e);
889
            return "Error generating content. Prices updated successfully.";
890
        } catch (ContentServiceException e) {
891
            logger.error("Error while pushing content to production", e);
892
            return "Error generating content. Prices updated successfully.";
893
        }
894
 
2427 ankur.sing 895
        return "Prices updated and content generated successfully";
2359 ankur.sing 896
    }
2427 ankur.sing 897
 
2489 ankur.sing 898
    /**
3354 chandransh 899
     * Returns list of items with a particular status.
900
     * @param st
901
     * @return
902
     */
3850 chandransh 903
    private List<Item> getItemsByStatus(status st, int start, int limit) {
3354 chandransh 904
        List<Item> itemList = new ArrayList<Item>();
905
        try {
906
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 907
            Client catalogClient = catalogServiceClient.getClient();
3354 chandransh 908
 
3850 chandransh 909
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
3354 chandransh 910
 
911
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
5504 phani.kuma 912
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null));
3354 chandransh 913
            }
914
        } catch (Exception e) {
915
            logger.error("Error while getting items by status: " + st, e);
916
        }
917
        return itemList;
918
    }
919
 
920
    /**
921
     * Creates a new Item object and populates its attributes from thrift item passed as parameter.
4423 phani.kuma 922
     * Also creates a Map each for VendorItemPricing, VendorItemMapping, SourceItemPricing and SimilarItems and adds these maps to the
3354 chandransh 923
     * new Item object.
924
     * @param thriftItem
925
     * @param tVendorPricings
926
     * @param tVendorMappings
4423 phani.kuma 927
     * @param tSourceMappings
928
     * @param tSimilarItems
5504 phani.kuma 929
     * @param tVoucherMappings
3354 chandransh 930
     * @return item object with attributes copied from thrift item object.
931
     */
932
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
5946 rajveer 933
            List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
934
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
4423 phani.kuma 935
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
5946 rajveer 936
            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 937
 
938
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
939
        VendorItemMapping vItemMapping;
940
        if(tVendorMappings != null) {
5946 rajveer 941
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
3354 chandransh 942
                vItemMapping = new VendorItemMapping();
943
                vItemMapping.setVendorId(vim.getVendorId());
944
                vItemMapping.setItemKey(vim.getItemKey());
945
                vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
946
            }
947
        }
948
 
949
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
950
        VendorPricings vPricings;
951
        if(tVendorPricings != null) {
5946 rajveer 952
            for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
3354 chandransh 953
                vPricings = new VendorPricings();
954
                vPricings.setVendorId(vip.getVendorId());
955
                vPricings.setMop(vip.getMop());
956
                vPricings.setDealerPrice(vip.getDealerPrice());
957
                vPricings.setTransferPrice(vip.getTransferPrice());
958
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
959
            }
960
        }
961
 
3558 rajveer 962
        Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
963
        SourcePricings sPricings;
964
        if(tSourceMappings != null) {
965
            for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
966
                sPricings = new SourcePricings();
967
                sPricings.setSourceId(sip.getSourceId());
968
                sPricings.setMrp(sip.getMrp());
969
                sPricings.setSellingPrice(sip.getSellingPrice());
970
                sourcePricingMap.put(sPricings.getSourceId(), sPricings);
971
            }
972
        }
4423 phani.kuma 973
 
974
        Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
975
        Item sItems;
976
        if(tSimilarItems != null) {
977
            for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
978
            	sItems = new Item();
979
            	sItems.setCatalogItemId(sit.getCatalogItemId());
980
            	sItems.setProductGroup(sit.getProductGroup());
981
            	sItems.setBrand(sit.getBrand());
982
            	sItems.setModelNumber(sit.getModelNumber());
983
            	sItems.setModelName(sit.getModelName());
984
            	sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
985
            	SimilarItemslist.put(sit.getCatalogItemId(), sItems);
986
            }
987
        }
3558 rajveer 988
 
4431 phani.kuma 989
        Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
990
        ItemInventory warehousedata;
5309 rajveer 991
        if(tItemInventory != null) {
992
        	Map<Long, Long> availabilityMap = tItemInventory.getAvailability();
993
        	Map<Long, Long> reservedMap = tItemInventory.getReserved();
4431 phani.kuma 994
            for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
995
            	warehousedata = new ItemInventory();
996
            	warehousedata.setWarehouseId(availability.getKey());
997
            	warehousedata.setAvailability(availability.getValue());
998
            	warehousedata.setReserved(reservedMap.get(availability.getKey()));
999
            	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1000
            }
1001
        }
1002
        else {
1003
        	itemInventoryMap = null;
1004
        }
5504 phani.kuma 1005
 
1006
        Map<String, VoucherItemMapping> voucherMap = new HashMap<String, VoucherItemMapping>();
1007
        VoucherItemMapping voucher;
1008
        if(tVoucherMappings != null) {
1009
            for(in.shop2020.model.v1.catalog.VoucherItemMapping tvoucher : tVoucherMappings) {
5516 phani.kuma 1010
            	voucher = new VoucherItemMapping(tvoucher.getAmount(), VoucherType.findByValue((int) tvoucher.getVoucherType()).name());
1011
            	voucherMap.put(VoucherType.findByValue((int) tvoucher.getVoucherType()).name(), voucher);
5504 phani.kuma 1012
            }
1013
        }
4431 phani.kuma 1014
 
3354 chandransh 1015
        Item item = new Item(thriftItem.getId(),
1016
                thriftItem.getProductGroup(),
1017
                thriftItem.getBrand(),
1018
                thriftItem.getModelNumber(),
1019
                thriftItem.getModelName(),
1020
                thriftItem.getColor(),
1021
                CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
1022
                thriftItem.getCategory(),
1023
                thriftItem.getComments(),
1024
                thriftItem.getCatalogItemId(),
1025
                thriftItem.getFeatureId(),
1026
                thriftItem.getFeatureDescription(),
1027
                thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
1028
                thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
1029
                thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
1030
                thriftItem.getAddedOn(),
1031
                thriftItem.getStartDate(),
5217 amit.gupta 1032
                thriftItem.isSetComingSoonStartDate() ? thriftItem.getComingSoonStartDate() : null ,
1033
                thriftItem.isSetExpectedArrivalDate() ? thriftItem.getExpectedArrivalDate() : null ,
3354 chandransh 1034
                thriftItem.getRetireDate(),
1035
                thriftItem.getUpdatedOn(),
1036
                thriftItem.getItemStatus().name(),
1037
                thriftItem.getItemStatus().getValue(),
1038
                thriftItem.getStatus_description(),
1039
                thriftItem.getBestDealText(),
1040
                thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
1041
                thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
1042
                thriftItem.isDefaultForEntity(),
1043
                thriftItem.isRisky(),
3359 chandransh 1044
                thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
4506 phani.kuma 1045
                thriftItem.isIsWarehousePreferenceSticky(),
5384 phani.kuma 1046
                thriftItem.isHasItemNo(),
1047
                ItemType.SERIALIZED.equals(thriftItem.getType()),
5460 phani.kuma 1048
                thriftItem.isClearance(),
6241 amit.gupta 1049
                thriftItem.isSetShowSellingPrice() ? thriftItem.isShowSellingPrice() : false,
4506 phani.kuma 1050
                thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
4431 phani.kuma 1051
                itemInventoryMap,
3354 chandransh 1052
                vendorPricingMap,
3558 rajveer 1053
                vItemMap,
4423 phani.kuma 1054
                sourcePricingMap,
5504 phani.kuma 1055
                SimilarItemslist,
1056
                voucherMap);
3354 chandransh 1057
        return item;
1058
    }
1059
 
1060
    /**
2489 ankur.sing 1061
     * 
3922 chandransh 1062
     * @return True if push to production count is less than maximum allowed.
2489 ankur.sing 1063
     */
3922 chandransh 1064
    private boolean canPushToProduction() {
1065
        int count = getPushToProdCount(logFile);
1066
        return count < maxCount;
2427 ankur.sing 1067
    }
3922 chandransh 1068
 
2489 ankur.sing 1069
    /**
1070
     * If this is the first attempt to push to production for current date, returns 0
1071
     * else reads number of lines from daily rolling log file to get the count.
1072
     * @return push to production count for current date
1073
     */
2498 ankur.sing 1074
    private int getPushToProdCount(String logfile) {
1075
        // logfile is "/var/log/services/pushToProductionCount/pushToProd.log"
1076
        // this should also be set in log4j.properties
2427 ankur.sing 1077
        int lineCount = 0;
2498 ankur.sing 1078
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
2427 ankur.sing 1079
        Date currentDate = Calendar.getInstance().getTime();
1080
        if(pushToProdDate == null ||  !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {
1081
            pushToProdDate = currentDate;
1082
            return lineCount;
1083
        }
1084
        try {
2498 ankur.sing 1085
            BufferedReader br = new BufferedReader(new FileReader(logfile));
2427 ankur.sing 1086
            while (br.readLine() != null) {
1087
                lineCount++;
1088
            }
1089
        } catch (IOException e) {
3354 chandransh 1090
            logger.error("Error while reading the log file", e);
2427 ankur.sing 1091
        }
1092
        return lineCount;
1093
    }
4423 phani.kuma 1094
 
1095
	@Override
1096
	public boolean deleteSimilarItem(long itemId, long catalogItemId) {
1097
		try{
1098
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1099
            Client catalogClient = catalogServiceClient.getClient();
4423 phani.kuma 1100
 
1101
            return catalogClient.deleteSimilarItem(itemId, catalogItemId);
1102
 
1103
        }catch(Exception e){
1104
            logger.error("Error while deleting the SimilarItems for: " + itemId, e);
1105
        }
1106
        return false;
1107
	}
1108
 
1109
	@Override
1110
	public Item addSimilarItem(long itemId, long catalogItemId) {
1111
		try{
1112
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1113
            Client catalogClient = catalogServiceClient.getClient();
4423 phani.kuma 1114
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1115
 
5504 phani.kuma 1116
            return getItemFromThriftItem(thriftItem, null, null, null, null, null, null);
4423 phani.kuma 1117
        }catch(Exception e){
1118
            logger.error("Error while adding the SimilarItems for: " + itemId, e);
1119
        }
1120
        return null;
1121
	}
4431 phani.kuma 1122
 
1123
	@Override
1124
	public Map<Long, ItemInventory> getProdItemInventory(long itemId) {
1125
		try {
1126
            // Initialize client for production server
1127
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
1128
                    ConfigClientKeys.catalog_service_server_port.toString());
5946 rajveer 1129
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1130
            InventoryClient inventoryServiceClient = new InventoryClient();
1131
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1132
            in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(itemId);
4431 phani.kuma 1133
 
1134
            Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1135
            ItemInventory warehousedata;
1136
            if(thriftItemInventory != null) {
1137
            	Map<Long, Long> availabilityMap = thriftItemInventory.getAvailability();
1138
            	Map<Long, Long> reservedMap = thriftItemInventory.getReserved();
1139
                for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1140
                	warehousedata = new ItemInventory();
1141
                	warehousedata.setWarehouseId(availability.getKey());
1142
                	warehousedata.setAvailability(availability.getValue());
1143
                	warehousedata.setReserved(reservedMap.get(availability.getKey()));
1144
                	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1145
                }
1146
            }
1147
            else {
1148
            	itemInventoryMap = null;
1149
            }
1150
            return itemInventoryMap;
1151
        } catch (Exception e) {
1152
            logger.error("Error while updating item's risky flag on staging", e);
1153
        }
1154
		return null;
1155
	}
4649 phani.kuma 1156
 
1157
	@Override
1158
	public boolean addAuthorizationLog(long itemId, String username, String message) {
1159
		try{
1160
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1161
            Client catalogClient = catalogServiceClient.getClient();
4649 phani.kuma 1162
 
1163
            return catalogClient.addAuthorizationLog(itemId, username, message);
1164
 
1165
        }catch(Exception e){
1166
            logger.error("Error while adding the event for: " + itemId, e);
1167
        }
1168
		return false;
1169
	}
1170
 
1171
	@Override
1172
	public Map<String, String> getConfigdataforPriceCompare() {
1173
		Map<String, String> ConfigMap = new HashMap<String, String>();
1174
		try {
1175
			ConfigMap.put("courier_cost_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_cost_factor.toString()));
1176
            ConfigMap.put("courier_weight_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_weight_factor.toString()));
1177
            ConfigMap.put("breakeven_divisor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_divisor.toString()));
1178
            ConfigMap.put("breakeven_additon_factor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_additon_factor.toString()));
1179
            ConfigMap.put("transfer_price_percentage", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_percentage.toString()));
1180
            ConfigMap.put("transfer_price_factor", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_factor.toString()));
1181
        } catch(ConfigException ce) {
1182
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1183
            ConfigMap.put("courier_cost_factor", "60");
1184
            ConfigMap.put("courier_weight_factor", "500");
1185
            ConfigMap.put("breakeven_divisor", "0.98");
1186
            ConfigMap.put("breakeven_additon_factor", "50");
1187
            ConfigMap.put("transfer_price_percentage", "2");
1188
            ConfigMap.put("transfer_price_factor", "50");
1189
        }
1190
		return ConfigMap;
1191
	}
4957 phani.kuma 1192
 
1193
	@Override
1194
	public List<String> getAllCategories() {
1195
		List<String> categoryList = new ArrayList<String>();
1196
		List<Long> parentCategoryIDs = Arrays.asList(new Long[] {(long) 0,(long) 10001,(long) 10009,(long) 10049});
1197
        try {
1198
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1199
            Client catalogClient = catalogServiceClient.getClient();
4957 phani.kuma 1200
 
1201
            List<in.shop2020.model.v1.catalog.Category> categories = catalogClient.getAllCategories();
1202
 
1203
            for(in.shop2020.model.v1.catalog.Category category : categories) {
1204
            	if(!parentCategoryIDs.contains(category.getParent_category_id())){
1205
            		categoryList.add(category.getDisplay_name());
1206
            	}
1207
            	else{
1208
            		continue;
1209
            	}
1210
            }
1211
        } catch (Exception e) {
1212
            logger.error("Error while getting all the categories: ", e);
1213
        }
1214
        return categoryList;
1215
	}
1216
 
1217
	@Override
1218
	public List<String> getAllBrands() {
1219
		List<String> brandsList = new ArrayList<String>();
1220
        try {
1221
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1222
            Client catalogClient = catalogServiceClient.getClient();
4957 phani.kuma 1223
 
1224
            brandsList = catalogClient.getAllBrands();
1225
        } catch (Exception e) {
1226
            logger.error("Error while getting all the categories: ", e);
1227
        }
1228
        return brandsList;
1229
	}
5427 amit.gupta 1230
 
5504 phani.kuma 1231
	@Override
5516 phani.kuma 1232
	public boolean deleteVoucher(Long catalogItemId, Long voucherType) {
5504 phani.kuma 1233
		try{
1234
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1235
            Client catalogClient = catalogServiceClient.getClient();
5504 phani.kuma 1236
 
1237
            return catalogClient.deleteVoucherForItem(catalogItemId, voucherType);
1238
 
1239
        }catch(Exception e){
1240
            logger.error("Error while deleting the Voucher for: " + catalogItemId, e);
1241
        }
1242
        return false;
1243
	}
1244
 
1245
	@Override
5516 phani.kuma 1246
	public boolean addVoucher(Long catalogItemId, Long voucherType, long voucherAmount) {
5504 phani.kuma 1247
		try{
1248
            CatalogClient catalogServiceClient = new CatalogClient();
5946 rajveer 1249
            Client catalogClient = catalogServiceClient.getClient();
5504 phani.kuma 1250
 
1251
            return catalogClient.addupdateVoucherForItem(catalogItemId, voucherType, voucherAmount);
1252
 
1253
        }catch(Exception e){
1254
            logger.error("Error while adding the Voucher for: " + catalogItemId, e);
1255
        }
1256
		return false;
1257
	}
1258
	@Override
5516 phani.kuma 1259
	public Map<Long, String> getvoucherTypes() {
1260
		Map<Long, String> voucherType = new HashMap<Long, String>();
5504 phani.kuma 1261
		for(VoucherType voucher : VoucherType.values())
1262
		{
5516 phani.kuma 1263
			voucherType.put((long) voucher.getValue(), voucher.name());
5504 phani.kuma 1264
		}
1265
		return voucherType;
1266
	}
1267
 
5586 phani.kuma 1268
	@Override
1269
	public boolean getConfigforentityIdMandatory() {
1270
		try {
1271
			String entityId_mandatory = ConfigClient.getClient().get(ConfigClientKeys.entityId_mandatory.toString());
1272
			if (entityId_mandatory.equals("TRUE")) {
1273
				return true;
1274
			}
1275
        } catch(ConfigException ce) {
1276
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1277
        }
1278
		return false;
1279
	}
1280
 
1281
	@Override
1282
	public boolean checkEntityId(long entityId) {
1283
		try {
1284
            CatalogClient catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_master.toString(), ConfigClientKeys.catalog_service_server_port.toString());
5946 rajveer 1285
            Client catalogClient = catalogServiceClient.getClient();
5586 phani.kuma 1286
            return catalogClient.isValidCatalogItemId(entityId);
1287
        } catch (Exception e) {
1288
            logger.error("Error while checking for a Catalog Item Id: ", e);
1289
        }
1290
		return false;
1291
	}
1292
 
6096 amit.gupta 1293
	@Override
1294
	public String updateExpectedDelayOnProd(Item item) {
1295
		try{
1296
            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
1297
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
1298
                    ConfigClientKeys.catalog_service_server_port.toString());
1299
 
1300
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1301
 
1302
 
1303
            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
1304
            if(item.getExpectedDelay() != null) {
1305
            	tItem.setExpectedDelay(item.getExpectedDelay());
1306
 
1307
	            long rItemId;
1308
	            if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
1309
	                logger.error("Error updating item on production, returned Item Id: " + rItemId);
1310
	                return "Error updating expected delay on production";
1311
	            }
6241 amit.gupta 1312
	            InventoryClient inventoryServiceClient= new InventoryClient();
1313
	            InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
6096 amit.gupta 1314
	            inventoryClient.clearItemAvailabilityCacheForItem(rItemId);
1315
	            logger.info("Successfully updated item: " + item.getId());
1316
	            return "Expected delay successfully updated on prod"; 
1317
            } else {
1318
            	return "Error:expected delay should not be null";
1319
            }
1320
        } catch (Exception e) {
6098 amit.gupta 1321
            logger.error("Error while updating expected delay on production", e);
1322
            return "Error while updating expected delay on production";
6096 amit.gupta 1323
        }
1324
	}
1325
 
1326
 
1327
 
1328
 
1329
 
6530 vikram.rag 1330
}