Subversion Repositories SmartDukaan

Rev

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

Rev 10484 Rev 11671
Line 16... Line 16...
16
import in.shop2020.content.ContentServiceException;
16
import in.shop2020.content.ContentServiceException;
17
import in.shop2020.model.v1.catalog.CatalogService.Client;
17
import in.shop2020.model.v1.catalog.CatalogService.Client;
18
import in.shop2020.model.v1.catalog.CatalogServiceException;
18
import in.shop2020.model.v1.catalog.CatalogServiceException;
19
import in.shop2020.model.v1.catalog.Insurer;
19
import in.shop2020.model.v1.catalog.Insurer;
20
import in.shop2020.model.v1.catalog.ItemType;
20
import in.shop2020.model.v1.catalog.ItemType;
-
 
21
import in.shop2020.model.v1.catalog.PrivateDeal;
21
import in.shop2020.model.v1.catalog.status;
22
import in.shop2020.model.v1.catalog.status;
22
import in.shop2020.model.v1.inventory.InventoryService;
23
import in.shop2020.model.v1.inventory.InventoryService;
23
import in.shop2020.model.v1.inventory.ItemStockPurchaseParams;
24
import in.shop2020.model.v1.inventory.ItemStockPurchaseParams;
24
import in.shop2020.model.v1.inventory.OOSStatus;
25
import in.shop2020.model.v1.inventory.OOSStatus;
25
import in.shop2020.model.v1.user.VoucherType;
26
import in.shop2020.model.v1.user.VoucherType;
Line 55... Line 56...
55
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
56
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
56
 
57
 
57
@SuppressWarnings("serial")
58
@SuppressWarnings("serial")
58
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
59
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
59
 
60
 
60
    private static Logger logger = Logger.getLogger(CatalogServiceImpl.class);
61
	private static Logger logger = Logger.getLogger(CatalogServiceImpl.class);
61
    
62
 
62
    private static Logger pushToProdLogger = Logger.getLogger("pushToProdLogger");
63
	private static Logger pushToProdLogger = Logger.getLogger("pushToProdLogger");
63
    
64
 
64
    private static Date pushToProdDate;
65
	private static Date pushToProdDate;
65
    
66
 
66
    private static String logFile;
67
	private static String logFile;
67
    
68
 
68
    private static int maxCount;
69
	private static int maxCount;
69
    
70
 
70
    private static final int EBAYSOURCE = 6;
71
	private static final int EBAYSOURCE = 6;
71
    private static final int SNAPDEALSOURCE = 7;
72
	private static final int SNAPDEALSOURCE = 7;
72
    private static final int FLIPKARTSOURCE = 8;
73
	private static final int FLIPKARTSOURCE = 8;
-
 
74
 
-
 
75
	List<Item> privateDealitemList;
73
    
76
 
74
    static {
77
	static {
75
        try {
78
		try {
76
            logFile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
79
			logFile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
77
            maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));    
80
			maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));    
78
        } catch(ConfigException ce) {
81
		} catch(ConfigException ce) {
79
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
82
			logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
80
            logFile = "/var/log/services/pushToProductionCount/pushToProd.log";
83
			logFile = "/var/log/services/pushToProductionCount/pushToProd.log";
81
            maxCount = 5;
84
			maxCount = 5;
82
        }
85
		}
83
                
-
 
-
 
86
 
84
    }
87
	}
85
    
88
 
86
    @Override
89
	@Override
87
    public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
90
	public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
88
        int count = 0;
91
		int count = 0;
89
        try{
92
		try{
90
            CatalogClient catalogServiceClient = new CatalogClient();
93
			CatalogClient catalogServiceClient = new CatalogClient();
91
            Client catalogClient = catalogServiceClient.getClient();
94
			Client catalogClient = catalogServiceClient.getClient();
92
            
95
 
93
            status stat = status.findByValue(itemStatus.getValue());
96
			status stat = status.findByValue(itemStatus.getValue());
94
            count = catalogClient.getItemCountByStatus(useStatus, stat);
97
			count = catalogClient.getItemCountByStatus(useStatus, stat);
95
        }catch(Exception e){
98
		}catch(Exception e){
96
            logger.error("Error while getting the count of items from the catalog service", e);
99
			logger.error("Error while getting the count of items from the catalog service", e);
97
        }
100
		}
98
        return count;
101
		return count;
99
    }
102
	}
100
    
103
 
101
    @Override
104
	@Override
102
	public List<Item> getInventoryOutofSyncItems(int offset, int limit){
105
	public List<Item> getInventoryOutofSyncItems(int offset, int limit){
103
        List<Item> itemList = new ArrayList<Item>();
106
		List<Item> itemList = new ArrayList<Item>();
104
 
107
 
105
        try {
108
		try {
106
            CatalogClient catalogServiceClient = new CatalogClient();
109
			CatalogClient catalogServiceClient = new CatalogClient();
107
            Client catalogClient = catalogServiceClient.getClient();
110
			Client catalogClient = catalogServiceClient.getClient();
108
 
111
 
109
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllIgnoredInventoryUpdateItemsList(offset, limit);
112
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllIgnoredInventoryUpdateItemsList(offset, limit);
110
 
113
 
111
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
114
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
112
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null));
115
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null));
113
            }
116
			}
114
        } catch (Exception e) {
117
		} catch (Exception e) {
115
            logger.error("Error while getting all items from the catalog service", e);
118
			logger.error("Error while getting all items from the catalog service", e);
116
        }
119
		}
117
        return itemList;
120
		return itemList;
118
    }
121
	}
119
    
122
 
120
    @Override
123
	@Override
121
    public int getInventoryOutofSyncItemsCount(){
124
	public int getInventoryOutofSyncItemsCount(){
122
	int count=0;
125
		int count=0;
123
    	try {
126
		try {
124
            InventoryClient inventoryServiceClient = new InventoryClient();
127
			InventoryClient inventoryServiceClient = new InventoryClient();
125
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
128
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
126
 
129
 
127
            count = inventoryClient.getAllIgnoredInventoryupdateItemsCount();
130
			count = inventoryClient.getAllIgnoredInventoryupdateItemsCount();
128
 
131
 
129
            } catch (Exception e) {
132
		} catch (Exception e) {
130
            logger.error("Error while getting all items from the catalog service", e);
133
			logger.error("Error while getting all items from the catalog service", e);
131
        }
134
		}
132
    	return count;	
135
		return count;	
133
    }    
136
	}
134
    
137
 
135
    @Override
138
	public List<Item> getPrivateDealItems(int offset,int limit){
136
    public List<Item> getAllItems(int start, int limit) {
139
		privateDealitemList = new ArrayList<Item>();
137
        List<Item> itemList = new ArrayList<Item>();
140
		try {
138
 
141
			CatalogClient catalogServiceClient = new CatalogClient();
139
        try {
142
			Client catalogClient = catalogServiceClient.getClient();
140
            CatalogClient catalogServiceClient = new CatalogClient();
143
 
141
            Client catalogClient = catalogServiceClient.getClient();
144
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getPrivateDealItems(offset, limit);
142
 
145
 
143
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
146
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
144
 
147
				privateDealitemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null));
145
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
148
			}
146
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null));
149
		} catch (Exception e) {
147
            }
150
			logger.error("Error while getting all items from the catalog service", e);
148
        } catch (Exception e) {
151
		}
149
            logger.error("Error while getting all items from the catalog service", e);
152
		return privateDealitemList;
150
        }
153
	}
151
        return itemList;
154
	public int getPrivateDealItemsCount(){
152
    }
155
		if(privateDealitemList!=null)
153
 
156
			return privateDealitemList.size();
154
    public List<Item> getAllActiveItems(int start, int limit){
157
		else
155
        return getItemsByStatus(status.ACTIVE, start, limit);
158
			return 0;
156
    }
159
	}
157
 
160
 
158
    @Override
161
	@Override
159
    public List<Item> getAllPhasedOutItems(int start, int limit){
162
	public List<Item> getAllItems(int start, int limit) {
160
        return getItemsByStatus(status.PHASED_OUT, start, limit);
163
		List<Item> itemList = new ArrayList<Item>();
161
    }
164
		logger.error("Inside get All Items");
162
 
165
		try {
163
    @Override
166
			CatalogClient catalogServiceClient = new CatalogClient();
164
    public List<Item> getAllPausedItems(int start, int limit){
167
			Client catalogClient = catalogServiceClient.getClient();
165
        return getItemsByStatus(status.PAUSED, start, limit);
168
 
166
    }
169
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
167
 
170
			logger.error("Before get item from thrift");
168
    @Override
171
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
169
    public List<Item> getAllInProcessItems(int start, int limit) {
172
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null));
170
        return getItemsByStatus(status.IN_PROCESS, start, limit);
173
			}
171
    }
174
			logger.error("After get item from thrift");
172
 
175
		} catch (Exception e) {
173
    @Override
176
			logger.error("Error while getting all items from the catalog service", e);
174
    public List<Item> getAllContentCompleteItems(int start, int limit) {
177
		}
175
        return getItemsByStatus(status.CONTENT_COMPLETE, start, limit);
178
		logger.error("Item List return Size "+ itemList.size());
176
    }
179
		return itemList;
177
 
180
	}
178
    public List<Item> getBestDeals(){
181
 
179
        List<Item> itemList = new ArrayList<Item>();
182
	public List<Item> getAllActiveItems(int start, int limit){
180
        try {
183
		return getItemsByStatus(status.ACTIVE, start, limit);
181
            CatalogClient catalogServiceClient = new CatalogClient();
184
	}
182
            Client catalogClient = catalogServiceClient.getClient();
185
 
183
 
186
	@Override
184
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
187
	public List<Item> getAllPhasedOutItems(int start, int limit){
185
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
188
		return getItemsByStatus(status.PHASED_OUT, start, limit);
186
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null));
189
	}
187
            }
190
 
188
        } catch(Exception e){
191
	@Override
189
            logger.error("Error while getting the best deals from the catalog service", e);
192
	public List<Item> getAllPausedItems(int start, int limit){
190
        }
193
		return getItemsByStatus(status.PAUSED, start, limit);
191
        //Collections.sort(itemList, new ItemsComparator());
194
	}
192
        return itemList;
195
 
193
    }
196
	@Override
194
    
197
	public List<Item> getAllInProcessItems(int start, int limit) {
195
    @Override
198
		return getItemsByStatus(status.IN_PROCESS, start, limit);
196
    public List<Item> getRiskyItems() {
199
	}
197
        List<Item> itemList = new ArrayList<Item>();
200
 
198
        try {
201
	@Override
199
            CatalogClient catalogServiceClient = new CatalogClient();
202
	public List<Item> getAllContentCompleteItems(int start, int limit) {
200
            Client catalogClient = catalogServiceClient.getClient();
203
		return getItemsByStatus(status.CONTENT_COMPLETE, start, limit);
201
 
204
	}
202
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
205
 
203
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
206
	public List<Item> getBestDeals(){
204
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null));
207
		List<Item> itemList = new ArrayList<Item>();
205
            }
208
		try {
206
        } catch(Exception e){
209
			CatalogClient catalogServiceClient = new CatalogClient();
207
            logger.error("Error while getting the risky items from the catalog service", e);
210
			Client catalogClient = catalogServiceClient.getClient();
208
        }
211
 
209
        Collections.sort(itemList, new ItemsComparator());
212
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
210
        return itemList;
213
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
211
    }
214
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null));
212
 
215
			}
213
    public List<Item> getBestSellers(){
216
		} catch(Exception e){
214
        List<Item> itemList = new ArrayList<Item>();
217
			logger.error("Error while getting the best deals from the catalog service", e);
215
 
218
		}
216
        try {
219
		//Collections.sort(itemList, new ItemsComparator());
217
            CatalogClient catalogServiceClient = new CatalogClient();
220
		return itemList;
218
            Client catalogClient = catalogServiceClient.getClient();
221
	}
219
 
222
 
220
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
223
	@Override
221
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
224
	public List<Item> getRiskyItems() {
222
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null));
225
		List<Item> itemList = new ArrayList<Item>();
223
            }
226
		try {
224
        } catch(Exception e){
227
			CatalogClient catalogServiceClient = new CatalogClient();
225
            logger.error("Error while getting the best sellers from the catalog service", e);
228
			Client catalogClient = catalogServiceClient.getClient();
226
        }
229
 
227
        return itemList;        
230
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
228
    }
231
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
229
    
232
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null));
230
    @Override
233
			}
231
    public boolean addtoIgnoredInventoryUpdateItemsIdsWarehouseIds(long itemId,long warehouseId){
234
		} catch(Exception e){
232
    	try {
235
			logger.error("Error while getting the risky items from the catalog service", e);
233
				InventoryClient inventoryServiceClient = new InventoryClient();
236
		}
234
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
237
		Collections.sort(itemList, new ItemsComparator());
235
				return inventoryClient.insertItemtoIgnoreInventoryUpdatelist(itemId, warehouseId);
238
		return itemList;
236
			} catch (Exception e) {
239
	}
237
            logger.error("Error while inserting item to ignore inventory update list", e);
240
 
238
            }
241
	public List<Item> getBestSellers(){
239
			return false;
242
		List<Item> itemList = new ArrayList<Item>();
240
    }
243
 
241
    
244
		try {
242
    @Override
245
			CatalogClient catalogServiceClient = new CatalogClient();
243
    public boolean deleteFromIgnoredInventoryUpdateItemsIdsWarehouseIds(long itemId,long warehouseId){
246
			Client catalogClient = catalogServiceClient.getClient();
244
    	try {
247
 
245
    			InventoryClient inventoryServiceClient = new InventoryClient();
248
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
246
    			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
249
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
247
    			return inventoryClient.deleteItemFromIgnoredInventoryUpdateList(itemId,warehouseId);
250
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null));
248
    			
251
			}
-
 
252
		} catch(Exception e){
-
 
253
			logger.error("Error while getting the best sellers from the catalog service", e);
-
 
254
		}
-
 
255
		return itemList;        
-
 
256
	}
-
 
257
 
-
 
258
	@Override
-
 
259
	public boolean addtoIgnoredInventoryUpdateItemsIdsWarehouseIds(long itemId,long warehouseId){
-
 
260
		try {
-
 
261
			InventoryClient inventoryServiceClient = new InventoryClient();
-
 
262
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
263
			return inventoryClient.insertItemtoIgnoreInventoryUpdatelist(itemId, warehouseId);
249
		} catch (Exception e) {
264
		} catch (Exception e) {
250
			logger.error("Error while inserting item to ignore inventory update list", e);
265
			logger.error("Error while inserting item to ignore inventory update list", e);
251
        }
266
		}
252
		return false;
267
		return false;
253
}
268
	}
254
 
269
 
-
 
270
	@Override
-
 
271
	public boolean deleteFromIgnoredInventoryUpdateItemsIdsWarehouseIds(long itemId,long warehouseId){
-
 
272
		try {
-
 
273
			InventoryClient inventoryServiceClient = new InventoryClient();
-
 
274
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
275
			return inventoryClient.deleteItemFromIgnoredInventoryUpdateList(itemId,warehouseId);
255
 
276
 
-
 
277
		} catch (Exception e) {
-
 
278
			logger.error("Error while inserting item to ignore inventory update list", e);
-
 
279
		}
-
 
280
		return false;
-
 
281
	}
-
 
282
 
-
 
283
 
-
 
284
 
-
 
285
	@Override
-
 
286
	public List<Item> getLatestArrivals(){
-
 
287
		List<Item> itemList = new ArrayList<Item>();
256
 
288
 
257
    @Override
289
		try {
258
    public List<Item> getLatestArrivals(){
290
			CatalogClient catalogServiceClient = new CatalogClient();
259
        List<Item> itemList = new ArrayList<Item>();
291
			Client catalogClient = catalogServiceClient.getClient();
260
 
292
 
261
        try {
293
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
262
            CatalogClient catalogServiceClient = new CatalogClient();
294
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
263
            Client catalogClient = catalogServiceClient.getClient();
295
				//List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
264
 
296
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null));
265
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
297
			}
266
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
298
		} catch(Exception e){
267
                //List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
299
			logger.error("Error while getting the latest arrivals from the catalog service", e);
268
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null));
300
		}
269
            }
301
		return itemList;
270
        } catch(Exception e){
302
	}
271
            logger.error("Error while getting the latest arrivals from the catalog service", e);
303
 
272
        }
304
	@Override
273
        return itemList;
305
	public List<Item> searchItems(int start, int limit, List<String> searchTerms) {
274
    }
306
		List<Item> itemList = new ArrayList<Item>();
275
 
307
 
276
    @Override
308
		try {
277
    public List<Item> searchItems(int start, int limit, List<String> searchTerms) {
309
			CatalogClient catalogServiceClient = new CatalogClient();
278
        List<Item> itemList = new ArrayList<Item>();
310
			Client catalogClient = catalogServiceClient.getClient();
279
 
311
 
280
        try {
312
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
281
            CatalogClient catalogServiceClient = new CatalogClient();
313
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
282
            Client catalogClient = catalogServiceClient.getClient();
314
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null,null));
283
 
315
			}
284
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
316
		} catch(Exception e){
285
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
317
			logger.error("Error while getting the search results from the catalog service", e);
286
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null,null));
318
		}
287
            }
319
		return itemList;
288
        } catch(Exception e){
320
	}
289
            logger.error("Error while getting the search results from the catalog service", e);
321
 
290
        }
322
	@Override
291
        return itemList;
323
	public int getSearchResultCount(List<String> searchTerms){
292
    }
324
		int count = 0;
293
    
325
		try {
294
    @Override
326
			CatalogClient catalogServiceClient = new CatalogClient();
295
    public int getSearchResultCount(List<String> searchTerms){
327
			Client catalogClient = catalogServiceClient.getClient();
296
        int count = 0;
328
 
297
        try {
329
			count = catalogClient.getSearchResultCount(searchTerms);
298
            CatalogClient catalogServiceClient = new CatalogClient();
330
		} catch(Exception e){
299
            Client catalogClient = catalogServiceClient.getClient();
331
			logger.error("Error while getting the search results from the catalog service", e);
300
 
332
		}
301
            count = catalogClient.getSearchResultCount(searchTerms);
333
 
302
        } catch(Exception e){
334
		return count;
303
            logger.error("Error while getting the search results from the catalog service", e);
335
	}
304
        }
336
 
305
        
337
	public Item getItem(long itemId){
306
        return count;
338
		try{
307
    }
339
			CatalogClient catalogServiceClient = new CatalogClient();
308
    
340
			Client catalogClient = catalogServiceClient.getClient();
309
    public Item getItem(long itemId){
-
 
310
        try{
-
 
311
            CatalogClient catalogServiceClient = new CatalogClient();
-
 
312
            Client catalogClient = catalogServiceClient.getClient();
-
 
313
            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
314
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
315
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
-
 
316
            Long catalogItemId = thriftItem.getCatalogItemId();
-
 
317
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByCatalogId(catalogItemId);
-
 
318
            List <Long> sameItemsWithDifferentColors = new ArrayList<Long>();
-
 
319
            if(thriftItems.size()>1){
-
 
320
	            for(in.shop2020.model.v1.catalog.Item tItem : thriftItems ){
-
 
321
	            	Long id = tItem.getId();
-
 
322
		        	if(!id.equals(itemId)){
-
 
323
		        		sameItemsWithDifferentColors.add(id); 
-
 
324
		        	}
-
 
325
	            }
-
 
326
            }
-
 
327
            List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
-
 
328
            Map<Long,String> stateIdNameMap = inventoryClient.getStateMaster();
-
 
329
            
-
 
330
            List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
-
 
331
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
-
 
332
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
-
 
333
            in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
-
 
334
            ItemStockPurchaseParams stockPurchaseParams = inventoryClient.getItemStockPurchaseParams(thriftItem.getId());
-
 
335
            Map<Long, String> saleHistory = new HashMap<Long, String>();
-
 
336
            List<OOSStatus> oosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 0, 5);
-
 
337
            String lastNdaySale = getOosString(oosStatuses);
-
 
338
            saleHistory.put(0L,lastNdaySale);
-
 
339
            List<OOSStatus> webOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 1, 5);
-
 
340
            String webLastNdaySale = getOosString(webOosStatuses);
-
 
341
            saleHistory.put(1L,webLastNdaySale);
-
 
342
            List<OOSStatus> amzOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 3, 5);
-
 
343
            String amzLastNdaySale = getOosString(amzOosStatuses);
-
 
344
            saleHistory.put(3L,amzLastNdaySale);
-
 
345
            List<OOSStatus> ebayOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 6, 5);
-
 
346
            String ebayLastNdaySale = getOosString(ebayOosStatuses);
-
 
347
            saleHistory.put(6L,ebayLastNdaySale);
-
 
348
            List<OOSStatus> spdOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 7, 5);
-
 
349
            String spdLastNdaySale = getOosString(spdOosStatuses);
-
 
350
            saleHistory.put(7L,spdLastNdaySale);
-
 
351
            List<OOSStatus> fktOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 8, 5);
-
 
352
            String fktLastNdaySale = getOosString(fktOosStatuses);
-
 
353
            saleHistory.put(8L,fktLastNdaySale);
-
 
354
            Long freebieItemId = catalogClient.getFreebieForItem(thriftItem.getId());
-
 
355
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
-
 
356
            Map<String,String> stateNameVatPercentageMap = new HashMap<String,String>();
-
 
357
            catalogClient =  new CatalogClient("catalog_service_server_host_prod","catalog_service_server_port").getClient();
-
 
358
            double vatrate;
-
 
359
            for(Entry<Long, String> entry:stateIdNameMap.entrySet()){
-
 
360
            	try{
-
 
361
            	     vatrate= catalogClient.getVatPercentageForItem(thriftItem.getId(),entry.getKey(),thriftItem.getSellingPrice());
-
 
362
            	}
-
 
363
            	catch(CatalogServiceException cex){
-
 
364
            		vatrate = -1.0;
-
 
365
            	}
-
 
366
            	stateNameVatPercentageMap.put(entry.getValue(),String.valueOf(vatrate));
-
 
367
            }
-
 
368
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers, stockPurchaseParams, saleHistory, freebieItemId , stateNameVatPercentageMap);
-
 
369
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
-
 
370
            return it;
-
 
371
        }catch(Exception e){
-
 
372
            logger.error("Error while getting the item from the catalog service", e);
-
 
373
        }
-
 
374
        return null;
-
 
375
    }
-
 
376
    
-
 
377
    private String getOosString(List<OOSStatus> oosStatuses){
-
 
378
    	String lastNdaySale = "";
-
 
379
        for(OOSStatus oosStatus : oosStatuses){
-
 
380
        	if(oosStatus.isIs_oos()){
-
 
381
        		lastNdaySale += "X-";
-
 
382
        	}else{
-
 
383
        		lastNdaySale += oosStatus.getNum_orders() + "-";
-
 
384
        	}
-
 
385
        }
-
 
386
        if(lastNdaySale!=""){
-
 
387
        	lastNdaySale = lastNdaySale.substring(0, lastNdaySale.length()-1);
-
 
388
        }
-
 
389
        return lastNdaySale;
-
 
390
    }
-
 
391
 
-
 
392
    @Override
-
 
393
    public boolean updateItem(Item item) {
-
 
394
        logger.info("Updating item with Id: " + item.getId());
-
 
395
        try{
-
 
396
            CatalogClient catalogServiceClient = new CatalogClient();
-
 
397
            Client catalogClient = catalogServiceClient.getClient();
-
 
398
            InventoryClient inventoryServiceClient = new InventoryClient();
-
 
399
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
400
            
-
 
401
            in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
-
 
402
            setThriftItemParams(tItem, item);
-
 
403
 
-
 
404
            long rItemId;
-
 
405
            if((rItemId = catalogClient.updateItem(tItem)) != item.getId()) {
-
 
406
                logger.error("Error updating item, returned Item Id: " + rItemId);
-
 
407
                return false;
-
 
408
            }
-
 
409
            logger.info("Successfully updated item with id: " + item.getId());
-
 
410
 
-
 
411
            Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();
-
 
412
            if(vendorMappings != null && !vendorMappings.isEmpty()) {
-
 
413
                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
-
 
414
 
-
 
415
                for(Entry<String, VendorItemMapping> e : vendorMappings.entrySet()) {
-
 
416
                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
-
 
417
                    VendorItemMapping v = e.getValue();
-
 
418
                    tVendorMapping.setVendorId(v.getVendorId());
-
 
419
                    tVendorMapping.setItemKey(v.getItemKey());
-
 
420
                    tVendorMapping.setItemId(item.getId());
-
 
421
                    inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
-
 
422
                    logger.info("Updates VendorItemMapping: " + tVendorMapping.toString());
-
 
423
                }
-
 
424
            }
-
 
425
 
-
 
426
            if(item.getMinStockLevel()!=0 || item.getNumOfDaysStock()!=0) {
-
 
427
            	inventoryClient.updateItemStockPurchaseParams(item.getId(), item.getNumOfDaysStock(),
-
 
428
            			item.getMinStockLevel());
-
 
429
            }
-
 
430
            
-
 
431
            if(item.getFreebieItemId()!=null) {
-
 
432
            	in.shop2020.model.v1.catalog.FreebieItem freebieItem = new in.shop2020.model.v1.catalog.FreebieItem();
-
 
433
            	freebieItem.setItemId(item.getId());
-
 
434
            	freebieItem.setFreebieItemId(item.getFreebieItemId());
-
 
435
            	catalogClient.addOrUpdateFreebieForItem(freebieItem);
-
 
436
            }
-
 
437
            
-
 
438
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
-
 
439
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
-
 
440
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
-
 
441
                for(VendorPricings v : vendorPricings.values()) {
-
 
442
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
-
 
443
                    tVendorPricing.setVendorId(v.getVendorId());
-
 
444
                    tVendorPricing.setItemId(item.getId());
-
 
445
                    tVendorPricing.setMop(v.getMop());
-
 
446
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
-
 
447
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
-
 
448
                    tVendorPricing.setNlc(v.getNlc());
-
 
449
                    inventoryClient.addVendorItemPricing(tVendorPricing);
-
 
450
                    logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
-
 
451
                }
-
 
452
            }
-
 
453
            
-
 
454
            Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
-
 
455
            if(sourcePricings != null && !sourcePricings.isEmpty()) {
-
 
456
                in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricings;
-
 
457
                for(SourcePricings s : sourcePricings.values()) {
-
 
458
                	tSourcePricings = new in.shop2020.model.v1.catalog.SourceItemPricing();
-
 
459
                	tSourcePricings.setSourceId(s.getSourceId());
-
 
460
                    tSourcePricings.setItemId(item.getId());
-
 
461
                    tSourcePricings.setMrp(s.getMrp());
-
 
462
                    tSourcePricings.setSellingPrice(s.getSellingPrice());
-
 
463
                    catalogClient.addSourceItemPricing(tSourcePricings);
-
 
464
                    logger.info("Updated SourceItemPricing: " + tSourcePricings.toString());
-
 
465
                }
-
 
466
            }
-
 
467
            
-
 
468
        }catch(Exception e){
-
 
469
            logger.error("Error while updating item: ", e);
-
 
470
            return false;
-
 
471
        }
-
 
472
        return true;
-
 
473
    }
-
 
474
 
-
 
475
    @Override
-
 
476
    public List<Long> getMonitoredWarehouseIdsForVendors(List<Long> vendorIds){
-
 
477
    	List<Long> monitoredWarehouseids=null;
-
 
478
    	 try {
-
 
479
			InventoryClient inventoryServiceClient = new InventoryClient();
341
			InventoryClient inventoryServiceClient = new InventoryClient();
-
 
342
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
343
			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
-
 
344
			PrivateDeal privateDeal = catalogClient.getPrivateDealDetails(itemId);
-
 
345
			Long catalogItemId = thriftItem.getCatalogItemId();
-
 
346
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByCatalogId(catalogItemId);
-
 
347
			List <Long> sameItemsWithDifferentColors = new ArrayList<Long>();
-
 
348
			if(thriftItems.size()>1){
-
 
349
				for(in.shop2020.model.v1.catalog.Item tItem : thriftItems ){
-
 
350
					Long id = tItem.getId();
-
 
351
					if(!id.equals(itemId)){
-
 
352
						sameItemsWithDifferentColors.add(id); 
-
 
353
					}
-
 
354
				}
-
 
355
			}
-
 
356
			List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
-
 
357
			Map<Long,String> stateIdNameMap = inventoryClient.getStateMaster();
-
 
358
 
-
 
359
			List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
-
 
360
			List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
-
 
361
			List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
-
 
362
			in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
-
 
363
			ItemStockPurchaseParams stockPurchaseParams = inventoryClient.getItemStockPurchaseParams(thriftItem.getId());
-
 
364
			Map<Long, String> saleHistory = new HashMap<Long, String>();
-
 
365
			List<OOSStatus> oosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 0, 5);
-
 
366
			String lastNdaySale = getOosString(oosStatuses);
-
 
367
			saleHistory.put(0L,lastNdaySale);
-
 
368
			List<OOSStatus> webOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 1, 5);
-
 
369
			String webLastNdaySale = getOosString(webOosStatuses);
-
 
370
			saleHistory.put(1L,webLastNdaySale);
-
 
371
			List<OOSStatus> amzOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 3, 5);
-
 
372
			String amzLastNdaySale = getOosString(amzOosStatuses);
-
 
373
			saleHistory.put(3L,amzLastNdaySale);
-
 
374
			List<OOSStatus> ebayOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 6, 5);
-
 
375
			String ebayLastNdaySale = getOosString(ebayOosStatuses);
-
 
376
			saleHistory.put(6L,ebayLastNdaySale);
-
 
377
			List<OOSStatus> spdOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 7, 5);
-
 
378
			String spdLastNdaySale = getOosString(spdOosStatuses);
-
 
379
			saleHistory.put(7L,spdLastNdaySale);
-
 
380
			List<OOSStatus> fktOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 8, 5);
-
 
381
			String fktLastNdaySale = getOosString(fktOosStatuses);
-
 
382
			saleHistory.put(8L,fktLastNdaySale);
-
 
383
			Long freebieItemId = catalogClient.getFreebieForItem(thriftItem.getId());
-
 
384
			List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
-
 
385
			Map<String,String> stateNameVatPercentageMap = new HashMap<String,String>();
-
 
386
			catalogClient =  new CatalogClient("catalog_service_server_host_prod","catalog_service_server_port").getClient();
-
 
387
			double vatrate;
-
 
388
			for(Entry<Long, String> entry:stateIdNameMap.entrySet()){
-
 
389
				try{
-
 
390
					vatrate= catalogClient.getVatPercentageForItem(thriftItem.getId(),entry.getKey(),thriftItem.getSellingPrice());
-
 
391
				}
-
 
392
				catch(CatalogServiceException cex){
-
 
393
					vatrate = -1.0;
-
 
394
				}
-
 
395
				stateNameVatPercentageMap.put(entry.getValue(),String.valueOf(vatrate));
-
 
396
			}
-
 
397
			Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers, stockPurchaseParams, saleHistory, freebieItemId , stateNameVatPercentageMap,privateDeal);
-
 
398
			it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
-
 
399
			return it;
-
 
400
		}catch(Exception e){
-
 
401
			logger.error("Error while getting the item from the catalog service", e);
-
 
402
		}
-
 
403
		return null;
-
 
404
	}
-
 
405
 
-
 
406
	private String getOosString(List<OOSStatus> oosStatuses){
-
 
407
		String lastNdaySale = "";
-
 
408
		for(OOSStatus oosStatus : oosStatuses){
-
 
409
			if(oosStatus.isIs_oos()){
-
 
410
				lastNdaySale += "X-";
-
 
411
			}else{
-
 
412
				lastNdaySale += oosStatus.getNum_orders() + "-";
-
 
413
			}
-
 
414
		}
-
 
415
		if(lastNdaySale!=""){
-
 
416
			lastNdaySale = lastNdaySale.substring(0, lastNdaySale.length()-1);
-
 
417
		}
-
 
418
		return lastNdaySale;
-
 
419
	}
-
 
420
 
-
 
421
	@Override
-
 
422
	public boolean updateItem(Item item) {
-
 
423
		logger.info("Updating item with Id: " + item.getId());
-
 
424
		try{
-
 
425
			CatalogClient catalogServiceClient = new CatalogClient();
-
 
426
			Client catalogClient = catalogServiceClient.getClient();
-
 
427
			InventoryClient inventoryServiceClient = new InventoryClient();
480
			 in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
428
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
429
 
-
 
430
			in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
-
 
431
			in.shop2020.model.v1.catalog.PrivateDeal privateDeal = new in.shop2020.model.v1.catalog.PrivateDeal(); 
-
 
432
			privateDeal.setItem_id(item.getId());
-
 
433
			privateDeal.setDealFreebieItemId(item.getPrivateDeal().getDealFreebieItemId());
-
 
434
			privateDeal.setDealPrice(item.getPrivateDeal().getDealPrice());
-
 
435
			privateDeal.setDealText(item.getPrivateDeal().getDealText());
-
 
436
			privateDeal.setDealFreebieOption(item.getPrivateDeal().getDealFreebieOption());
-
 
437
			privateDeal.setDealTextOption(item.getPrivateDeal().getDealTextOption());
-
 
438
			if(item.getPrivateDeal().getEndDate()!=null){
-
 
439
				privateDeal.setEndDate(item.getPrivateDeal().getEndDate());
-
 
440
			}
-
 
441
			if(item.getPrivateDeal().getStartDate()!=null){
-
 
442
				privateDeal.setStartDate(item.getPrivateDeal().getStartDate());
-
 
443
			}
-
 
444
			privateDeal.setIsCod(item.getPrivateDeal().isCod());
-
 
445
			privateDeal.setRank(item.getPrivateDeal().getRank());
-
 
446
			privateDeal.setIsActive(item.getPrivateDeal().isActive());
-
 
447
			if(privateDeal.getDealPrice() > 0 && privateDeal.getEndDate()!=0 && privateDeal.getStartDate()!=0){
-
 
448
				logger.info("Updating Private deal: " + item.getId());
-
 
449
				logger.info("Deal Price "+privateDeal.getDealPrice());
-
 
450
				logger.info("Deal Start Date "+privateDeal.getStartDate());
-
 
451
				logger.info("Deal End Date "+privateDeal.getEndDate());
-
 
452
				logger.info("Has COD on deal: " + privateDeal.isIsCod());
-
 
453
				logger.info("Response" + catalogClient.addOrUpdatePrivateDeal(privateDeal));
-
 
454
				logger.info("Updated Private deal: " + item.getId());
-
 
455
			}
-
 
456
			else{
-
 
457
				logger.info("Skipping Private deal: " + item.getId());
-
 
458
				logger.info("Deal Price "+privateDeal.getDealPrice());
-
 
459
				logger.info("Deal Start Date "+privateDeal.getStartDate());
-
 
460
				logger.info("Deal End Date "+privateDeal.getEndDate());
-
 
461
			}
-
 
462
			setThriftItemParams(tItem, item);
-
 
463
			long rItemId;
-
 
464
			if((rItemId = catalogClient.updateItem(tItem)) != item.getId()) {
-
 
465
				logger.error("Error updating item, returned Item Id: " + rItemId);
-
 
466
				return false;
-
 
467
			}
-
 
468
			logger.info("Successfully updated item with id: " + item.getId());
-
 
469
 
-
 
470
			Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();
-
 
471
			if(vendorMappings != null && !vendorMappings.isEmpty()) {
-
 
472
				in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
-
 
473
 
-
 
474
				for(Entry<String, VendorItemMapping> e : vendorMappings.entrySet()) {
-
 
475
					tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
-
 
476
					VendorItemMapping v = e.getValue();
-
 
477
					tVendorMapping.setVendorId(v.getVendorId());
-
 
478
					tVendorMapping.setItemKey(v.getItemKey());
-
 
479
					tVendorMapping.setItemId(item.getId());
-
 
480
					inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
-
 
481
					logger.info("Updates VendorItemMapping: " + tVendorMapping.toString());
-
 
482
				}
-
 
483
			}
-
 
484
 
-
 
485
			if(item.getMinStockLevel()!=0 || item.getNumOfDaysStock()!=0) {
-
 
486
				inventoryClient.updateItemStockPurchaseParams(item.getId(), item.getNumOfDaysStock(),
-
 
487
						item.getMinStockLevel());
-
 
488
			}
-
 
489
 
-
 
490
			if(item.getFreebieItemId()!=null) {
-
 
491
				in.shop2020.model.v1.catalog.FreebieItem freebieItem = new in.shop2020.model.v1.catalog.FreebieItem();
-
 
492
				freebieItem.setItemId(item.getId());
-
 
493
				freebieItem.setFreebieItemId(item.getFreebieItemId());
-
 
494
				catalogClient.addOrUpdateFreebieForItem(freebieItem);
-
 
495
			}
-
 
496
 
-
 
497
			Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
-
 
498
			if(vendorPricings != null && !vendorPricings.isEmpty()) {
-
 
499
				in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
-
 
500
				for(VendorPricings v : vendorPricings.values()) {
-
 
501
					tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
-
 
502
					tVendorPricing.setVendorId(v.getVendorId());
-
 
503
					tVendorPricing.setItemId(item.getId());
-
 
504
					tVendorPricing.setMop(v.getMop());
-
 
505
					tVendorPricing.setTransferPrice(v.getTransferPrice());
-
 
506
					tVendorPricing.setDealerPrice(v.getDealerPrice());
-
 
507
					tVendorPricing.setNlc(v.getNlc());
-
 
508
					inventoryClient.addVendorItemPricing(tVendorPricing);
-
 
509
					logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
-
 
510
				}
-
 
511
			}
-
 
512
 
-
 
513
			Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
-
 
514
			if(sourcePricings != null && !sourcePricings.isEmpty()) {
-
 
515
				in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricings;
-
 
516
				for(SourcePricings s : sourcePricings.values()) {
-
 
517
					tSourcePricings = new in.shop2020.model.v1.catalog.SourceItemPricing();
-
 
518
					tSourcePricings.setSourceId(s.getSourceId());
-
 
519
					tSourcePricings.setItemId(item.getId());
-
 
520
					tSourcePricings.setMrp(s.getMrp());
-
 
521
					tSourcePricings.setSellingPrice(s.getSellingPrice());
-
 
522
					catalogClient.addSourceItemPricing(tSourcePricings);
-
 
523
					logger.info("Updated SourceItemPricing: " + tSourcePricings.toString());
-
 
524
				}
-
 
525
			}
-
 
526
 
-
 
527
		}catch(Exception e){
-
 
528
			logger.error("Error while updating item: ", e);
-
 
529
			return false;
-
 
530
		}
-
 
531
		return true;
-
 
532
	}
-
 
533
 
-
 
534
	@Override
-
 
535
	public List<Long> getMonitoredWarehouseIdsForVendors(List<Long> vendorIds){
-
 
536
		List<Long> monitoredWarehouseids=null;
-
 
537
		try {
-
 
538
			InventoryClient inventoryServiceClient = new InventoryClient();
-
 
539
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
481
			 monitoredWarehouseids = inventoryClient.getMonitoredWarehouseForVendors(vendorIds);
540
			monitoredWarehouseids = inventoryClient.getMonitoredWarehouseForVendors(vendorIds);
482
		} catch (Exception e) {
541
		} catch (Exception e) {
483
			logger.error("Error while getting Monitored warehouse for vendor: ", e);
542
			logger.error("Error while getting Monitored warehouse for vendor: ", e);
484
		}
543
		}
485
		return monitoredWarehouseids;
544
		return monitoredWarehouseids;
486
        
545
 
487
    }
546
	}
488
    
547
 
489
    @Override
548
	@Override
490
    public List<ItemWarehouse> getignoredInventoryUpdateItemsIdsWarehouseIds(){
549
	public List<ItemWarehouse> getignoredInventoryUpdateItemsIdsWarehouseIds(){
491
		List<ItemWarehouse> ignoredItemIdwarehouseIdList = new ArrayList<ItemWarehouse>();
550
		List<ItemWarehouse> ignoredItemIdwarehouseIdList = new ArrayList<ItemWarehouse>();
492
    	try {
551
		try {
493
 
552
 
494
			InventoryClient inventoryServiceClient = new InventoryClient();
553
			InventoryClient inventoryServiceClient = new InventoryClient();
495
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
554
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
496
			List<IgnoredInventoryUpdateItems> ignoredInventoryUpdateItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
555
			List<IgnoredInventoryUpdateItems> ignoredInventoryUpdateItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
497
			for(IgnoredInventoryUpdateItems ignoredInventoryUpdateItem:ignoredInventoryUpdateItems){
556
			for(IgnoredInventoryUpdateItems ignoredInventoryUpdateItem:ignoredInventoryUpdateItems){
498
				ignoredItemIdwarehouseIdList.add(new ItemWarehouse(ignoredInventoryUpdateItem.getItemId(),ignoredInventoryUpdateItem.getWarehouseId()));
557
				ignoredItemIdwarehouseIdList.add(new ItemWarehouse(ignoredInventoryUpdateItem.getItemId(),ignoredInventoryUpdateItem.getWarehouseId()));
499
			}
558
			}
500
			
559
 
501
			
560
 
502
		} catch (Exception e) {
561
		} catch (Exception e) {
503
			logger.error("Error while getting Monitored warehouseid and itemid : ", e);
562
			logger.error("Error while getting Monitored warehouseid and itemid : ", e);
504
		}
563
		}
505
		return ignoredItemIdwarehouseIdList;
564
		return ignoredItemIdwarehouseIdList;
506
    	
565
 
507
    }
566
	}
508
    @Override
567
	@Override
509
    public Map<Long, String> getAllVendors() {
568
	public Map<Long, String> getAllVendors() {
510
        Map<Long, String> vendorMap = new HashMap<Long, String>();
569
		Map<Long, String> vendorMap = new HashMap<Long, String>();
511
        try {
570
		try {
512
            InventoryClient inventoryServiceClient = new InventoryClient();
571
			InventoryClient inventoryServiceClient = new InventoryClient();
513
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
572
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
514
            
573
 
515
            List<in.shop2020.model.v1.inventory.Vendor> vendors = inventoryClient.getAllVendors();
574
			List<in.shop2020.model.v1.inventory.Vendor> vendors = inventoryClient.getAllVendors();
516
 
575
 
517
            for(in.shop2020.model.v1.inventory.Vendor v : vendors) {
576
			for(in.shop2020.model.v1.inventory.Vendor v : vendors) {
518
                vendorMap.put(v.getId(), v.getName());
577
				vendorMap.put(v.getId(), v.getName());
519
            }
578
			}
520
        } catch (Exception e) {
579
		} catch (Exception e) {
521
            logger.error("Error while getting all the vendors: ", e);
580
			logger.error("Error while getting all the vendors: ", e);
522
        }
581
		}
523
        return vendorMap;
582
		return vendorMap;
524
    }
583
	}
525
 
584
 
526
    @Override
585
	@Override
527
    public Map<Long, String> getAllSources() {
586
	public Map<Long, String> getAllSources() {
528
        Map<Long, String> sourceMap = new HashMap<Long, String>();
587
		Map<Long, String> sourceMap = new HashMap<Long, String>();
529
        try {
588
		try {
530
            CatalogClient catalogServiceClient = new CatalogClient();
589
			CatalogClient catalogServiceClient = new CatalogClient();
531
            Client catalogClient = catalogServiceClient.getClient();
590
			Client catalogClient = catalogServiceClient.getClient();
532
 
591
 
533
            List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
592
			List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
534
 
593
 
535
            for(in.shop2020.model.v1.catalog.Source s : sources) {
594
			for(in.shop2020.model.v1.catalog.Source s : sources) {
536
            	sourceMap.put(s.getId(), s.getName());
595
				sourceMap.put(s.getId(), s.getName());
537
            }
596
			}
538
        } catch (Exception e) {
597
		} catch (Exception e) {
539
            logger.error("Error while getting all the vendors: ", e);
598
			logger.error("Error while getting all the vendors: ", e);
540
        }
599
		}
541
        return sourceMap;
600
		return sourceMap;
542
    }
601
	}
543
 
602
 
544
    @Override
603
	@Override
545
    public Map<Long, String> getShippingWarehouses() {
604
	public Map<Long, String> getShippingWarehouses() {
546
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
605
		Map<Long, String> warehouseMap = new HashMap<Long, String>();
547
        Set<Long> shippingLocations = new HashSet<Long>();
606
		Set<Long> shippingLocations = new HashSet<Long>();
548
        try {
607
		try {
549
            InventoryClient inventoryServiceClient = new InventoryClient();
608
			InventoryClient inventoryServiceClient = new InventoryClient();
550
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
609
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
551
            
610
 
552
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
611
			List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
553
 
612
 
554
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
613
			for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
555
                shippingLocations.add(warehouse.getShippingWarehouseId());
614
				shippingLocations.add(warehouse.getShippingWarehouseId());
556
            }
615
			}
557
            
616
 
558
            for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
617
			for(in.shop2020.model.v1.inventory.Warehouse warehouse : warehouses) {
559
                if (shippingLocations.contains(warehouse.getId())) {
618
				if (shippingLocations.contains(warehouse.getId())) {
560
                    warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
619
					warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
561
                }                
620
				}                
562
            }
621
			}
563
        } catch (Exception e) {
622
		} catch (Exception e) {
564
            logger.error("Error while getting all the warehouses:", e );
623
			logger.error("Error while getting all the warehouses:", e );
565
        }
624
		}
566
        return warehouseMap;
625
		return warehouseMap;
567
    }
626
	}
568
 
627
 
569
    @Override
628
	@Override
570
    public Map<Long, String> getAllWarehouses() {
629
	public Map<Long, String> getAllWarehouses() {
571
        Map<Long, String> warehouseMap = new HashMap<Long, String>();
630
		Map<Long, String> warehouseMap = new HashMap<Long, String>();
572
        try {
631
		try {
573
        	InventoryClient inventoryServiceClient = new InventoryClient();
632
			InventoryClient inventoryServiceClient = new InventoryClient();
574
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
633
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
575
 
634
 
576
            List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
635
			List<in.shop2020.model.v1.inventory.Warehouse> warehouses = inventoryClient.getAllWarehouses(true);
577
 
636
 
578
            for(in.shop2020.model.v1.inventory.Warehouse w : warehouses) {
637
			for(in.shop2020.model.v1.inventory.Warehouse w : warehouses) {
579
                warehouseMap.put(w.getId(), w.getDisplayName());
638
				warehouseMap.put(w.getId(), w.getDisplayName());
580
            }
639
			}
581
        } catch (Exception e) {
640
		} catch (Exception e) {
582
            logger.error("Error while getting all the warehouses:", e );
641
			logger.error("Error while getting all the warehouses:", e );
583
        }
642
		}
584
        return warehouseMap;
643
		return warehouseMap;
585
    }
644
	}
586
 
645
 
587
    @Override
646
	@Override
588
    public long addItem(Item item) {
647
	public long addItem(Item item) {
589
        long itemId = 0;
648
		long itemId = 0;
590
        try {
649
		try {
591
            CatalogClient catalogServiceClient = new CatalogClient();
650
			CatalogClient catalogServiceClient = new CatalogClient();
592
            Client catalogClient = catalogServiceClient.getClient();
651
			Client catalogClient = catalogServiceClient.getClient();
593
            InventoryClient inventoryServiceClient = new InventoryClient();
652
			InventoryClient inventoryServiceClient = new InventoryClient();
594
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
653
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
595
 
654
 
596
            in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
655
			in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
597
            setThriftItemParams(tItem, item);
656
			setThriftItemParams(tItem, item);
598
            itemId = catalogClient.addItem(tItem);
657
			itemId = catalogClient.addItem(tItem);
599
 
658
			PrivateDeal privateDeal = catalogClient.getPrivateDealDetails(item.getId());
600
            Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
659
			if(item.getPrivateDeal().getDealPrice() != 0 || item.getPrivateDeal().getDealFreebieItemId() != 0){
601
            if(vendorPricings != null && !vendorPricings.isEmpty()) {
660
				privateDeal.setItem_id(item.getId());
602
                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
661
				privateDeal.setDealFreebieItemId(item.getPrivateDeal().getDealFreebieItemId());
603
                for(VendorPricings v : vendorPricings.values()) {
662
				privateDeal.setDealPrice(item.getPrivateDeal().getDealPrice());
604
                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
663
				catalogClient.addOrUpdatePrivateDeal(privateDeal);
605
                    tVendorPricing.setVendorId(v.getVendorId());
664
			}
606
                    tVendorPricing.setItemId(itemId);
665
			Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
607
                    tVendorPricing.setMop(v.getMop());
666
			if(vendorPricings != null && !vendorPricings.isEmpty()) {
608
                    tVendorPricing.setTransferPrice(v.getTransferPrice());
667
				in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
609
                    tVendorPricing.setNlc(v.getNlc());
668
				for(VendorPricings v : vendorPricings.values()) {
610
                    tVendorPricing.setDealerPrice(v.getDealerPrice());
669
					tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
611
                    inventoryClient.addVendorItemPricing(tVendorPricing);
670
					tVendorPricing.setVendorId(v.getVendorId());
612
                }
671
					tVendorPricing.setItemId(itemId);
613
            }
672
					tVendorPricing.setMop(v.getMop());
614
 
673
					tVendorPricing.setTransferPrice(v.getTransferPrice());
615
            Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();
674
					tVendorPricing.setNlc(v.getNlc());
616
            if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
675
					tVendorPricing.setDealerPrice(v.getDealerPrice());
617
                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
676
					inventoryClient.addVendorItemPricing(tVendorPricing);
618
                for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {
677
				}
619
                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
678
			}
620
                    VendorItemMapping v = e.getValue();
679
 
621
                    tVendorMapping.setVendorId(v.getVendorId());
680
			Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();
622
                    tVendorMapping.setItemKey(v.getItemKey());
681
			if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
623
                    tVendorMapping.setItemId(itemId);
682
				in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
624
                    inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
683
				for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {
625
                }
684
					tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
626
            }
685
					VendorItemMapping v = e.getValue();
627
            
686
					tVendorMapping.setVendorId(v.getVendorId());
628
        	inventoryClient.updateItemStockPurchaseParams(itemId, item.getNumOfDaysStock(),
687
					tVendorMapping.setItemKey(v.getItemKey());
629
        			item.getMinStockLevel());
688
					tVendorMapping.setItemId(itemId);
630
        	
689
					inventoryClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
631
        	if(item.getFreebieItemId()!=null && item.getFreebieItemId()!=0) {
690
				}
632
        		in.shop2020.model.v1.catalog.FreebieItem freebieItem = 
691
			}
633
        			new in.shop2020.model.v1.catalog.FreebieItem();
692
 
634
        		freebieItem.setItemId(itemId);
693
			inventoryClient.updateItemStockPurchaseParams(itemId, item.getNumOfDaysStock(),
635
        		freebieItem.setFreebieItemId(item.getFreebieItemId());
694
					item.getMinStockLevel());
636
        		catalogClient.addOrUpdateFreebieForItem(freebieItem);
695
 
637
        	}
696
			if(item.getFreebieItemId()!=null && item.getFreebieItemId()!=0) {
638
        	
697
				in.shop2020.model.v1.catalog.FreebieItem freebieItem = 
639
        } catch (Exception e) {
698
					new in.shop2020.model.v1.catalog.FreebieItem();
640
            logger.error("Error while adding an item: ", e);
699
				freebieItem.setItemId(itemId);
641
        }
700
				freebieItem.setFreebieItemId(item.getFreebieItemId());
642
        return itemId;
701
				catalogClient.addOrUpdateFreebieForItem(freebieItem);
643
    }
702
			}
644
 
703
 
645
    @Override
704
		} catch (Exception e) {
646
    public long checkSimilarItem(String brand, String modelNumber, String modelName, String color) {
705
			logger.error("Error while adding an item: ", e);
647
 
706
		}
648
        try {
707
		return itemId;
649
            CatalogClient catalogServiceClient = new CatalogClient();
708
	}
650
            Client catalogClient = catalogServiceClient.getClient();
709
 
651
            return catalogClient.checkSimilarItem(brand, modelNumber, modelName, color);
710
	@Override
652
        } catch (Exception e) {
711
	public long checkSimilarItem(String brand, String modelNumber, String modelName, String color) {
653
            logger.error("Error while checking for a similar item: ", e);
712
 
654
        }
713
		try {
655
        return 0;
714
			CatalogClient catalogServiceClient = new CatalogClient();
656
    }
715
			Client catalogClient = catalogServiceClient.getClient();
657
 
716
			return catalogClient.checkSimilarItem(brand, modelNumber, modelName, color);
658
    private void setThriftItemParams(in.shop2020.model.v1.catalog.Item tItem, Item item) {
717
		} catch (Exception e) {
659
        tItem.setId(tItem.getId());
718
			logger.error("Error while checking for a similar item: ", e);
660
        tItem.setProductGroup(item.getProductGroup());
719
		}
661
        tItem.setBrand(item.getBrand());
720
		return 0;
662
        tItem.setModelName(item.getModelName());
721
	}
663
        tItem.setModelNumber(item.getModelNumber());
722
 
664
        tItem.setColor(item.getColor());
723
	private void setThriftItemParams(in.shop2020.model.v1.catalog.Item tItem, Item item) {
665
        tItem.setShowSellingPrice(item.isShowSellingPrice());
724
		tItem.setId(tItem.getId());
666
        tItem.setHoldOverride(item.isHoldOverride());
725
		tItem.setProductGroup(item.getProductGroup());
667
        tItem.setStatus_description(item.getItemStatusDesc());
726
		tItem.setBrand(item.getBrand());
668
        tItem.setComments(item.getComments());
727
		tItem.setModelName(item.getModelName());
669
 
728
		tItem.setModelNumber(item.getModelNumber());
670
        if(item.getMrp() != null) {
729
		tItem.setColor(item.getColor());
671
            tItem.setMrp(item.getMrp());
730
		tItem.setShowSellingPrice(item.isShowSellingPrice());
672
        }
731
		tItem.setHoldOverride(item.isHoldOverride());
673
        
732
		tItem.setStatus_description(item.getItemStatusDesc());
674
        if(item.getCatalogItemId() != null) {
733
		tItem.setComments(item.getComments());
675
            tItem.setCatalogItemId(item.getCatalogItemId());
734
 
676
        }
735
		if(item.getMrp() != null) {
677
        
736
			tItem.setMrp(item.getMrp());
678
        if(item.getSellingPrice() != null) {
737
		}
679
            tItem.setSellingPrice(item.getSellingPrice());
738
 
680
        }
739
		if(item.getCatalogItemId() != null) {
681
        
740
			tItem.setCatalogItemId(item.getCatalogItemId());
682
        if(item.getWeight() != null) {
741
		}
683
            tItem.setWeight(item.getWeight());
742
 
684
        }
743
		if(item.getSellingPrice() != null) {
685
        
744
			tItem.setSellingPrice(item.getSellingPrice());
686
        if(item.getExpectedDelay() != null) {
745
		}
687
            tItem.setExpectedDelay(item.getExpectedDelay());
746
 
688
        }
747
		if(item.getWeight() != null) {
689
        
748
			tItem.setWeight(item.getWeight());
690
        tItem.setIsWarehousePreferenceSticky(item.isWarehouseStickiness());
749
		}
691
        
750
 
692
        if(item.getPreferredVendor() != null) {
751
		if(item.getExpectedDelay() != null) {
693
            tItem.setPreferredVendor(item.getPreferredVendor());
752
			tItem.setExpectedDelay(item.getExpectedDelay());
694
        }
753
		}
695
        tItem.setPreferredInsurer(item.getPreferredInsurer());
754
 
696
 
755
		tItem.setIsWarehousePreferenceSticky(item.isWarehouseStickiness());
697
        if(item.getAsin() != null) {
756
 
698
            tItem.setAsin(item.getAsin());
757
		if(item.getPreferredVendor() != null) {
699
        }
758
			tItem.setPreferredVendor(item.getPreferredVendor());
700
        if(item.getHoldInventory()!= null) {
759
		}
701
        	tItem.setHoldInventory(item.getHoldInventory());
760
		tItem.setPreferredInsurer(item.getPreferredInsurer());
702
        }
761
 
703
        else{
762
		if(item.getAsin() != null) {
704
        	tItem.setHoldInventory(0);
763
			tItem.setAsin(item.getAsin());
705
        }	
764
		}
706
        if(item.getDefaultInventory()!=null){
765
		if(item.getHoldInventory()!= null) {
707
        	tItem.setDefaultInventory(item.getDefaultInventory());
766
			tItem.setHoldInventory(item.getHoldInventory());
708
        }
767
		}
709
        else{
768
		else{
710
        	tItem.setDefaultInventory(0);
769
			tItem.setHoldInventory(0);
711
        }
770
		}	
712
        tItem.setBestDealText(item.getBestDealsText());
771
		if(item.getDefaultInventory()!=null){
713
        tItem.setBestDealsDetailsText(item.getBestDealsDetailsText());
772
			tItem.setDefaultInventory(item.getDefaultInventory());
714
        tItem.setBestDealsDetailsLink(item.getBestDealsDetailsLink());
773
		}
715
        if(item.getBestDealsValue() != null) {
774
		else{
716
            tItem.setBestDealValue(item.getBestDealsValue());
775
			tItem.setDefaultInventory(0);
717
        }
776
		}
718
        
777
		tItem.setBestDealText(item.getBestDealsText());
719
        if(item.getBestSellingRank() != null) {
778
		tItem.setBestDealsDetailsText(item.getBestDealsDetailsText());
720
            tItem.setBestSellingRank(item.getBestSellingRank());
779
		tItem.setBestDealsDetailsLink(item.getBestDealsDetailsLink());
721
        }
780
		if(item.getBestDealsValue() != null) {
722
        
781
			tItem.setBestDealValue(item.getBestDealsValue());
723
        tItem.setDefaultForEntity(item.isDefaultForEntity());
782
		}
724
        tItem.setRisky(item.isRisky());
783
 
725
        tItem.setHasItemNo(item.isHasItemNo());
784
		if(item.getBestSellingRank() != null) {
726
        
785
			tItem.setBestSellingRank(item.getBestSellingRank());
727
        if(item.isItemType()) {
786
		}
728
        	tItem.setType(ItemType.SERIALIZED);
787
 
729
        }
788
		tItem.setDefaultForEntity(item.isDefaultForEntity());
730
        else {
789
		tItem.setRisky(item.isRisky());
731
        	tItem.setType(ItemType.NON_SERIALIZED);
790
		tItem.setHasItemNo(item.isHasItemNo());
732
        }
791
 
733
        
792
		if(item.isItemType()) {
734
        if(item.getStartDate() != null) {
793
			tItem.setType(ItemType.SERIALIZED);
735
            tItem.setStartDate(item.getStartDate());
794
		}
736
        }
795
		else {
737
        
796
			tItem.setType(ItemType.NON_SERIALIZED);
738
        if(item.getExpectedArrivalDate() != null) {
797
		}
739
        	tItem.setExpectedArrivalDate(item.getExpectedArrivalDate());
798
 
740
        } else {
799
		if(item.getStartDate() != null) {
741
        	tItem.unsetComingSoonStartDate();
800
			tItem.setStartDate(item.getStartDate());
742
        	tItem.unsetExpectedArrivalDate();
801
		}
743
        	if(status.COMING_SOON.equals(tItem.getItemStatus())){
802
 
744
        		tItem.setItemStatus(status.CONTENT_COMPLETE);
803
		if(item.getExpectedArrivalDate() != null) {
745
        		tItem.setStatus_description("Content generation completed");
804
			tItem.setExpectedArrivalDate(item.getExpectedArrivalDate());
746
        	}
805
		} else {
747
        }
806
			tItem.unsetComingSoonStartDate();
748
 
807
			tItem.unsetExpectedArrivalDate();
749
        if(item.getComingSoonStartDate() != null) {
808
			if(status.COMING_SOON.equals(tItem.getItemStatus())){
750
        	tItem.setComingSoonStartDate(item.getComingSoonStartDate());
809
				tItem.setItemStatus(status.CONTENT_COMPLETE);
751
        } else {
810
				tItem.setStatus_description("Content generation completed");
752
        	tItem.unsetComingSoonStartDate();
811
			}
753
        }
812
		}
754
        
813
 
755
        if(item.getRetireDate() != null) {
814
		if(item.getComingSoonStartDate() != null) {
756
            tItem.setRetireDate(item.getRetireDate());
815
			tItem.setComingSoonStartDate(item.getComingSoonStartDate());
757
        }
816
		} else {
758
        
817
			tItem.unsetComingSoonStartDate();
759
        tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());
818
		}
760
    }
819
 
761
 
820
		if(item.getRetireDate() != null) {
762
    @Override
821
			tItem.setRetireDate(item.getRetireDate());
763
    public void pauseItem(long itemId) {
822
		}
764
        try {
823
 
765
            CatalogClient catalogServiceClient = new CatalogClient();
824
		tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());
766
            Client catalogClient = catalogServiceClient.getClient();
825
	}
767
 
826
 
768
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
827
	@Override
769
        } catch (Exception e) {
828
	public void pauseItem(long itemId) {
770
            logger.error("Error while pausing the item: " + itemId, e);
829
		try {
771
        }
830
			CatalogClient catalogServiceClient = new CatalogClient();
772
 
831
			Client catalogClient = catalogServiceClient.getClient();
773
    }
832
 
774
 
833
			catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
775
    @Override
834
		} catch (Exception e) {
776
    public void markInProcess(long itemId) {
835
			logger.error("Error while pausing the item: " + itemId, e);
777
        try {
836
		}
778
            CatalogClient catalogServiceClient = new CatalogClient();
837
 
779
            Client catalogClient = catalogServiceClient.getClient();
838
	}
780
 
839
 
781
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
840
	@Override
782
        } catch (Exception e) {
841
	public void markInProcess(long itemId) {
783
            logger.error("Error while marking in-process the item: " + itemId, e);
842
		try {
784
        }
843
			CatalogClient catalogServiceClient = new CatalogClient();
785
    }
844
			Client catalogClient = catalogServiceClient.getClient();
786
 
845
 
787
    @Override
846
			catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
788
    public void phaseoutItem(long itemId) {
847
		} catch (Exception e) {
789
        try {
848
			logger.error("Error while marking in-process the item: " + itemId, e);
790
            CatalogClient catalogServiceClient = new CatalogClient();
849
		}
791
            Client catalogClient = catalogServiceClient.getClient();
850
	}
792
 
851
 
793
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
852
	@Override
794
        } catch (Exception e) {
853
	public void phaseoutItem(long itemId) {
795
            logger.error("Error while phasing out the item: " + itemId, e);
854
		try {
796
        }
855
			CatalogClient catalogServiceClient = new CatalogClient();
797
    }
856
			Client catalogClient = catalogServiceClient.getClient();
798
 
857
 
799
    @Override
858
			catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
800
    public void activateItem(long itemId) {
859
		} catch (Exception e) {
801
        try {
860
			logger.error("Error while phasing out the item: " + itemId, e);
802
            CatalogClient catalogServiceClient = new CatalogClient();
861
		}
803
            Client catalogClient = catalogServiceClient.getClient();
862
	}
804
 
863
 
805
            catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
864
	@Override
806
        } catch (Exception e) {
865
	public void activateItem(long itemId) {
807
            logger.error("Error while activating the item: " + itemId, e);
866
		try {
808
        }
867
			CatalogClient catalogServiceClient = new CatalogClient();
809
    }
868
			Client catalogClient = catalogServiceClient.getClient();
810
 
869
 
811
    @Override
870
			catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
812
    public boolean changeItemRiskyFlag(long itemId, boolean risky) {
871
		} catch (Exception e) {
813
        try {
872
			logger.error("Error while activating the item: " + itemId, e);
814
            logger.info("Updating risky flag for item id: " + itemId + " to " + risky);
873
		}
815
            // Initialize client for staging server
874
	}
816
            CatalogClient catalogServiceClient = new CatalogClient();
875
 
817
            Client catalogClient = catalogServiceClient.getClient();
876
	@Override
818
 
877
	public boolean changeItemRiskyFlag(long itemId, boolean risky) {
819
            // Initialize client for production server
878
		try {
820
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
879
			logger.info("Updating risky flag for item id: " + itemId + " to " + risky);
821
                    ConfigClientKeys.catalog_service_server_port.toString());
880
			// Initialize client for staging server
822
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
881
			CatalogClient catalogServiceClient = new CatalogClient();
823
            catalogClient.changeItemRiskyFlag(itemId, risky);
882
			Client catalogClient = catalogServiceClient.getClient();
824
 
883
 
825
            try{
884
			// Initialize client for production server
826
                catalogClient_Prod.changeItemRiskyFlag(itemId, risky);
885
			CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
827
            }catch(Exception e){
886
					ConfigClientKeys.catalog_service_server_port.toString());
828
                logger.error("Error while updating item's risky flag on production", e);
887
			Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
829
                // If not able to change risky flag on production, revert on staging and return false (to show error to user).
888
			catalogClient.changeItemRiskyFlag(itemId, risky);
830
                catalogClient.changeItemRiskyFlag(itemId, !risky);        
889
 
831
                return false;
890
			try{
832
            }
891
				catalogClient_Prod.changeItemRiskyFlag(itemId, risky);
833
        } catch (Exception e) {
892
			}catch(Exception e){
834
            logger.error("Error while updating item's risky flag on staging", e);
893
				logger.error("Error while updating item's risky flag on production", e);
835
            return false;
894
				// If not able to change risky flag on production, revert on staging and return false (to show error to user).
836
        }
895
				catalogClient.changeItemRiskyFlag(itemId, !risky);        
837
        return true;
896
				return false;
838
    }
897
			}
839
 
898
		} catch (Exception e) {
840
    
899
			logger.error("Error while updating item's risky flag on staging", e);
841
    /**
900
			return false;
842
     * Retuns list of Items filtered by category (column is product_group in catalog.item table)
901
		}
843
     * This list is used to generate master sheet (excel sheet)
902
		return true;
844
     * @param category
903
	}
845
     * @param brand
904
 
846
     * @return
905
 
847
     */
906
	/**
848
    public List<Item> getItemsForMasterSheet(String category, String brand) {
907
	 * Retuns list of Items filtered by category (column is product_group in catalog.item table)
849
        List<Item> itemList = new ArrayList<Item>();
908
	 * This list is used to generate master sheet (excel sheet)
850
        try {
909
	 * @param category
851
            CatalogClient catalogServiceClient = new CatalogClient();
910
	 * @param brand
852
            Client catalogClient = catalogServiceClient.getClient();
911
	 * @return
853
            InventoryClient inventoryServiceClient = new InventoryClient();
912
	 */
854
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
913
	public List<Item> getItemsForMasterSheet(String category, String brand) {
855
            
914
		List<Item> itemList = new ArrayList<Item>();
856
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsForMasterSheet(category, brand);
915
		try {
857
            
916
			CatalogClient catalogServiceClient = new CatalogClient();
858
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
917
			Client catalogClient = catalogServiceClient.getClient();
859
                List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
918
			InventoryClient inventoryServiceClient = new InventoryClient();
860
                List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
919
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
861
                List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
920
 
862
                itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null, null, null));
921
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsForMasterSheet(category, brand);
863
            }
922
 
864
        } catch (Exception e) {
923
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
865
            logger.error("Error while getting items by category: " + category, e);
924
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
866
        }
925
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
867
        Collections.sort(itemList, new ItemsComparator());
926
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
868
        return itemList;
927
				itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null, null, null));
869
    }
928
			}
870
 
929
		} catch (Exception e) {
871
    @Override
930
			logger.error("Error while getting items by category: " + category, e);
872
    public String updateItemOnProduction(Item item) {
931
		}
873
    	if(!canPushToProduction()) {
932
		Collections.sort(itemList, new ItemsComparator());
874
    		// If we can't push to production, then return that message to user
933
		return itemList;
875
    		// else move forward with update.
934
	}
876
    		return "Maximum push to production count reached for today";
935
 
877
    	}
936
	@Override
878
    	List<Long> itemIds = item.getSameItemsWithDifferentColors();
937
	public String updateItemOnProduction(Item item) {
879
    	List<Item> items = new ArrayList<Item>();
938
		if(!canPushToProduction()) {
880
    	items.add(item);
939
			// If we can't push to production, then return that message to user
881
    	for(Long itemId : itemIds) {
940
			// else move forward with update.
882
    		try {
941
			return "Maximum push to production count reached for today";
883
    			CatalogClient catalogServiceClient = new CatalogClient();
942
		}
884
    			Client catalogClient = catalogServiceClient.getClient();
943
		List<Long> itemIds = item.getSameItemsWithDifferentColors();
885
    			InventoryClient inventoryServiceClient = new InventoryClient();
944
		List<Item> items = new ArrayList<Item>();
886
                in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
945
		items.add(item);
887
                
946
		for(Long itemId : itemIds) {
888
    			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
947
			try {
-
 
948
				CatalogClient catalogServiceClient = new CatalogClient();
-
 
949
				Client catalogClient = catalogServiceClient.getClient();
-
 
950
				InventoryClient inventoryServiceClient = new InventoryClient();
-
 
951
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
952
 
-
 
953
				in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
889
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
954
				List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
890
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
955
				List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
891
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
956
				List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
892
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null, null, null));
957
				items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null, null, null, null));
893
    		} catch (Exception e) {
958
			} catch (Exception e) {
894
    			logger.error("Could not fetch item for : " + itemId, e);
959
				logger.error("Could not fetch item for : " + itemId, e);
895
    			return "Could not push to production. No item got pushed.";
960
				return "Could not push to production. No item got pushed.";
896
    		}
961
			}
897
    	}
962
		}
898
    	for (Item it : items) {
963
		for (Item it : items) {
899
	        logger.info("Update item on production call, Item Id: " + it.getId());
964
			logger.info("Update item on production call, Item Id: " + it.getId());
900
	        
965
 
901
	        try{
966
			try{
902
	            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
967
				CatalogClient catalogServiceClient_Prod = new CatalogClient( 
903
	                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
968
						ConfigClientKeys.catalog_service_server_host_prod.toString(),
904
	                    ConfigClientKeys.catalog_service_server_port.toString());
969
						ConfigClientKeys.catalog_service_server_port.toString());
905
	            
970
 
906
	            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
971
				Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
907
	
972
 
908
	            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(it.getId());
973
				in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(it.getId());
909
	            
974
 
910
	            InventoryClient inventoryServiceClient = new InventoryClient();
975
				InventoryClient inventoryServiceClient = new InventoryClient();
911
	            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
976
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
912
	            
977
 
913
	            if(it.getMrp() != null) {
978
				if(it.getMrp() != null) {
914
	                tItem.setMrp(it.getMrp());
979
					tItem.setMrp(it.getMrp());
915
	            }
980
				}
916
	            
981
 
917
	            if(it.getSellingPrice() != null) {
982
				if(it.getSellingPrice() != null) {
918
	                tItem.setSellingPrice(it.getSellingPrice());
983
					tItem.setSellingPrice(it.getSellingPrice());
919
	            }
984
				}
920
	            
985
 
921
                tItem.setBestDealText(it.getBestDealsText());
986
				tItem.setBestDealText(it.getBestDealsText());
922
	            
987
 
923
	            if (it.getItemStatusValue()  == ItemStatus.ACTIVE.getValue() || it.getItemStatusValue()  == ItemStatus.PAUSED.getValue()) {
988
				if (it.getItemStatusValue()  == ItemStatus.ACTIVE.getValue() || it.getItemStatusValue()  == ItemStatus.PAUSED.getValue()) {
924
	            	tItem.setItemStatus(status.findByValue(it.getItemStatusValue()));
989
					tItem.setItemStatus(status.findByValue(it.getItemStatusValue()));
925
	            	tItem.setStartDate(it.getStartDate());
990
					tItem.setStartDate(it.getStartDate());
926
	            }
991
				}
927
	            long rItemId;
992
				long rItemId;
928
	            if((rItemId = catalogClient_Prod.updateItem(tItem)) != it.getId()) {
993
				if((rItemId = catalogClient_Prod.updateItem(tItem)) != it.getId()) {
929
	                logger.error("Error updating item on production, returned Item Id: " + rItemId);
994
					logger.error("Error updating item on production, returned Item Id: " + rItemId);
930
	                return "Error updating item prices on production";
995
					return "Error updating item prices on production";
931
	            }
996
				}
932
	            if(it.getFreebieItemId() !=null && it.getFreebieItemId()!=0) {
997
				if(it.getFreebieItemId() !=null && it.getFreebieItemId()!=0) {
933
	            	in.shop2020.model.v1.catalog.FreebieItem freebieItem = new in.shop2020.model.v1.catalog.FreebieItem();
998
					in.shop2020.model.v1.catalog.FreebieItem freebieItem = new in.shop2020.model.v1.catalog.FreebieItem();
934
	            	freebieItem.setItemId(it.getId());
999
					freebieItem.setItemId(it.getId());
935
	            	freebieItem.setFreebieItemId(it.getFreebieItemId());
1000
					freebieItem.setFreebieItemId(it.getFreebieItemId());
936
	            	catalogClient_Prod.addOrUpdateFreebieForItem(freebieItem);
1001
					catalogClient_Prod.addOrUpdateFreebieForItem(freebieItem);
937
	            }
1002
				}
938
	            logger.info("Successfully updated item: " + it.getId());
1003
				logger.info("Successfully updated item: " + it.getId());
939
	
1004
 
940
	            StringBuilder sb = new StringBuilder();
1005
				StringBuilder sb = new StringBuilder();
941
	            
1006
 
942
	            Map<Long, VendorPricings> vendorPricings = it.getVendorPricesMap();
1007
				Map<Long, VendorPricings> vendorPricings = it.getVendorPricesMap();
943
	            if(vendorPricings != null && !vendorPricings.isEmpty()) {
1008
				if(vendorPricings != null && !vendorPricings.isEmpty()) {
944
	                in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
1009
					in.shop2020.model.v1.inventory.VendorItemPricing tVendorPricing;
945
	                for(VendorPricings v : vendorPricings.values()) {
1010
					for(VendorPricings v : vendorPricings.values()) {
946
	                    tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
1011
						tVendorPricing = new in.shop2020.model.v1.inventory.VendorItemPricing();
947
	                    tVendorPricing.setVendorId(v.getVendorId());
1012
						tVendorPricing.setVendorId(v.getVendorId());
948
	                    tVendorPricing.setItemId(it.getId());
1013
						tVendorPricing.setItemId(it.getId());
949
	                    tVendorPricing.setMop(v.getMop());
1014
						tVendorPricing.setMop(v.getMop());
950
	                    tVendorPricing.setTransferPrice(v.getTransferPrice());
1015
						tVendorPricing.setTransferPrice(v.getTransferPrice());
951
	                    tVendorPricing.setNlc(v.getNlc());
1016
						tVendorPricing.setNlc(v.getNlc());
952
	                    tVendorPricing.setDealerPrice(v.getDealerPrice());
1017
						tVendorPricing.setDealerPrice(v.getDealerPrice());
953
	                    inventoryClient.addVendorItemPricing(tVendorPricing);
1018
						inventoryClient.addVendorItemPricing(tVendorPricing);
954
	                    logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
1019
						logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
955
	                    sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",NLC= " +v.getNlc() + ",DP=" + v.getDealerPrice() + "], ");
1020
						sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",NLC= " +v.getNlc() + ",DP=" + v.getDealerPrice() + "], ");
956
	                }
1021
					}
957
	            }
1022
				}
958
	            
1023
 
959
	            Map<String, VendorItemMapping> vendorMappings = it.getVendorKeysMap();
1024
				Map<String, VendorItemMapping> vendorMappings = it.getVendorKeysMap();
960
	            if(vendorMappings != null && !vendorMappings.isEmpty()) {
1025
				if(vendorMappings != null && !vendorMappings.isEmpty()) {
961
	                in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
1026
					in.shop2020.model.v1.inventory.VendorItemMapping tVendorMapping;
962
	                for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
1027
					for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
963
	                    tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
1028
						tVendorMapping = new in.shop2020.model.v1.inventory.VendorItemMapping();
964
	                    tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
1029
						tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
965
	                    tVendorMapping.setItemId(it.getId());
1030
						tVendorMapping.setItemId(it.getId());
966
	                    tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
1031
						tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
967
	                    inventoryClient.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
1032
						inventoryClient.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
968
	                    logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
1033
						logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
969
	                    sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
1034
						sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
970
	                }
1035
					}
971
	            }
1036
				}
972
	
1037
 
973
	            Map<Long, SourcePricings> sourcePricings = it.getSourcePricesMap();
1038
				Map<Long, SourcePricings> sourcePricings = it.getSourcePricesMap();
974
	            if(sourcePricings != null && !sourcePricings.isEmpty()){
1039
				if(sourcePricings != null && !sourcePricings.isEmpty()){
975
	                in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricing;
1040
					in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricing;
976
	                for(SourcePricings s : sourcePricings.values()){
1041
					for(SourcePricings s : sourcePricings.values()){
977
	                    tSourcePricing = new in.shop2020.model.v1.catalog.SourceItemPricing();
1042
						tSourcePricing = new in.shop2020.model.v1.catalog.SourceItemPricing();
978
	                    tSourcePricing.setSourceId(s.getSourceId());
1043
						tSourcePricing.setSourceId(s.getSourceId());
979
	                    tSourcePricing.setItemId(it.getId());
1044
						tSourcePricing.setItemId(it.getId());
980
	                    tSourcePricing.setMrp(s.getMrp());
1045
						tSourcePricing.setMrp(s.getMrp());
981
	                    tSourcePricing.setSellingPrice(s.getSellingPrice());
1046
						tSourcePricing.setSellingPrice(s.getSellingPrice());
982
	                    catalogClient_Prod.addSourceItemPricing(tSourcePricing);
1047
						catalogClient_Prod.addSourceItemPricing(tSourcePricing);
983
	                    logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
1048
						logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
984
	                    sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
1049
						sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
985
	                }
1050
					}
986
	            }
1051
				}
987
	            
1052
 
988
	            pushToProdLogger.info("Id=" + it.getId() + ",MRP=" + it.getMrp() + ",SP=" + " " + it.getSellingPrice() + sb.toString());
1053
				pushToProdLogger.info("Id=" + it.getId() + ",MRP=" + it.getMrp() + ",SP=" + " " + it.getSellingPrice() + sb.toString());
989
	        } catch (Exception e) {
1054
			} catch (Exception e) {
990
	            logger.error("Error while updating prices on production", e);
1055
				logger.error("Error while updating prices on production", e);
991
	            return "Error while updating all prices on production. Some of the prices may not have been  updated";
1056
				return "Error while updating all prices on production. Some of the prices may not have been  updated";
992
	        }
1057
			}
993
    	}
1058
		}
994
        
1059
 
995
        try {
1060
		try {
996
            ContentClient contentServiceClient = new ContentClient();
1061
			ContentClient contentServiceClient = new ContentClient();
997
            ContentService.Client contentClient = contentServiceClient.getClient();
1062
			ContentService.Client contentClient = contentServiceClient.getClient();
998
            
1063
 
999
            contentClient.pushContentToProduction(items.get(0).getCatalogItemId());
1064
			contentClient.pushContentToProduction(items.get(0).getCatalogItemId());
1000
        } catch (TTransportException e) {
1065
		} catch (TTransportException e) {
1001
            logger.error("Error while establishing connection to the content server", e);
1066
			logger.error("Error while establishing connection to the content server", e);
1002
            return "Error generating content. Prices updated successfully.";
1067
			return "Error generating content. Prices updated successfully.";
1003
        } catch (TException e) {
1068
		} catch (TException e) {
1004
            logger.error("Error while pushing content to production", e);
1069
			logger.error("Error while pushing content to production", e);
1005
            return "Error generating content. Prices updated successfully.";
1070
			return "Error generating content. Prices updated successfully.";
1006
        } catch (ContentServiceException e) {
1071
		} catch (ContentServiceException e) {
1007
            logger.error("Error while pushing content to production", e);
1072
			logger.error("Error while pushing content to production", e);
1008
            return "Error generating content. Prices updated successfully.";
1073
			return "Error generating content. Prices updated successfully.";
1009
        }
1074
		}
1010
        
1075
 
1011
        return "Prices updated and content generated successfully";
1076
		return "Prices updated and content generated successfully";
1012
    }
1077
	}
1013
    
1078
 
1014
    /**
1079
	/**
1015
     * Returns list of items with a particular status.
1080
	 * Returns list of items with a particular status.
1016
     * @param st
1081
	 * @param st
1017
     * @return
1082
	 * @return
1018
     */
1083
	 */
1019
    private List<Item> getItemsByStatus(status st, int start, int limit) {
1084
	private List<Item> getItemsByStatus(status st, int start, int limit) {
1020
        List<Item> itemList = new ArrayList<Item>();
1085
		List<Item> itemList = new ArrayList<Item>();
1021
        try {
1086
		try {
1022
            CatalogClient catalogServiceClient = new CatalogClient();
1087
			CatalogClient catalogServiceClient = new CatalogClient();
1023
            Client catalogClient = catalogServiceClient.getClient();
1088
			Client catalogClient = catalogServiceClient.getClient();
1024
 
1089
 
1025
            List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
1090
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
1026
 
1091
 
1027
            for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
1092
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
1028
                itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null));
1093
				itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null, null, null));
1029
            }
1094
			}
1030
        } catch (Exception e) {
1095
		} catch (Exception e) {
1031
            logger.error("Error while getting items by status: " + st, e);
1096
			logger.error("Error while getting items by status: " + st, e);
1032
        }
1097
		}
1033
        return itemList;
1098
		return itemList;
1034
    }
1099
	}
1035
    
1100
 
1036
    /**
1101
	/**
1037
     * Creates a new Item object and populates its attributes from thrift item passed as parameter.
1102
	 * Creates a new Item object and populates its attributes from thrift item passed as parameter.
1038
     * Also creates a Map each for VendorItemPricing, VendorItemMapping, SourceItemPricing and SimilarItems and adds these maps to the
1103
	 * Also creates a Map each for VendorItemPricing, VendorItemMapping, SourceItemPricing and SimilarItems and adds these maps to the
1039
     * new Item object.
1104
	 * new Item object.
1040
     * @param thriftItem
1105
	 * @param thriftItem
1041
     * @param tVendorPricings
1106
	 * @param tVendorPricings
1042
     * @param tVendorMappings
1107
	 * @param tVendorMappings
1043
     * @param tSourceMappings
1108
	 * @param tSourceMappings
1044
     * @param tSimilarItems
1109
	 * @param tSimilarItems
1045
     * @param tVoucherMappings
1110
	 * @param tVoucherMappings
1046
     * @param stockPurchaseParams 
1111
	 * @param stockPurchaseParams 
1047
     * @return item object with attributes copied from thrift item object.
1112
	 * @return item object with attributes copied from thrift item object.
1048
     */
1113
	 */
1049
    private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
1114
	private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
1050
            List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
1115
			List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
1051
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
1116
			List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
1052
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
1117
			List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
1053
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, 
1118
			List<in.shop2020.model.v1.catalog.Item> tSimilarItems, 
1054
            in.shop2020.model.v1.inventory.ItemInventory tItemInventory, 
1119
			in.shop2020.model.v1.inventory.ItemInventory tItemInventory, 
1055
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings, 
1120
			List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings, 
1056
            ItemStockPurchaseParams tStockPurchaseParams, Map<Long,String> saleHistory, Long freebieItemId){
1121
			ItemStockPurchaseParams tStockPurchaseParams, Map<Long,String> saleHistory, Long freebieItemId){
1057
 
1122
 
1058
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
1123
		Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
1059
        VendorItemMapping vItemMapping;
1124
		VendorItemMapping vItemMapping;
1060
        if(tVendorMappings != null) {
1125
		if(tVendorMappings != null) {
1061
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
1126
			for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
1062
                vItemMapping = new VendorItemMapping();
1127
				vItemMapping = new VendorItemMapping();
1063
                vItemMapping.setVendorId(vim.getVendorId());
1128
				vItemMapping.setVendorId(vim.getVendorId());
1064
                vItemMapping.setItemKey(vim.getItemKey());
1129
				vItemMapping.setItemKey(vim.getItemKey());
1065
                vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
1130
				vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
1066
            }
1131
			}
1067
        }
1132
		}
1068
 
1133
 
1069
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
1134
		Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
1070
        VendorPricings vPricings;
1135
		VendorPricings vPricings;
1071
        if(tVendorPricings != null) {
1136
		if(tVendorPricings != null) {
1072
            for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
1137
			for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
1073
                vPricings = new VendorPricings();
1138
				vPricings = new VendorPricings();
1074
                vPricings.setVendorId(vip.getVendorId());
1139
				vPricings.setVendorId(vip.getVendorId());
1075
                vPricings.setMop(vip.getMop());
1140
				vPricings.setMop(vip.getMop());
1076
                vPricings.setDealerPrice(vip.getDealerPrice());
1141
				vPricings.setDealerPrice(vip.getDealerPrice());
1077
                vPricings.setTransferPrice(vip.getTransferPrice());
1142
				vPricings.setTransferPrice(vip.getTransferPrice());
1078
                vPricings.setNlc(vip.getNlc());
1143
				vPricings.setNlc(vip.getNlc());
1079
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
1144
				vendorPricingMap.put(vPricings.getVendorId(), vPricings);
1080
            }
1145
			}
1081
        }
1146
		}
1082
 
1147
 
1083
        Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
1148
		Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
1084
        SourcePricings sPricings;
1149
		SourcePricings sPricings;
1085
        if(tSourceMappings != null) {
1150
		if(tSourceMappings != null) {
1086
            for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
1151
			for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
1087
                sPricings = new SourcePricings();
1152
				sPricings = new SourcePricings();
1088
                sPricings.setSourceId(sip.getSourceId());
1153
				sPricings.setSourceId(sip.getSourceId());
1089
                sPricings.setMrp(sip.getMrp());
1154
				sPricings.setMrp(sip.getMrp());
1090
                sPricings.setSellingPrice(sip.getSellingPrice());
1155
				sPricings.setSellingPrice(sip.getSellingPrice());
1091
                sourcePricingMap.put(sPricings.getSourceId(), sPricings);
1156
				sourcePricingMap.put(sPricings.getSourceId(), sPricings);
1092
            }
1157
			}
1093
        }
1158
		}
1094
        
1159
 
1095
        Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
1160
		Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
1096
        Item sItems;
1161
		Item sItems;
1097
        if(tSimilarItems != null) {
1162
		if(tSimilarItems != null) {
1098
            for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
1163
			for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
1099
            	sItems = new Item();
1164
				sItems = new Item();
1100
            	sItems.setCatalogItemId(sit.getCatalogItemId());
1165
				sItems.setCatalogItemId(sit.getCatalogItemId());
1101
            	sItems.setProductGroup(sit.getProductGroup());
1166
				sItems.setProductGroup(sit.getProductGroup());
1102
            	sItems.setBrand(sit.getBrand());
1167
				sItems.setBrand(sit.getBrand());
1103
            	sItems.setModelNumber(sit.getModelNumber());
1168
				sItems.setModelNumber(sit.getModelNumber());
1104
            	sItems.setModelName(sit.getModelName());
1169
				sItems.setModelName(sit.getModelName());
1105
            	sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
1170
				sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
1106
            	SimilarItemslist.put(sit.getCatalogItemId(), sItems);
1171
				SimilarItemslist.put(sit.getCatalogItemId(), sItems);
1107
            }
1172
			}
1108
        }
1173
		}
1109
 
1174
 
1110
        Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1175
		Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1111
        ItemInventory warehousedata;
1176
		ItemInventory warehousedata;
1112
        if(tItemInventory != null) {
1177
		if(tItemInventory != null) {
1113
        	Map<Long, Long> availabilityMap = tItemInventory.getAvailability();
1178
			Map<Long, Long> availabilityMap = tItemInventory.getAvailability();
1114
        	Map<Long, Long> reservedMap = tItemInventory.getReserved();
1179
			Map<Long, Long> reservedMap = tItemInventory.getReserved();
1115
        	Map<Long, Long> heldMap = tItemInventory.getHeld();
1180
			Map<Long, Long> heldMap = tItemInventory.getHeld();
1116
            for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1181
			for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1117
            	Map<Integer, Long> heldInventoryMap = new HashMap<Integer, Long>();
1182
				Map<Integer, Long> heldInventoryMap = new HashMap<Integer, Long>();
1118
            	warehousedata = new ItemInventory();
1183
				warehousedata = new ItemInventory();
1119
            	warehousedata.setWarehouseId(availability.getKey());
1184
				warehousedata.setWarehouseId(availability.getKey());
1120
            	warehousedata.setAvailability(availability.getValue());
1185
				warehousedata.setAvailability(availability.getValue());
1121
            	warehousedata.setReserved(reservedMap.get(availability.getKey()));
1186
				warehousedata.setReserved(reservedMap.get(availability.getKey()));
1122
            	warehousedata.setHeld(heldMap.get(availability.getKey()));
1187
				warehousedata.setHeld(heldMap.get(availability.getKey()));
1123
            	try {
1188
				try {
1124
	            	if(warehousedata.getHeld()>0) {
1189
					if(warehousedata.getHeld()>0) {
1125
	            		InventoryService.Client inventoryClient = new InventoryClient().getClient();
1190
						InventoryService.Client inventoryClient = new InventoryClient().getClient();
1126
	            		heldInventoryMap = inventoryClient.getHeldInventoryMapForItem(thriftItem.getId(), availability.getKey());
1191
						heldInventoryMap = inventoryClient.getHeldInventoryMapForItem(thriftItem.getId(), availability.getKey());
1127
	            	}
1192
					}
1128
	            	if(heldInventoryMap.size()>0) {
1193
					if(heldInventoryMap.size()>0) {
1129
	            		for(Integer source : heldInventoryMap.keySet()) {
1194
						for(Integer source : heldInventoryMap.keySet()) {
1130
	            			switch(source) {
1195
							switch(source) {
1131
	            				case EBAYSOURCE: warehousedata.setEbayHeld(heldInventoryMap.get(source));
1196
							case EBAYSOURCE: warehousedata.setEbayHeld(heldInventoryMap.get(source));
1132
	            				break;
1197
							break;
1133
	            				case SNAPDEALSOURCE: warehousedata.setSnapdealHeld(heldInventoryMap.get(source));
1198
							case SNAPDEALSOURCE: warehousedata.setSnapdealHeld(heldInventoryMap.get(source));
1134
	            				break;
1199
							break;
1135
	            				case FLIPKARTSOURCE: warehousedata.setFlipkartHeld(heldInventoryMap.get(source));
1200
							case FLIPKARTSOURCE: warehousedata.setFlipkartHeld(heldInventoryMap.get(source));
1136
	            			}
1201
							}
1137
	            		}
1202
						}
1138
	            	}
1203
					}
1139
            	} catch (Exception e) {
1204
				} catch (Exception e) {
1140
            		logger.error("Error in getting data from holdInventoryDetail for itemId " + thriftItem.getId() + 
1205
					logger.error("Error in getting data from holdInventoryDetail for itemId " + thriftItem.getId() + 
1141
            				" and warehouse " +availability.getKey());
1206
							" and warehouse " +availability.getKey());
1142
            	}
1207
				}
1143
            	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1208
				itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1144
            }
1209
			}
1145
        }
1210
		}
1146
        else {
1211
		else {
1147
        	itemInventoryMap = null;
1212
			itemInventoryMap = null;
1148
        }
1213
		}
1149
        
1214
 
1150
        Map<String, VoucherItemMapping> voucherMap = new HashMap<String, VoucherItemMapping>();
1215
		Map<String, VoucherItemMapping> voucherMap = new HashMap<String, VoucherItemMapping>();
1151
        VoucherItemMapping voucher;
1216
		VoucherItemMapping voucher;
1152
        if(tVoucherMappings != null) {
1217
		if(tVoucherMappings != null) {
1153
            for(in.shop2020.model.v1.catalog.VoucherItemMapping tvoucher : tVoucherMappings) {
1218
			for(in.shop2020.model.v1.catalog.VoucherItemMapping tvoucher : tVoucherMappings) {
1154
            	voucher = new VoucherItemMapping(tvoucher.getAmount(), VoucherType.findByValue((int) tvoucher.getVoucherType()).name());
1219
				voucher = new VoucherItemMapping(tvoucher.getAmount(), VoucherType.findByValue((int) tvoucher.getVoucherType()).name());
1155
            	voucherMap.put(VoucherType.findByValue((int) tvoucher.getVoucherType()).name(), voucher);
1220
				voucherMap.put(VoucherType.findByValue((int) tvoucher.getVoucherType()).name(), voucher);
1156
            }
1221
			}
1157
        }
1222
		}
1158
       
1223
 
1159
        in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams stockPurchaseParams = 
1224
		in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams stockPurchaseParams = 
1160
        	new in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams();
1225
			new in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams();
1161
        if(tStockPurchaseParams != null) {
1226
		if(tStockPurchaseParams != null) {
1162
        	stockPurchaseParams.setItem_id(tStockPurchaseParams.getItem_id());
1227
			stockPurchaseParams.setItem_id(tStockPurchaseParams.getItem_id());
1163
        	stockPurchaseParams.setMinStockLevel(tStockPurchaseParams.getMinStockLevel());
1228
			stockPurchaseParams.setMinStockLevel(tStockPurchaseParams.getMinStockLevel());
1164
        	stockPurchaseParams.setNumOfDaysStock(tStockPurchaseParams.getNumOfDaysStock());
1229
			stockPurchaseParams.setNumOfDaysStock(tStockPurchaseParams.getNumOfDaysStock());
1165
        }
1230
		}
1166
        
1231
 
1167
        Item item = new Item(thriftItem.getId(),
1232
		Item item = new Item(thriftItem.getId(),
1168
                thriftItem.getProductGroup(),
1233
				thriftItem.getProductGroup(),
1169
                thriftItem.getBrand(),
1234
				thriftItem.getBrand(),
1170
                thriftItem.getModelNumber(),
1235
				thriftItem.getModelNumber(),
1171
                thriftItem.getModelName(),
1236
				thriftItem.getModelName(),
1172
                thriftItem.getColor(),
1237
				thriftItem.getColor(),
1173
                CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
1238
				CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
1174
                thriftItem.getCategory(),
1239
				thriftItem.getCategory(),
1175
                thriftItem.getComments(),
1240
				thriftItem.getComments(),
1176
                thriftItem.getCatalogItemId(),
1241
				thriftItem.getCatalogItemId(),
1177
                thriftItem.getFeatureId(),
1242
				thriftItem.getFeatureId(),
1178
                thriftItem.getFeatureDescription(),
1243
				thriftItem.getFeatureDescription(),
1179
                thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
1244
				thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
1180
                thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
1245
						thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
1181
                thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
1246
								thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
1182
                thriftItem.getAddedOn(),
1247
										thriftItem.getAddedOn(),
1183
                thriftItem.getStartDate(),
1248
										thriftItem.getStartDate(),
1184
                thriftItem.isSetComingSoonStartDate() ? thriftItem.getComingSoonStartDate() : null ,
1249
										thriftItem.isSetComingSoonStartDate() ? thriftItem.getComingSoonStartDate() : null ,
1185
                thriftItem.isSetExpectedArrivalDate() ? thriftItem.getExpectedArrivalDate() : null ,
1250
												thriftItem.isSetExpectedArrivalDate() ? thriftItem.getExpectedArrivalDate() : null ,
1186
                thriftItem.getRetireDate(),
1251
														thriftItem.getRetireDate(),
1187
                thriftItem.getUpdatedOn(),
1252
														thriftItem.getUpdatedOn(),
1188
                thriftItem.getItemStatus().name(),
1253
														thriftItem.getItemStatus().name(),
1189
                thriftItem.getItemStatus().getValue(),
1254
														thriftItem.getItemStatus().getValue(),
1190
                thriftItem.getStatus_description(),
1255
														thriftItem.getStatus_description(),
1191
                thriftItem.getBestDealText(),
1256
														thriftItem.getBestDealText(),
1192
                thriftItem.getBestDealsDetailsText(),
1257
														thriftItem.getBestDealsDetailsText(),
1193
                thriftItem.getBestDealsDetailsLink(),
1258
														thriftItem.getBestDealsDetailsLink(),
1194
                thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
1259
														thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
1195
                thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
1260
																thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
1196
                thriftItem.isDefaultForEntity(),
1261
																		thriftItem.isDefaultForEntity(),
1197
                thriftItem.isRisky(),
1262
																		thriftItem.isRisky(),
1198
                thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
1263
																		thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
1199
                thriftItem.isIsWarehousePreferenceSticky(),
1264
																				thriftItem.isIsWarehousePreferenceSticky(),
1200
                thriftItem.isHasItemNo(),
1265
																				thriftItem.isHasItemNo(),
1201
                ItemType.SERIALIZED.equals(thriftItem.getType()),
1266
																				ItemType.SERIALIZED.equals(thriftItem.getType()),
1202
                thriftItem.isSetShowSellingPrice() ? thriftItem.isShowSellingPrice() : false,
1267
																				thriftItem.isSetShowSellingPrice() ? thriftItem.isShowSellingPrice() : false,
1203
                thriftItem.isHoldOverride(),
1268
																						thriftItem.isHoldOverride(),
1204
                thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
1269
																						thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
1205
                thriftItem.isSetPreferredInsurer() ? thriftItem.getPreferredInsurer() : null,		
1270
																								thriftItem.isSetPreferredInsurer() ? thriftItem.getPreferredInsurer() : null,		
1206
                itemInventoryMap,
1271
																										itemInventoryMap,
1207
                vendorPricingMap,
1272
																										vendorPricingMap,
1208
                vItemMap,
1273
																										vItemMap,
1209
                sourcePricingMap,
1274
																										sourcePricingMap,
1210
                SimilarItemslist,
1275
																										SimilarItemslist,
1211
                voucherMap, 
1276
																										voucherMap, 
1212
                stockPurchaseParams.getNumOfDaysStock(), 
1277
																										stockPurchaseParams.getNumOfDaysStock(), 
1213
                stockPurchaseParams.getMinStockLevel(), 
1278
																										stockPurchaseParams.getMinStockLevel(), 
1214
                saleHistory, 
1279
																										saleHistory, 
1215
                freebieItemId,
1280
																										freebieItemId,
1216
                thriftItem.getAsin(),
1281
																										thriftItem.getAsin(),
1217
                thriftItem.getHoldInventory(),
1282
																										thriftItem.getHoldInventory(),
1218
                thriftItem.getDefaultInventory());
1283
																										thriftItem.getDefaultInventory());
1219
        return item;
1284
		return item;
1220
    }
1285
	}
1221
    
1286
 
1222
    /**
1287
	/**
1223
     * 
1288
	 * 
1224
     * @return True if push to production count is less than maximum allowed.
1289
	 * @return True if push to production count is less than maximum allowed.
1225
     */
1290
	 */
1226
    private boolean canPushToProduction() {
1291
	private boolean canPushToProduction() {
1227
        int count = getPushToProdCount(logFile);
1292
		int count = getPushToProdCount(logFile);
1228
        return count < maxCount;
1293
		return count < maxCount;
1229
    }
1294
	}
1230
      
1295
 
1231
    /**
1296
	/**
1232
     * If this is the first attempt to push to production for current date, returns 0
1297
	 * If this is the first attempt to push to production for current date, returns 0
1233
     * else reads number of lines from daily rolling log file to get the count.
1298
	 * else reads number of lines from daily rolling log file to get the count.
1234
     * @return push to production count for current date
1299
	 * @return push to production count for current date
1235
     */
1300
	 */
1236
    private int getPushToProdCount(String logfile) {
1301
	private int getPushToProdCount(String logfile) {
1237
        // logfile is "/var/log/services/pushToProductionCount/pushToProd.log"
1302
		// logfile is "/var/log/services/pushToProductionCount/pushToProd.log"
1238
        // this should also be set in log4j.properties
1303
		// this should also be set in log4j.properties
1239
        int lineCount = 0;
1304
		int lineCount = 0;
1240
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
1305
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
1241
        Date currentDate = Calendar.getInstance().getTime();
1306
		Date currentDate = Calendar.getInstance().getTime();
1242
        if(pushToProdDate == null ||  !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {
1307
		if(pushToProdDate == null ||  !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {
1243
            pushToProdDate = currentDate;
1308
			pushToProdDate = currentDate;
1244
            return lineCount;
1309
			return lineCount;
1245
        }
1310
		}
1246
        try {
1311
		try {
1247
            BufferedReader br = new BufferedReader(new FileReader(logfile));
1312
			BufferedReader br = new BufferedReader(new FileReader(logfile));
1248
            while (br.readLine() != null) {
1313
			while (br.readLine() != null) {
1249
                lineCount++;
1314
				lineCount++;
1250
            }
1315
			}
1251
        } catch (IOException e) {
1316
		} catch (IOException e) {
1252
            logger.error("Error while reading the log file", e);
1317
			logger.error("Error while reading the log file", e);
1253
        }
1318
		}
1254
        return lineCount;
1319
		return lineCount;
1255
    }
1320
	}
1256
 
1321
 
1257
	@Override
1322
	@Override
1258
	public boolean deleteSimilarItem(long itemId, long catalogItemId) {
1323
	public boolean deleteSimilarItem(long itemId, long catalogItemId) {
1259
		try{
1324
		try{
1260
            CatalogClient catalogServiceClient = new CatalogClient();
1325
			CatalogClient catalogServiceClient = new CatalogClient();
1261
            Client catalogClient = catalogServiceClient.getClient();
1326
			Client catalogClient = catalogServiceClient.getClient();
1262
 
1327
 
1263
            return catalogClient.deleteSimilarItem(itemId, catalogItemId);
1328
			return catalogClient.deleteSimilarItem(itemId, catalogItemId);
1264
 
1329
 
1265
        }catch(Exception e){
1330
		}catch(Exception e){
1266
            logger.error("Error while deleting the SimilarItems for: " + itemId, e);
1331
			logger.error("Error while deleting the SimilarItems for: " + itemId, e);
1267
        }
1332
		}
1268
        return false;
1333
		return false;
1269
	}
1334
	}
1270
 
1335
 
1271
	@Override
1336
	@Override
1272
	public Item addSimilarItem(long itemId, long catalogItemId) {
1337
	public Item addSimilarItem(long itemId, long catalogItemId) {
1273
		try{
1338
		try{
1274
            CatalogClient catalogServiceClient = new CatalogClient();
1339
			CatalogClient catalogServiceClient = new CatalogClient();
1275
            Client catalogClient = catalogServiceClient.getClient();
1340
			Client catalogClient = catalogServiceClient.getClient();
1276
            in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1341
			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
1277
 
1342
 
1278
            return getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null);
1343
			return getItemFromThriftItem(thriftItem, null, null, null, null, null, null, null, null, null,null,null);
1279
        }catch(Exception e){
1344
		}catch(Exception e){
1280
            logger.error("Error while adding the SimilarItems for: " + itemId, e);
1345
			logger.error("Error while adding the SimilarItems for: " + itemId, e);
1281
        }
1346
		}
1282
        return null;
1347
		return null;
1283
	}
1348
	}
1284
 
1349
 
1285
	@Override
1350
	@Override
1286
	public Map<Long, ItemInventory> getProdItemInventory(long itemId) {
1351
	public Map<Long, ItemInventory> getProdItemInventory(long itemId) {
1287
		try {
1352
		try {
1288
            // Initialize client for production server
1353
			// Initialize client for production server
1289
            CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
1354
			CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
1290
                    ConfigClientKeys.catalog_service_server_port.toString());
1355
					ConfigClientKeys.catalog_service_server_port.toString());
1291
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1356
			Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1292
            InventoryClient inventoryServiceClient = new InventoryClient();
1357
			InventoryClient inventoryServiceClient = new InventoryClient();
1293
            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1358
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1294
            in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(itemId);
1359
			in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(itemId);
1295
            
1360
 
1296
            Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1361
			Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1297
            ItemInventory warehousedata;
1362
			ItemInventory warehousedata;
1298
            if(thriftItemInventory != null) {
1363
			if(thriftItemInventory != null) {
1299
            	Map<Long, Long> availabilityMap = thriftItemInventory.getAvailability();
1364
				Map<Long, Long> availabilityMap = thriftItemInventory.getAvailability();
1300
            	Map<Long, Long> reservedMap = thriftItemInventory.getReserved();
1365
				Map<Long, Long> reservedMap = thriftItemInventory.getReserved();
1301
            	Map<Long, Long> heldMap = thriftItemInventory.getHeld();
1366
				Map<Long, Long> heldMap = thriftItemInventory.getHeld();
1302
                for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1367
				for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1303
                	Map<Integer, Long> heldInventoryMap = new HashMap<Integer, Long>();
1368
					Map<Integer, Long> heldInventoryMap = new HashMap<Integer, Long>();
1304
                	warehousedata = new ItemInventory();
1369
					warehousedata = new ItemInventory();
1305
                	warehousedata.setWarehouseId(availability.getKey());
1370
					warehousedata.setWarehouseId(availability.getKey());
1306
                	warehousedata.setAvailability(availability.getValue());
1371
					warehousedata.setAvailability(availability.getValue());
1307
                	warehousedata.setReserved(reservedMap.get(availability.getKey()));
1372
					warehousedata.setReserved(reservedMap.get(availability.getKey()));
1308
                	warehousedata.setHeld(heldMap.get(availability.getKey()));
1373
					warehousedata.setHeld(heldMap.get(availability.getKey()));
1309
                	try {
1374
					try {
1310
	            		if(warehousedata.getHeld()>0) {
1375
						if(warehousedata.getHeld()>0) {
1311
	                		heldInventoryMap = inventoryClient.getHeldInventoryMapForItem(itemId, availability.getKey());
1376
							heldInventoryMap = inventoryClient.getHeldInventoryMapForItem(itemId, availability.getKey());
1312
	                	}
1377
						}
1313
	                	if(heldInventoryMap.size()>0) {
1378
						if(heldInventoryMap.size()>0) {
1314
	                		for(Integer source : heldInventoryMap.keySet()) {
1379
							for(Integer source : heldInventoryMap.keySet()) {
1315
	                			switch(source) {
1380
								switch(source) {
1316
	                				case EBAYSOURCE: warehousedata.setEbayHeld(heldInventoryMap.get(source));
1381
								case EBAYSOURCE: warehousedata.setEbayHeld(heldInventoryMap.get(source));
1317
	                				break;
1382
								break;
1318
	                				case SNAPDEALSOURCE: warehousedata.setSnapdealHeld(heldInventoryMap.get(source));
1383
								case SNAPDEALSOURCE: warehousedata.setSnapdealHeld(heldInventoryMap.get(source));
1319
	                				break;
1384
								break;
1320
	                				case FLIPKARTSOURCE: warehousedata.setFlipkartHeld(heldInventoryMap.get(source));
1385
								case FLIPKARTSOURCE: warehousedata.setFlipkartHeld(heldInventoryMap.get(source));
1321
	                			}
1386
								}
1322
	                		}
1387
							}
1323
	                	} 
1388
						} 
1324
                	}catch (Exception e) {
1389
					}catch (Exception e) {
1325
                		logger.error("Error in getting data from holdInventoryDetail for itemId " + itemId + 
1390
						logger.error("Error in getting data from holdInventoryDetail for itemId " + itemId + 
1326
                				" and warehouse " +availability.getKey());
1391
								" and warehouse " +availability.getKey());
1327
                	}
1392
					}
1328
                	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1393
					itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1329
                }
1394
				}
1330
            }
1395
			}
1331
            else {
1396
			else {
1332
            	itemInventoryMap = null;
1397
				itemInventoryMap = null;
1333
            }
1398
			}
1334
            return itemInventoryMap;
1399
			return itemInventoryMap;
1335
        } catch (Exception e) {
1400
		} catch (Exception e) {
1336
            logger.error("Error while updating item's risky flag on staging", e);
1401
			logger.error("Error while updating item's risky flag on staging", e);
1337
        }
1402
		}
1338
		return null;
1403
		return null;
1339
	}
1404
	}
1340
 
1405
 
1341
	@Override
1406
	@Override
1342
	public boolean addAuthorizationLog(long itemId, String username, String message) {
1407
	public boolean addAuthorizationLog(long itemId, String username, String message) {
1343
		try{
1408
		try{
1344
            CatalogClient catalogServiceClient = new CatalogClient();
1409
			CatalogClient catalogServiceClient = new CatalogClient();
1345
            Client catalogClient = catalogServiceClient.getClient();
1410
			Client catalogClient = catalogServiceClient.getClient();
1346
 
1411
 
1347
            return catalogClient.addAuthorizationLog(itemId, username, message);
1412
			return catalogClient.addAuthorizationLog(itemId, username, message);
1348
 
1413
 
1349
        }catch(Exception e){
1414
		}catch(Exception e){
1350
            logger.error("Error while adding the event for: " + itemId, e);
1415
			logger.error("Error while adding the event for: " + itemId, e);
1351
        }
1416
		}
1352
		return false;
1417
		return false;
1353
	}
1418
	}
1354
 
1419
 
1355
	@Override
1420
	@Override
1356
	public Map<String, String> getConfigdataforPriceCompare() {
1421
	public Map<String, String> getConfigdataforPriceCompare() {
1357
		Map<String, String> ConfigMap = new HashMap<String, String>();
1422
		Map<String, String> ConfigMap = new HashMap<String, String>();
1358
		try {
1423
		try {
1359
			ConfigMap.put("courier_cost_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_cost_factor.toString()));
1424
			ConfigMap.put("courier_cost_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_cost_factor.toString()));
1360
            ConfigMap.put("courier_weight_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_weight_factor.toString()));
1425
			ConfigMap.put("courier_weight_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_weight_factor.toString()));
1361
            ConfigMap.put("breakeven_divisor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_divisor.toString()));
1426
			ConfigMap.put("breakeven_divisor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_divisor.toString()));
1362
            ConfigMap.put("breakeven_additon_factor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_additon_factor.toString()));
1427
			ConfigMap.put("breakeven_additon_factor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_additon_factor.toString()));
1363
            ConfigMap.put("transfer_price_percentage", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_percentage.toString()));
1428
			ConfigMap.put("transfer_price_percentage", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_percentage.toString()));
1364
            ConfigMap.put("transfer_price_factor", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_factor.toString()));
1429
			ConfigMap.put("transfer_price_factor", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_factor.toString()));
1365
        } catch(ConfigException ce) {
1430
		} catch(ConfigException ce) {
1366
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1431
			logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1367
            ConfigMap.put("courier_cost_factor", "60");
1432
			ConfigMap.put("courier_cost_factor", "60");
1368
            ConfigMap.put("courier_weight_factor", "500");
1433
			ConfigMap.put("courier_weight_factor", "500");
1369
            ConfigMap.put("breakeven_divisor", "0.98");
1434
			ConfigMap.put("breakeven_divisor", "0.98");
1370
            ConfigMap.put("breakeven_additon_factor", "50");
1435
			ConfigMap.put("breakeven_additon_factor", "50");
1371
            ConfigMap.put("transfer_price_percentage", "2");
1436
			ConfigMap.put("transfer_price_percentage", "2");
1372
            ConfigMap.put("transfer_price_factor", "50");
1437
			ConfigMap.put("transfer_price_factor", "50");
1373
        }
1438
		}
1374
		return ConfigMap;
1439
		return ConfigMap;
1375
	}
1440
	}
1376
 
1441
 
1377
	@Override
1442
	@Override
1378
	public List<String> getAllCategories() {
1443
	public List<String> getAllCategories() {
1379
		List<String> categoryList = new ArrayList<String>();
1444
		List<String> categoryList = new ArrayList<String>();
1380
		List<Long> parentCategoryIDs = Arrays.asList(new Long[] {(long) 0,(long) 10001,(long) 10009,(long) 10049});
1445
		List<Long> parentCategoryIDs = Arrays.asList(new Long[] {(long) 0,(long) 10001,(long) 10009,(long) 10049});
1381
        try {
1446
		try {
1382
            CatalogClient catalogServiceClient = new CatalogClient();
1447
			CatalogClient catalogServiceClient = new CatalogClient();
1383
            Client catalogClient = catalogServiceClient.getClient();
1448
			Client catalogClient = catalogServiceClient.getClient();
1384
 
1449
 
1385
            List<in.shop2020.model.v1.catalog.Category> categories = catalogClient.getAllCategories();
1450
			List<in.shop2020.model.v1.catalog.Category> categories = catalogClient.getAllCategories();
1386
 
1451
 
1387
            for(in.shop2020.model.v1.catalog.Category category : categories) {
1452
			for(in.shop2020.model.v1.catalog.Category category : categories) {
1388
            	if(!parentCategoryIDs.contains(category.getParent_category_id())){
1453
				if(!parentCategoryIDs.contains(category.getParent_category_id())){
1389
            		categoryList.add(category.getDisplay_name());
1454
					categoryList.add(category.getDisplay_name());
1390
            	}
1455
				}
1391
            	else{
1456
				else{
1392
            		continue;
1457
					continue;
1393
            	}
1458
				}
1394
            }
1459
			}
1395
        } catch (Exception e) {
1460
		} catch (Exception e) {
1396
            logger.error("Error while getting all the categories: ", e);
1461
			logger.error("Error while getting all the categories: ", e);
1397
        }
1462
		}
1398
        return categoryList;
1463
		return categoryList;
1399
	}
1464
	}
1400
 
1465
 
1401
	@Override
1466
	@Override
1402
	public List<String> getAllBrands() {
1467
	public List<String> getAllBrands() {
1403
		List<String> brandsList = new ArrayList<String>();
1468
		List<String> brandsList = new ArrayList<String>();
1404
        try {
1469
		try {
1405
            CatalogClient catalogServiceClient = new CatalogClient();
1470
			CatalogClient catalogServiceClient = new CatalogClient();
1406
            Client catalogClient = catalogServiceClient.getClient();
1471
			Client catalogClient = catalogServiceClient.getClient();
1407
 
1472
 
1408
            brandsList = catalogClient.getAllBrands();
1473
			brandsList = catalogClient.getAllBrands();
1409
        } catch (Exception e) {
1474
		} catch (Exception e) {
1410
            logger.error("Error while getting all the categories: ", e);
1475
			logger.error("Error while getting all the categories: ", e);
1411
        }
1476
		}
1412
        return brandsList;
1477
		return brandsList;
1413
	}
1478
	}
1414
 
1479
 
1415
	@Override
1480
	@Override
1416
	public boolean deleteVoucher(Long catalogItemId, Long voucherType) {
1481
	public boolean deleteVoucher(Long catalogItemId, Long voucherType) {
1417
		try{
1482
		try{
1418
            CatalogClient catalogServiceClient = new CatalogClient();
1483
			CatalogClient catalogServiceClient = new CatalogClient();
1419
            Client catalogClient = catalogServiceClient.getClient();
1484
			Client catalogClient = catalogServiceClient.getClient();
1420
 
1485
 
1421
            return catalogClient.deleteVoucherForItem(catalogItemId, voucherType);
1486
			return catalogClient.deleteVoucherForItem(catalogItemId, voucherType);
1422
 
1487
 
1423
        }catch(Exception e){
1488
		}catch(Exception e){
1424
            logger.error("Error while deleting the Voucher for: " + catalogItemId, e);
1489
			logger.error("Error while deleting the Voucher for: " + catalogItemId, e);
1425
        }
1490
		}
1426
        return false;
1491
		return false;
1427
	}
1492
	}
1428
 
1493
 
1429
	@Override
1494
	@Override
1430
	public boolean addVoucher(Long catalogItemId, Long voucherType, long voucherAmount) {
1495
	public boolean addVoucher(Long catalogItemId, Long voucherType, long voucherAmount) {
1431
		try{
1496
		try{
1432
            CatalogClient catalogServiceClient = new CatalogClient();
1497
			CatalogClient catalogServiceClient = new CatalogClient();
1433
            Client catalogClient = catalogServiceClient.getClient();
1498
			Client catalogClient = catalogServiceClient.getClient();
1434
 
1499
 
1435
            return catalogClient.addupdateVoucherForItem(catalogItemId, voucherType, voucherAmount);
1500
			return catalogClient.addupdateVoucherForItem(catalogItemId, voucherType, voucherAmount);
1436
 
1501
 
1437
        }catch(Exception e){
1502
		}catch(Exception e){
1438
            logger.error("Error while adding the Voucher for: " + catalogItemId, e);
1503
			logger.error("Error while adding the Voucher for: " + catalogItemId, e);
1439
        }
1504
		}
1440
		return false;
1505
		return false;
1441
	}
1506
	}
1442
	@Override
1507
	@Override
1443
	public Map<Long, String> getvoucherTypes() {
1508
	public Map<Long, String> getvoucherTypes() {
1444
		Map<Long, String> voucherType = new HashMap<Long, String>();
1509
		Map<Long, String> voucherType = new HashMap<Long, String>();
Line 1454... Line 1519...
1454
		try {
1519
		try {
1455
			String entityId_mandatory = ConfigClient.getClient().get(ConfigClientKeys.entityId_mandatory.toString());
1520
			String entityId_mandatory = ConfigClient.getClient().get(ConfigClientKeys.entityId_mandatory.toString());
1456
			if (entityId_mandatory.equals("TRUE")) {
1521
			if (entityId_mandatory.equals("TRUE")) {
1457
				return true;
1522
				return true;
1458
			}
1523
			}
1459
        } catch(ConfigException ce) {
1524
		} catch(ConfigException ce) {
1460
            logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1525
			logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
1461
        }
1526
		}
1462
		return false;
1527
		return false;
1463
	}
1528
	}
1464
 
1529
 
1465
	@Override
1530
	@Override
1466
	public boolean checkEntityId(long entityId) {
1531
	public boolean checkEntityId(long entityId) {
1467
		try {
1532
		try {
1468
            CatalogClient catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_master.toString(), ConfigClientKeys.catalog_service_server_port.toString());
1533
			CatalogClient catalogServiceClient = new CatalogClient(ConfigClientKeys.catalog_service_server_host_master.toString(), ConfigClientKeys.catalog_service_server_port.toString());
1469
            Client catalogClient = catalogServiceClient.getClient();
1534
			Client catalogClient = catalogServiceClient.getClient();
1470
            return catalogClient.isValidCatalogItemId(entityId);
1535
			return catalogClient.isValidCatalogItemId(entityId);
1471
        } catch (Exception e) {
1536
		} catch (Exception e) {
1472
            logger.error("Error while checking for a Catalog Item Id: ", e);
1537
			logger.error("Error while checking for a Catalog Item Id: ", e);
1473
        }
1538
		}
1474
		return false;
1539
		return false;
1475
	}
1540
	}
1476
 
1541
 
1477
	@Override
1542
	@Override
1478
	public String updateExpectedDelayOnProd(Item item) {
1543
	public String updateExpectedDelayOnProd(Item item) {
1479
		try{
1544
		try{
1480
            CatalogClient catalogServiceClient_Prod = new CatalogClient( 
1545
			CatalogClient catalogServiceClient_Prod = new CatalogClient( 
1481
                    ConfigClientKeys.catalog_service_server_host_prod.toString(),
1546
					ConfigClientKeys.catalog_service_server_host_prod.toString(),
1482
                    ConfigClientKeys.catalog_service_server_port.toString());
1547
					ConfigClientKeys.catalog_service_server_port.toString());
1483
            
1548
 
1484
            Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1549
			Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
1485
 
1550
 
1486
 
1551
 
1487
            in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
1552
			in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
1488
            if(item.getExpectedDelay() != null) {
1553
			if(item.getExpectedDelay() != null) {
1489
            	tItem.setExpectedDelay(item.getExpectedDelay());
1554
				tItem.setExpectedDelay(item.getExpectedDelay());
1490
            	if(item.isItemType()) {
1555
				if(item.isItemType()) {
1491
                	tItem.setType(ItemType.SERIALIZED);
1556
					tItem.setType(ItemType.SERIALIZED);
1492
                }
1557
				}
1493
                else {
1558
				else {
1494
                	tItem.setType(ItemType.NON_SERIALIZED);
1559
					tItem.setType(ItemType.NON_SERIALIZED);
1495
                }
1560
				}
1496
	            long rItemId;
1561
				long rItemId;
1497
	            if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
1562
				if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
1498
	                logger.error("Error updating item on production, returned Item Id: " + rItemId);
1563
					logger.error("Error updating item on production, returned Item Id: " + rItemId);
1499
	                return "Error updating expected delay on production";
1564
					return "Error updating expected delay on production";
1500
	            }
1565
				}
1501
	            InventoryClient inventoryServiceClient= new InventoryClient();
1566
				InventoryClient inventoryServiceClient= new InventoryClient();
1502
	            InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1567
				InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
1503
	            inventoryClient.clearItemAvailabilityCacheForItem(rItemId);
1568
				inventoryClient.clearItemAvailabilityCacheForItem(rItemId);
1504
	            logger.info("Successfully updated item: " + item.getId());
1569
				logger.info("Successfully updated item: " + item.getId());
1505
	            return "Expected delay successfully updated on prod"; 
1570
				return "Expected delay successfully updated on prod"; 
1506
            } else {
1571
			} else {
1507
            	return "Error:expected delay should not be null";
1572
				return "Error:expected delay should not be null";
1508
            }
1573
			}
1509
        } catch (Exception e) {
1574
		} catch (Exception e) {
1510
            logger.error("Error while updating expected delay on production", e);
1575
			logger.error("Error while updating expected delay on production", e);
1511
            return "Error while updating expected delay on production";
1576
			return "Error while updating expected delay on production";
1512
        }
1577
		}
1513
	}
1578
	}
1514
 
1579
 
1515
	@Override
1580
	@Override
1516
	public Map<Long, String> getAllInsurers() {
1581
	public Map<Long, String> getAllInsurers() {
1517
		 Map<Long, String> insurersMap = new HashMap<Long, String>();
1582
		Map<Long, String> insurersMap = new HashMap<Long, String>();
1518
	        try {
1583
		try {
1519
	            CatalogClient catalogServiceClient = new CatalogClient();
1584
			CatalogClient catalogServiceClient = new CatalogClient();
1520
	            in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
1585
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
1521
	            
1586
 
1522
	            List<Insurer> insurers = catalogClient.getAllInsurers();
1587
			List<Insurer> insurers = catalogClient.getAllInsurers();
1523
 
1588
 
1524
	            for(in.shop2020.model.v1.catalog.Insurer i : insurers) {
1589
			for(in.shop2020.model.v1.catalog.Insurer i : insurers) {
1525
	                insurersMap.put(i.getId(), i.getName());
1590
				insurersMap.put(i.getId(), i.getName());
1526
	            }
1591
			}
1527
	        } catch (Exception e) {
1592
		} catch (Exception e) {
1528
	            logger.error("Error while getting all the vendors: ", e);
1593
			logger.error("Error while getting all the vendors: ", e);
1529
	        }
1594
		}
1530
	        return insurersMap;
1595
		return insurersMap;
1531
	}
1596
	}
1532
	
1597
 
1533
	private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
1598
	private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
1534
            List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
1599
			List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
1535
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
1600
			List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
1536
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
1601
			List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
1537
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, 
1602
			List<in.shop2020.model.v1.catalog.Item> tSimilarItems, 
1538
            in.shop2020.model.v1.inventory.ItemInventory tItemInventory, 
1603
			in.shop2020.model.v1.inventory.ItemInventory tItemInventory, 
1539
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings, 
1604
			List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings, 
1540
            ItemStockPurchaseParams tStockPurchaseParams, Map<Long,String> saleHistory, Long freebieItemId,Map<String,String> stateNameVatPercentageMap){
1605
			ItemStockPurchaseParams tStockPurchaseParams, Map<Long,String> saleHistory, Long freebieItemId,Map<String,String> stateNameVatPercentageMap,in.shop2020.model.v1.catalog.PrivateDeal tPrivateDeal){
1541
 
1606
 
1542
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
1607
		Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
1543
        VendorItemMapping vItemMapping;
1608
		VendorItemMapping vItemMapping;
1544
        if(tVendorMappings != null) {
1609
		if(tVendorMappings != null) {
1545
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
1610
			for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
1546
                vItemMapping = new VendorItemMapping();
1611
				vItemMapping = new VendorItemMapping();
1547
                vItemMapping.setVendorId(vim.getVendorId());
1612
				vItemMapping.setVendorId(vim.getVendorId());
1548
                vItemMapping.setItemKey(vim.getItemKey());
1613
				vItemMapping.setItemKey(vim.getItemKey());
1549
                vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
1614
				vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
1550
            }
1615
			}
1551
        }
1616
		}
1552
 
1617
 
1553
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
1618
		Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
1554
        VendorPricings vPricings;
1619
		VendorPricings vPricings;
1555
        if(tVendorPricings != null) {
1620
		if(tVendorPricings != null) {
1556
            for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
1621
			for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
1557
                vPricings = new VendorPricings();
1622
				vPricings = new VendorPricings();
1558
                vPricings.setVendorId(vip.getVendorId());
1623
				vPricings.setVendorId(vip.getVendorId());
1559
                vPricings.setMop(vip.getMop());
1624
				vPricings.setMop(vip.getMop());
1560
                vPricings.setDealerPrice(vip.getDealerPrice());
1625
				vPricings.setDealerPrice(vip.getDealerPrice());
1561
                vPricings.setTransferPrice(vip.getTransferPrice());
1626
				vPricings.setTransferPrice(vip.getTransferPrice());
1562
                vPricings.setNlc(vip.getNlc());
1627
				vPricings.setNlc(vip.getNlc());
1563
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
1628
				vendorPricingMap.put(vPricings.getVendorId(), vPricings);
1564
            }
1629
			}
1565
        }
1630
		}
1566
 
1631
 
1567
        Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
1632
		Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
1568
        SourcePricings sPricings;
1633
		SourcePricings sPricings;
1569
        if(tSourceMappings != null) {
1634
		if(tSourceMappings != null) {
1570
            for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
1635
			for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
1571
                sPricings = new SourcePricings();
1636
				sPricings = new SourcePricings();
1572
                sPricings.setSourceId(sip.getSourceId());
1637
				sPricings.setSourceId(sip.getSourceId());
1573
                sPricings.setMrp(sip.getMrp());
1638
				sPricings.setMrp(sip.getMrp());
1574
                sPricings.setSellingPrice(sip.getSellingPrice());
1639
				sPricings.setSellingPrice(sip.getSellingPrice());
1575
                sourcePricingMap.put(sPricings.getSourceId(), sPricings);
1640
				sourcePricingMap.put(sPricings.getSourceId(), sPricings);
1576
            }
1641
			}
1577
        }
1642
		}
1578
        
1643
 
1579
        Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
1644
		Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
1580
        Item sItems;
1645
		Item sItems;
1581
        if(tSimilarItems != null) {
1646
		if(tSimilarItems != null) {
1582
            for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
1647
			for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
1583
            	sItems = new Item();
1648
				sItems = new Item();
1584
            	sItems.setCatalogItemId(sit.getCatalogItemId());
1649
				sItems.setCatalogItemId(sit.getCatalogItemId());
1585
            	sItems.setProductGroup(sit.getProductGroup());
1650
				sItems.setProductGroup(sit.getProductGroup());
1586
            	sItems.setBrand(sit.getBrand());
1651
				sItems.setBrand(sit.getBrand());
1587
            	sItems.setModelNumber(sit.getModelNumber());
1652
				sItems.setModelNumber(sit.getModelNumber());
1588
            	sItems.setModelName(sit.getModelName());
1653
				sItems.setModelName(sit.getModelName());
1589
            	sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
1654
				sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
1590
            	SimilarItemslist.put(sit.getCatalogItemId(), sItems);
1655
				SimilarItemslist.put(sit.getCatalogItemId(), sItems);
1591
            }
1656
			}
1592
        }
1657
		}
1593
 
1658
 
1594
        Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1659
		Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
1595
        ItemInventory warehousedata;
1660
		ItemInventory warehousedata;
1596
        if(tItemInventory != null) {
1661
		if(tItemInventory != null) {
1597
        	Map<Long, Long> availabilityMap = tItemInventory.getAvailability();
1662
			Map<Long, Long> availabilityMap = tItemInventory.getAvailability();
1598
        	Map<Long, Long> reservedMap = tItemInventory.getReserved();
1663
			Map<Long, Long> reservedMap = tItemInventory.getReserved();
1599
        	Map<Long, Long> heldMap = tItemInventory.getHeld();
1664
			Map<Long, Long> heldMap = tItemInventory.getHeld();
1600
            for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1665
			for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
1601
            	Map<Integer, Long> heldInventoryMap = new HashMap<Integer, Long>();
1666
				Map<Integer, Long> heldInventoryMap = new HashMap<Integer, Long>();
1602
            	warehousedata = new ItemInventory();
1667
				warehousedata = new ItemInventory();
1603
            	warehousedata.setWarehouseId(availability.getKey());
1668
				warehousedata.setWarehouseId(availability.getKey());
1604
            	warehousedata.setAvailability(availability.getValue());
1669
				warehousedata.setAvailability(availability.getValue());
1605
            	warehousedata.setReserved(reservedMap.get(availability.getKey()));
1670
				warehousedata.setReserved(reservedMap.get(availability.getKey()));
1606
            	warehousedata.setHeld(heldMap.get(availability.getKey()));
1671
				warehousedata.setHeld(heldMap.get(availability.getKey()));
1607
            	try {
1672
				try {
1608
	            	if(warehousedata.getHeld()>0) {
1673
					if(warehousedata.getHeld()>0) {
1609
	            		InventoryService.Client inventoryClient = new InventoryClient().getClient();
1674
						InventoryService.Client inventoryClient = new InventoryClient().getClient();
1610
	            		heldInventoryMap = inventoryClient.getHeldInventoryMapForItem(thriftItem.getId(), availability.getKey());
1675
						heldInventoryMap = inventoryClient.getHeldInventoryMapForItem(thriftItem.getId(), availability.getKey());
1611
	            	}
1676
					}
1612
	            	if(heldInventoryMap.size()>0) {
1677
					if(heldInventoryMap.size()>0) {
1613
	            		for(Integer source : heldInventoryMap.keySet()) {
1678
						for(Integer source : heldInventoryMap.keySet()) {
1614
	            			switch(source) {
1679
							switch(source) {
1615
	            				case EBAYSOURCE: warehousedata.setEbayHeld(heldInventoryMap.get(source));
1680
							case EBAYSOURCE: warehousedata.setEbayHeld(heldInventoryMap.get(source));
1616
	            				break;
1681
							break;
1617
	            				case SNAPDEALSOURCE: warehousedata.setSnapdealHeld(heldInventoryMap.get(source));
1682
							case SNAPDEALSOURCE: warehousedata.setSnapdealHeld(heldInventoryMap.get(source));
1618
	            				break;
1683
							break;
1619
	            				case FLIPKARTSOURCE: warehousedata.setFlipkartHeld(heldInventoryMap.get(source));
1684
							case FLIPKARTSOURCE: warehousedata.setFlipkartHeld(heldInventoryMap.get(source));
1620
	            			}
1685
							}
1621
	            		}
1686
						}
1622
	            	}
1687
					}
1623
            	} catch (Exception e) {
1688
				} catch (Exception e) {
1624
            		logger.error("Error in getting data from holdInventoryDetail for itemId " + thriftItem.getId() + 
1689
					logger.error("Error in getting data from holdInventoryDetail for itemId " + thriftItem.getId() + 
1625
            				" and warehouse " +availability.getKey());
1690
							" and warehouse " +availability.getKey());
1626
            	}
1691
				}
1627
            	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1692
				itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
1628
            }
1693
			}
1629
        }
1694
		}
1630
        else {
1695
		else {
1631
        	itemInventoryMap = null;
1696
			itemInventoryMap = null;
1632
        }
1697
		}
1633
        
1698
 
1634
        Map<String, VoucherItemMapping> voucherMap = new HashMap<String, VoucherItemMapping>();
1699
		Map<String, VoucherItemMapping> voucherMap = new HashMap<String, VoucherItemMapping>();
1635
        VoucherItemMapping voucher;
1700
		VoucherItemMapping voucher;
1636
        if(tVoucherMappings != null) {
1701
		if(tVoucherMappings != null) {
1637
            for(in.shop2020.model.v1.catalog.VoucherItemMapping tvoucher : tVoucherMappings) {
1702
			for(in.shop2020.model.v1.catalog.VoucherItemMapping tvoucher : tVoucherMappings) {
1638
            	voucher = new VoucherItemMapping(tvoucher.getAmount(), VoucherType.findByValue((int) tvoucher.getVoucherType()).name());
1703
				voucher = new VoucherItemMapping(tvoucher.getAmount(), VoucherType.findByValue((int) tvoucher.getVoucherType()).name());
1639
            	voucherMap.put(VoucherType.findByValue((int) tvoucher.getVoucherType()).name(), voucher);
1704
				voucherMap.put(VoucherType.findByValue((int) tvoucher.getVoucherType()).name(), voucher);
1640
            }
1705
			}
1641
        }
1706
		}
1642
       
1707
 
1643
        in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams stockPurchaseParams = 
1708
		in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams stockPurchaseParams = 
1644
        	new in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams();
1709
			new in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams();
1645
        if(tStockPurchaseParams != null) {
1710
		if(tStockPurchaseParams != null) {
1646
        	stockPurchaseParams.setItem_id(tStockPurchaseParams.getItem_id());
1711
			stockPurchaseParams.setItem_id(tStockPurchaseParams.getItem_id());
1647
        	stockPurchaseParams.setMinStockLevel(tStockPurchaseParams.getMinStockLevel());
1712
			stockPurchaseParams.setMinStockLevel(tStockPurchaseParams.getMinStockLevel());
1648
        	stockPurchaseParams.setNumOfDaysStock(tStockPurchaseParams.getNumOfDaysStock());
1713
			stockPurchaseParams.setNumOfDaysStock(tStockPurchaseParams.getNumOfDaysStock());
1649
        }
1714
		}
1650
        
1715
		in.shop2020.catalog.dashboard.shared.PrivateDeal privateDeal=null;
1651
        Item item = new Item(thriftItem.getId(),
1716
		if(tPrivateDeal!=null){
1652
                thriftItem.getProductGroup(),
1717
			privateDeal= new in.shop2020.catalog.dashboard.shared.PrivateDeal();
1653
                thriftItem.getBrand(),
1718
			privateDeal.setDealFreebieItemId(tPrivateDeal.getDealFreebieItemId());
1654
                thriftItem.getModelNumber(),
1719
			privateDeal.setItem_id(tPrivateDeal.getItem_id());
1655
                thriftItem.getModelName(),
1720
			privateDeal.setDealPrice(tPrivateDeal.getDealPrice());
1656
                thriftItem.getColor(),
1721
			privateDeal.setDealFreebieItemId(tPrivateDeal.getDealFreebieItemId());
1657
                CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
1722
			if(tPrivateDeal.isSetStartDate()){
1658
                thriftItem.getCategory(),
1723
				privateDeal.setStartDate(tPrivateDeal.getStartDate());
1659
                thriftItem.getComments(),
1724
			}
1660
                thriftItem.getCatalogItemId(),
1725
			else{
1661
                thriftItem.getFeatureId(),
1726
				privateDeal.setStartDate(null);
1662
                thriftItem.getFeatureDescription(),
1727
			}
1663
                thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
1728
			if(tPrivateDeal.isSetEndDate()){
1664
                thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
1729
				privateDeal.setEndDate(tPrivateDeal.getEndDate());
1665
                thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
1730
			}
1666
                thriftItem.getAddedOn(),
1731
			else{
1667
                thriftItem.getStartDate(),
1732
				privateDeal.setEndDate(null);
1668
                thriftItem.isSetComingSoonStartDate() ? thriftItem.getComingSoonStartDate() : null ,
1733
			}
1669
                thriftItem.isSetExpectedArrivalDate() ? thriftItem.getExpectedArrivalDate() : null ,
1734
			privateDeal.setDealTextOption(tPrivateDeal.getDealTextOption());
1670
                thriftItem.getRetireDate(),
1735
			privateDeal.setRank(tPrivateDeal.getRank());
1671
                thriftItem.getUpdatedOn(),
1736
			privateDeal.setCod(tPrivateDeal.isIsCod());
1672
                thriftItem.getItemStatus().name(),
1737
			privateDeal.setDealFreebieOption(tPrivateDeal.getDealFreebieOption());
1673
                thriftItem.getItemStatus().getValue(),
1738
			if(tPrivateDeal.getDealText()!=null){
1674
                thriftItem.getStatus_description(),
1739
				privateDeal.setDealText(tPrivateDeal.getDealText());
1675
                thriftItem.getBestDealText(),
1740
			}
1676
                thriftItem.getBestDealsDetailsText(),
1741
			else{
1677
                thriftItem.getBestDealsDetailsLink(),
1742
				privateDeal.setDealText("");
1678
                thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
1743
			}
1679
                thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
1744
 
1680
                thriftItem.isDefaultForEntity(),
1745
			privateDeal.setActive(tPrivateDeal.isIsActive());
1681
                thriftItem.isRisky(),
1746
		}
1682
                thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
1747
		Item item = new Item(thriftItem.getId(),
1683
                thriftItem.isIsWarehousePreferenceSticky(),
1748
				thriftItem.getProductGroup(),
1684
                thriftItem.isHasItemNo(),
1749
				thriftItem.getBrand(),
1685
                ItemType.SERIALIZED.equals(thriftItem.getType()),
1750
				thriftItem.getModelNumber(),
1686
                thriftItem.isSetShowSellingPrice() ? thriftItem.isShowSellingPrice() : false,
1751
				thriftItem.getModelName(),
1687
                thriftItem.isHoldOverride(),
1752
				thriftItem.getColor(),
1688
                thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
1753
				CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
1689
                thriftItem.isSetPreferredInsurer() ? thriftItem.getPreferredInsurer() : null,		
1754
				thriftItem.getCategory(),
1690
                itemInventoryMap,
1755
				thriftItem.getComments(),
1691
                vendorPricingMap,
1756
				thriftItem.getCatalogItemId(),
1692
                vItemMap,
1757
				thriftItem.getFeatureId(),
1693
                sourcePricingMap,
1758
				thriftItem.getFeatureDescription(),
1694
                SimilarItemslist,
1759
				thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
1695
                voucherMap, 
1760
						thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
1696
                stockPurchaseParams.getNumOfDaysStock(), 
1761
								thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
1697
                stockPurchaseParams.getMinStockLevel(), 
1762
										thriftItem.getAddedOn(),
1698
                saleHistory, 
1763
										thriftItem.getStartDate(),
1699
                freebieItemId,
1764
										thriftItem.isSetComingSoonStartDate() ? thriftItem.getComingSoonStartDate() : null ,
1700
                thriftItem.getAsin(),
1765
												thriftItem.isSetExpectedArrivalDate() ? thriftItem.getExpectedArrivalDate() : null ,
1701
                thriftItem.getHoldInventory(),
1766
														thriftItem.getRetireDate(),
1702
                thriftItem.getDefaultInventory(),stateNameVatPercentageMap);
1767
														thriftItem.getUpdatedOn(),
1703
        return item;
1768
														thriftItem.getItemStatus().name(),
1704
    }
1769
														thriftItem.getItemStatus().getValue(),
-
 
1770
														thriftItem.getStatus_description(),
-
 
1771
														thriftItem.getBestDealText(),
-
 
1772
														thriftItem.getBestDealsDetailsText(),
-
 
1773
														thriftItem.getBestDealsDetailsLink(),
-
 
1774
														thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
-
 
1775
																thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
-
 
1776
																		thriftItem.isDefaultForEntity(),
-
 
1777
																		thriftItem.isRisky(),
-
 
1778
																		thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
-
 
1779
																				thriftItem.isIsWarehousePreferenceSticky(),
-
 
1780
																				thriftItem.isHasItemNo(),
-
 
1781
																				ItemType.SERIALIZED.equals(thriftItem.getType()),
-
 
1782
																				thriftItem.isSetShowSellingPrice() ? thriftItem.isShowSellingPrice() : false,
-
 
1783
																						thriftItem.isHoldOverride(),
-
 
1784
																						thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
-
 
1785
																								thriftItem.isSetPreferredInsurer() ? thriftItem.getPreferredInsurer() : null,		
-
 
1786
																										itemInventoryMap,
-
 
1787
																										vendorPricingMap,
-
 
1788
																										vItemMap,
-
 
1789
																										sourcePricingMap,
-
 
1790
																										SimilarItemslist,
-
 
1791
																										voucherMap, 
-
 
1792
																										stockPurchaseParams.getNumOfDaysStock(), 
-
 
1793
																										stockPurchaseParams.getMinStockLevel(), 
-
 
1794
																										saleHistory, 
-
 
1795
																										freebieItemId,
-
 
1796
																										thriftItem.getAsin(),
-
 
1797
																										thriftItem.getHoldInventory(),
-
 
1798
																										thriftItem.getDefaultInventory(),stateNameVatPercentageMap,privateDeal);
-
 
1799
		return item;
-
 
1800
	}
1705
}
1801
}