Subversion Repositories SmartDukaan

Rev

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