Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
9404 vikram.rag 1
package in.shop2020;
2
 
9456 vikram.rag 3
import in.shop2020.model.v1.catalog.CatalogService;
9404 vikram.rag 4
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.SnapdealItem;
9495 vikram.rag 6
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
9404 vikram.rag 7
import in.shop2020.model.v1.inventory.InventoryService.Client;
8
import in.shop2020.model.v1.inventory.InventoryType;
9
import in.shop2020.model.v1.inventory.ItemInventory;
10
import in.shop2020.model.v1.inventory.SnapdealInventoryItem;
11
import in.shop2020.model.v1.inventory.Warehouse;
12
import in.shop2020.model.v1.inventory.WarehouseType;
13
import in.shop2020.thrift.clients.CatalogClient;
14
import in.shop2020.thrift.clients.InventoryClient;
15
import in.shop2020.thrift.clients.TransactionClient;
9459 vikram.rag 16
import in.shop2020.utils.GmailUtils;
9404 vikram.rag 17
import inventory.Inventory;
9456 vikram.rag 18
import inventory.InventoryHistory;
19
import inventory.InventoryHistoryItems;
9404 vikram.rag 20
import inventory.InventoryItems;
9495 vikram.rag 21
import inventory.PendingOrderInventoryHistory;
9404 vikram.rag 22
import inventory.SnapdealItemForInventory;
23
 
24
import java.io.BufferedReader;
9459 vikram.rag 25
import java.io.File;
9404 vikram.rag 26
import java.io.FileInputStream;
27
import java.io.FileNotFoundException;
28
import java.io.FileOutputStream;
29
import java.io.IOException;
30
import java.io.InputStreamReader;
31
import java.io.UnsupportedEncodingException;
32
import java.util.ArrayList;
9459 vikram.rag 33
import java.util.Calendar;
34
import java.util.GregorianCalendar;
9404 vikram.rag 35
import java.util.HashMap;
36
import java.util.List;
37
import java.util.Map;
9495 vikram.rag 38
import java.util.Map.Entry;
9404 vikram.rag 39
 
9459 vikram.rag 40
import javax.mail.MessagingException;
41
 
9404 vikram.rag 42
import org.apache.http.HttpResponse;
43
import org.apache.http.NameValuePair;
44
import org.apache.http.client.ClientProtocolException;
45
import org.apache.http.client.HttpClient;
46
import org.apache.http.client.entity.UrlEncodedFormEntity;
47
import org.apache.http.client.methods.HttpGet;
48
import org.apache.http.client.methods.HttpPost;
9510 vikram.rag 49
import org.apache.http.entity.mime.MultipartEntity;
50
import org.apache.http.entity.mime.content.ContentBody;
51
import org.apache.http.entity.mime.content.FileBody;
9404 vikram.rag 52
import org.apache.http.impl.client.DefaultHttpClient;
53
import org.apache.http.message.BasicNameValuePair;
54
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
55
import org.apache.poi.ss.usermodel.Row;
56
import org.apache.poi.ss.usermodel.Sheet;
57
import org.apache.poi.ss.usermodel.Workbook;
58
import org.apache.thrift.TException;
59
import org.apache.thrift.transport.TTransportException;
9456 vikram.rag 60
 
9404 vikram.rag 61
import com.google.gson.Gson;
62
 
63
public class CreateSnapDealInventoryFeed {
9456 vikram.rag 64
	private static long time = System.currentTimeMillis();
9415 vikram.rag 65
	private static String SNAPDEAL_INVENTORY_SHEET;
9404 vikram.rag 66
	private static Map<Long, SnapdealItemForInventory> allItemsInventoryMap = new HashMap<Long, SnapdealItemForInventory>();
9501 vikram.rag 67
	private static ArrayList<Inventory> currentInventoryItemList;
9404 vikram.rag 68
	static Map<Long,Long> itemIdpendingOrdersMap = new HashMap<Long,Long>();
9456 vikram.rag 69
	private static Map<String,InventoryHistory> inventoryhistoryItemMap;
70
	private static DefaultHttpClient client = new DefaultHttpClient();
9495 vikram.rag 71
	static Map<String,SnapdealItemDetails> snapdealItemMap = new HashMap<String,SnapdealItemDetails>();
72
	static Map<Long,SnapdealItemDetails> itemSnapdealMap = new HashMap<Long,SnapdealItemDetails>();
73
	static Map<String,PendingOrderInventoryHistory> PendingOrdersInventoryHistoryMap = new HashMap<String,PendingOrderInventoryHistory>();
74
	static long lastUpdatedInventoryTime = 0;
75
	static{
76
		CatalogClient catalogServiceClient = null;
77
		try {
78
			catalogServiceClient = new CatalogClient();
79
		} catch (TTransportException e1) {
80
			// TODO Auto-generated catch block
81
			e1.printStackTrace();
82
		}
83
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
84
		List<SnapdealItemDetails> allSnapdealItems = null;
85
		try {
86
			allSnapdealItems = catalogClient.getAllSnapdealItems();
87
		} catch (TException e) {
88
			// TODO Auto-generated catch block
89
			e.printStackTrace();
90
		}
91
		for(SnapdealItemDetails snapdealItem:allSnapdealItems){
92
			snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
93
			itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
9502 vikram.rag 94
			System.out.println("Creating Item and Snapdeal Map " + snapdealItem.getItem_id() + " " + snapdealItem.getSkuAtSnapdeal());
9495 vikram.rag 95
		}
96
		in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
97
		try {
9497 vikram.rag 98
			transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9495 vikram.rag 99
			lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
9498 vikram.rag 100
			System.out.println("Time is " + lastUpdatedInventoryTime);
9495 vikram.rag 101
		} catch (Exception e) {
102
			try {
9497 vikram.rag 103
				transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9495 vikram.rag 104
				lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
105
			} catch (Exception ex) {
106
				ex.printStackTrace();
107
			}
108
		}
109
 
110
	}
111
 
9404 vikram.rag 112
	private static void calculateinventory(){
113
		CatalogClient catalogServiceClient = null;
114
		Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
115
		try {
116
			catalogServiceClient = new CatalogClient();
117
		} catch (TTransportException e) {
118
			// TODO Auto-generated catch block
119
			e.printStackTrace();
120
		}
121
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
122
		try {
123
			List<Item> aliveItems = catalogClient.getAllAliveItems();
124
			Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>(); 
125
			for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
126
				aliveItemsMap.put(thriftItem.getId(), thriftItem);
127
 
128
			}
9495 vikram.rag 129
			InventoryClient inventoryServiceClient = new InventoryClient();
9404 vikram.rag 130
			try {
131
				inventoryServiceClient = new InventoryClient();
132
			} catch (TTransportException e) {
133
				e.printStackTrace();
134
			}
135
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
136
			List<in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems> ignoreItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
9415 vikram.rag 137
			SNAPDEAL_INVENTORY_SHEET = "/home/snapdeal/snapdeal-inventory-"+time+".xls";
9404 vikram.rag 138
			availability = inventoryClient.getInventorySnapshot(0);
9456 vikram.rag 139
			List<Warehouse> allwarehouses = inventoryClient.getWarehouses(null,null,0,0,0);
140
			Map<Long,Warehouse> allWarehousesMap = new HashMap<Long,Warehouse>();
141
			for(Warehouse warehouse:allwarehouses){
142
				allWarehousesMap.put(warehouse.getId(),warehouse);
143
			}
9404 vikram.rag 144
			List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS_THIRDPARTY,null,0,0,0);
145
			List<Warehouse> ours_warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 0, 0, 0);
146
			List<Long> thirdpartywarehouseids = new ArrayList<Long>();
147
			List<Long> oursGoodWarehouse = new ArrayList<Long>();
148
			for(Warehouse warehouse:warehouses){
149
				thirdpartywarehouseids.add(warehouse.getId());
150
			}
151
			for (Warehouse warehouse:ours_warehouses){
152
				oursGoodWarehouse.add(warehouse.getId());
153
			}
154
			long available=0;
155
			long reserve=0;
156
			long total_held=0;
157
			long heldForSource=0;
158
			double nlc=0;
159
			double maxnlc=0;
160
			Item thriftItem;
9456 vikram.rag 161
			long sku = 0;
9501 vikram.rag 162
			for(Inventory inventoryItem:currentInventoryItemList){
9495 vikram.rag 163
				if(snapdealItemMap.containsKey(inventoryItem.getSellerSku())){
164
					sku = snapdealItemMap.get(inventoryItem.getSellerSku()).getItem_id();
9404 vikram.rag 165
				}
9495 vikram.rag 166
				else{
167
					continue;
9456 vikram.rag 168
				}
169
				if(aliveItemsMap.get(sku) != null){
170
					thriftItem = aliveItemsMap.get(sku);	
171
				}
9404 vikram.rag 172
				else{
173
					continue;
174
				}
175
				available=0;
176
				reserve=0;
177
				total_held=0;
178
				heldForSource=0;
179
				nlc=0;
180
				List<Warehouse> vendor_warehouses=null;
181
				SnapdealItemForInventory item;
182
				if(availability.get(thriftItem.getId())!=null){ 
183
					ItemInventory iteminventory = availability.get(thriftItem.getId());
184
					Map<Long,Long> itemavailability = new HashMap<Long,Long>();
185
					itemavailability = iteminventory.getAvailability();
186
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
187
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating availability)"+thriftItem.getPreferredVendor());						
188
						vendor_warehouses = inventoryClient.getWarehouses(WarehouseType.THIRD_PARTY,InventoryType.GOOD , thriftItem.getPreferredVendor(), 0, 0);
189
						vendor_warehouses.addAll(ours_warehouses);
190
						for (Warehouse warehouse:vendor_warehouses){
9456 vikram.rag 191
							if(warehouse.getBillingWarehouseId()!=7){
192
								continue;
193
							}
9404 vikram.rag 194
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
195
							ignoredItem.setItemId(thriftItem.getId());
196
							ignoredItem.setWarehouseId(warehouse.getId());
197
							if (itemavailability.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(ignoredItem)){
198
								try{
199
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
200
								}
201
								catch(TTransportException e){
202
									inventoryClient = inventoryServiceClient.getClient(); 
203
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
204
								}
205
								maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
9413 vikram.rag 206
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
9404 vikram.rag 207
								if(nlc !=0 && (maxnlc >= nlc)){
208
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
209
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 7);
210
									available = available + itemavailability.get(warehouse.getId()) - total_held;
9413 vikram.rag 211
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9404 vikram.rag 212
								}
9413 vikram.rag 213
								else if(maxnlc==0){
214
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
215
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 7);
216
									available = available + itemavailability.get(warehouse.getId()) - total_held;
217
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9404 vikram.rag 218
								}
219
							}
220
						}
221
					}
222
					else{
223
						for (Map.Entry<Long,Long> entry :  itemavailability.entrySet()) {
9456 vikram.rag 224
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
225
								continue;
226
							}
9404 vikram.rag 227
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
228
							ignoredItem.setItemId(thriftItem.getId());
229
							ignoredItem.setWarehouseId(entry.getKey());
230
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
9509 vikram.rag 231
 
9404 vikram.rag 232
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
233
								try{
234
									maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
235
								}
236
								catch(TTransportException e){
237
									catalogClient = catalogServiceClient.getClient();  
238
									maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
239
								}
9509 vikram.rag 240
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
9404 vikram.rag 241
								if(nlc !=0 && (maxnlc >= nlc)){
242
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
243
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 7);
244
									available =  available + entry.getValue() - total_held;
9509 vikram.rag 245
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9404 vikram.rag 246
								}
9413 vikram.rag 247
								else if(maxnlc==0){
248
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
249
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 7);
250
									available = available + itemavailability.get(entry.getKey()) - total_held;
9509 vikram.rag 251
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9413 vikram.rag 252
								}
253
 
9404 vikram.rag 254
							}
255
						}
256
					}
257
					Map<Long,Long> itemreserve = new HashMap<Long,Long>();
258
					itemreserve = iteminventory.getReserved();
259
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
260
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating Reserve)"+thriftItem.getPreferredVendor());
261
						for (Warehouse warehouse:vendor_warehouses){
9456 vikram.rag 262
							if(warehouse.getBillingWarehouseId()!=7){
263
								continue;
264
							}
9404 vikram.rag 265
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
266
							ignoredItem.setItemId(thriftItem.getId());
267
							ignoredItem.setWarehouseId(warehouse.getId());
268
							if (itemreserve.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(warehouse.getId())){
269
								nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
270
								maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
9509 vikram.rag 271
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
9404 vikram.rag 272
								if(nlc !=0 && (maxnlc >= nlc)){
273
									reserve = reserve + itemreserve.get(warehouse.getId());
9413 vikram.rag 274
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
9404 vikram.rag 275
								}
9413 vikram.rag 276
								else if(maxnlc==0){
277
									reserve = reserve + itemreserve.get(warehouse.getId());
278
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
279
								}
280
 
9404 vikram.rag 281
							}
282
						}
283
					}else{
284
						for (Map.Entry<Long,Long> entry : itemreserve.entrySet()) {
9456 vikram.rag 285
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
286
								continue;
287
							}
9404 vikram.rag 288
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
289
							ignoredItem.setItemId(thriftItem.getId());
290
							ignoredItem.setWarehouseId(entry.getKey());
291
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
292
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
293
								maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
9509 vikram.rag 294
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
9404 vikram.rag 295
								if(nlc !=0 && (maxnlc >= nlc)){
296
									reserve =  reserve + entry.getValue();
9413 vikram.rag 297
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
9404 vikram.rag 298
								}
9413 vikram.rag 299
								else if(maxnlc==0){
300
									reserve =  reserve + entry.getValue();
301
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
302
								}
303
 
9404 vikram.rag 304
							}
9413 vikram.rag 305
 
9404 vikram.rag 306
							else{
307
								//System.out.println("skipping inventory for warehouse id " + entry.getKey());
308
							}
309
						}
310
					}
311
					item= new SnapdealItemForInventory(thriftItem.getId(),available,reserve,heldForSource,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),thriftItem.isRisky(),thriftItem.getItemStatus());
9413 vikram.rag 312
					System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
9404 vikram.rag 313
				}
314
				else{
315
					item = new SnapdealItemForInventory(thriftItem.getId(),0,0,0,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),thriftItem.isRisky(),thriftItem.getItemStatus());
9413 vikram.rag 316
					System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
9404 vikram.rag 317
				}
318
 
319
				//System.out.println(" Item details are " + thriftItem.getId() +" " + available + " " + reserve + " " + thriftItem.getHoldInventory() + " "+ thriftItem.getDefaultInventory() + " " + thriftItem.isRisky());
320
				//System.out.println("+++++++++++++++++++++++");
321
				allItemsInventoryMap.put(thriftItem.getId(),item);
322
 
323
			}
324
 
325
		} catch (TException e) {
326
			// TODO Auto-generated catch block
327
			e.printStackTrace();
328
		}
329
 
330
	}
9456 vikram.rag 331
	private static void fetchinventoryhistoryfromsnapdeal() throws UnsupportedEncodingException, TException{
9404 vikram.rag 332
		HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
333
		HttpGet get; 
334
		BufferedReader rd= null;
335
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
336
		nameValuePairs.add(new BasicNameValuePair("j_username",
337
		"khushal.bhatia@saholic.com"));
338
		nameValuePairs.add(new BasicNameValuePair("j_password",
339
		"sonline"));
340
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
341
		HttpResponse response = null;
342
		try {
343
			response = client.execute(post);
344
		} catch (ClientProtocolException e) {
345
			// TODO Auto-generated catch block
346
			e.printStackTrace();
347
		} catch (IOException e) {
348
			// TODO Auto-generated catch block
349
			e.printStackTrace();
350
		}
351
		try {
352
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
353
		} catch (IllegalStateException e1) {
354
			// TODO Auto-generated catch block
355
			e1.printStackTrace();
356
		} catch (IOException e1) {
357
			// TODO Auto-generated catch block
358
			e1.printStackTrace();
359
		}
360
		String line = "";
361
		try {
362
			while ((line = rd.readLine()) != null) {
363
				System.out.println(line);
364
			}
365
		} catch (IOException e) {
366
			// TODO Auto-generated catch block
367
			e.printStackTrace();
368
		}
369
		int i = 1;
370
		Gson gson = new Gson();
9456 vikram.rag 371
		inventoryhistoryItemMap = new HashMap<String,InventoryHistory>();
372
		boolean exitfetchinghistory = true;
373
		while(exitfetchinghistory){
374
			System.out.println("Fetching inventory history page " +i);
375
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=dsc");
376
			try {
377
				response = client.execute(get);
378
			} catch (ClientProtocolException e) {
379
				// TODO Auto-generated catch block
380
				e.printStackTrace();
381
			} catch (IOException e) {
382
				// TODO Auto-generated catch block
383
				e.printStackTrace();
384
			}
385
			try {
386
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
387
			} catch (IllegalStateException e) {
388
				// TODO Auto-generated catch block
389
				e.printStackTrace();
390
			} catch (IOException e) {
391
				// TODO Auto-generated catch block
392
				e.printStackTrace();
393
			}
394
			InventoryHistoryItems inventoryhistoryitems = (InventoryHistoryItems) gson.fromJson(rd, InventoryHistoryItems.class);
395
			if(inventoryhistoryitems.getRows().size()!=0){
396
				//System.out.println("Parsing page " + i);
397
				for(InventoryHistory inventoryhistory : inventoryhistoryitems.getRows()){
398
					if(inventoryhistory.getUpdateTime() > lastUpdatedInventoryTime){
399
						if(inventoryhistoryItemMap.containsKey(inventoryhistory.getSellerSku())){
400
							if(inventoryhistoryItemMap.get(inventoryhistory.getSellerSku()).getUpdateTime() < inventoryhistory.getUpdateTime()){  
401
								inventoryhistoryItemMap.put(inventoryhistory.getSellerSku(),inventoryhistory);
402
							}
403
						}
404
						else{
405
							inventoryhistoryItemMap.put(inventoryhistory.getSellerSku(),inventoryhistory);
406
						}
407
					}
408
					else{
409
						exitfetchinghistory = false;
410
					}
411
				}
412
			}
413
			else{
414
				exitfetchinghistory = false;
415
			}
416
			i++;
417
		}
9495 vikram.rag 418
		InventoryClient inventoryServiceClient = new InventoryClient();
419
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
420
		List<SnapdealInventoryItem> snapdealInventoryItemHistoryList = inventoryClient.getSnapdealInventorySnapshot();
421
		if(snapdealInventoryItemHistoryList.size()>0){
422
			for(SnapdealInventoryItem snapdealInventoryItem:snapdealInventoryItemHistoryList){
423
				if(itemSnapdealMap.containsKey(snapdealInventoryItem.getItem_id())){
424
					PendingOrderInventoryHistory pendingOrdersInventoryHistory = new PendingOrderInventoryHistory();
425
					pendingOrdersInventoryHistory.setPendingOrders(snapdealInventoryItem.getPendingOrders());
426
					pendingOrdersInventoryHistory.setInventoryHistory(snapdealInventoryItem.getAvailability());
427
					pendingOrdersInventoryHistory.setLastUpdatedTimestamp(snapdealInventoryItem.getLastUpdatedOnSnapdeal());
428
					PendingOrdersInventoryHistoryMap.put(itemSnapdealMap.get(snapdealInventoryItem.getItem_id()).getSkuAtSnapdeal(), pendingOrdersInventoryHistory);
429
				}
430
			}
431
		}
432
		PendingOrderInventoryHistory  pendingOrdersInventoryHistory;
433
		for(Entry<String, InventoryHistory> inventoryHistoryItem :inventoryhistoryItemMap.entrySet()){
434
			if(PendingOrdersInventoryHistoryMap.containsKey(inventoryHistoryItem.getValue().getSellerSku())){
435
				pendingOrdersInventoryHistory = PendingOrdersInventoryHistoryMap.get(inventoryHistoryItem.getValue().getSellerSku());
436
				pendingOrdersInventoryHistory.setInventoryHistory(Long.parseLong(inventoryHistoryItem.getValue().getNewValue()));
437
				pendingOrdersInventoryHistory.setLastUpdatedTimestamp(inventoryHistoryItem.getValue().getUpdateTime());
438
				PendingOrdersInventoryHistoryMap.put(inventoryHistoryItem.getValue().getSellerSku(),pendingOrdersInventoryHistory);
439
			}
440
			else{
441
				pendingOrdersInventoryHistory = new PendingOrderInventoryHistory();
442
				pendingOrdersInventoryHistory.setInventoryHistory(Long.parseLong(inventoryHistoryItem.getValue().getNewValue()));
443
				pendingOrdersInventoryHistory.setLastUpdatedTimestamp(inventoryHistoryItem.getValue().getUpdateTime());
444
				pendingOrdersInventoryHistory.setPendingOrders(0);
445
				PendingOrdersInventoryHistoryMap.put(inventoryHistoryItem.getValue().getSellerSku(),pendingOrdersInventoryHistory);
446
			}
447
		}
9456 vikram.rag 448
	}
449
 
9495 vikram.rag 450
	private static void fetchcurrentinventoryfromsnapdeal() throws UnsupportedEncodingException, TException{
9456 vikram.rag 451
		/*client = new DefaultHttpClient();
452
		HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
453
		BufferedReader rd= null;
454
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
455
		nameValuePairs.add(new BasicNameValuePair("j_username",
456
		"khushal.bhatia@saholic.com"));
457
		nameValuePairs.add(new BasicNameValuePair("j_password",
458
		"sonline"));
459
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
460
		HttpResponse response = null;
9404 vikram.rag 461
		try {
9456 vikram.rag 462
			response = client.execute(post);
463
		} catch (ClientProtocolException e) {
9404 vikram.rag 464
			// TODO Auto-generated catch block
465
			e.printStackTrace();
9456 vikram.rag 466
		} catch (IOException e) {
467
			// TODO Auto-generated catch block
468
			e.printStackTrace();
9404 vikram.rag 469
		}
9456 vikram.rag 470
		try {
471
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
472
		} catch (IllegalStateException e1) {
473
			// TODO Auto-generated catch block
474
			e1.printStackTrace();
475
		} catch (IOException e1) {
476
			// TODO Auto-generated catch block
477
			e1.printStackTrace();
478
		}
479
		String line = "";
480
		try {
481
			while ((line = rd.readLine()) != null) {
482
				System.out.println(line);
483
			}
484
		} catch (IOException e) {
485
			// TODO Auto-generated catch block
486
			e.printStackTrace();
487
		}*/
488
		int i = 1;
489
		int items=0;
490
		Gson gson = new Gson();
491
		in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
9501 vikram.rag 492
		currentInventoryItemList = new ArrayList<Inventory>();
9456 vikram.rag 493
		HttpGet get;
494
		HttpResponse response = null;
495
		BufferedReader rd= null;
9404 vikram.rag 496
		while(true){
9456 vikram.rag 497
			System.out.println("Fetching current inventory page " +i);
9404 vikram.rag 498
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=normal&_search=false&nd="+time+"&rows="+30+"&page="+i+"&sidx=&sord=asc");
499
			try {
500
				response = client.execute(get);
501
			} catch (ClientProtocolException e) {
502
				// TODO Auto-generated catch block
503
				e.printStackTrace();
504
			} catch (IOException e) {
505
				// TODO Auto-generated catch block
506
				e.printStackTrace();
507
			}
508
			try {
509
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
510
			} catch (IllegalStateException e) {
511
				// TODO Auto-generated catch block
512
				e.printStackTrace();
513
			} catch (IOException e) {
514
				// TODO Auto-generated catch block
515
				e.printStackTrace();
516
			}
517
			InventoryItems inventoryitems = (InventoryItems) gson.fromJson(rd, InventoryItems.class);
518
			if(inventoryitems.getRows().size()!=0){
519
				for(Inventory inventory : inventoryitems.getRows()){
9508 vikram.rag 520
					System.out.println(inventory.getSellerSku());
521
					currentInventoryItemList.add(inventory);
9456 vikram.rag 522
					items++;
523
				}
524
			}
525
			else{
526
				System.out.println("Fetched  " + items);
527
				break;
528
			}
529
			i++;
530
		}
531
		in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
9495 vikram.rag 532
		SnapdealItemDetails snapdealitem = null;
9456 vikram.rag 533
		long sku = 0;
534
		long created_orders;
535
		long pending_orders;
536
		try {
9467 vikram.rag 537
			transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9456 vikram.rag 538
		} catch (TTransportException e1) {
539
			// TODO Auto-generated catch block
540
			e1.printStackTrace();
541
		}
542
		try {
543
			catalogServiceClient = new CatalogClient().getClient();
544
		} catch (TTransportException e1) {
545
			// TODO Auto-generated catch block
546
			e1.printStackTrace();
547
		}
548
		List<String> notMappedItems = new ArrayList<String>();
9501 vikram.rag 549
		for(Inventory inventory:currentInventoryItemList){
9456 vikram.rag 550
			created_orders = 0;
551
			pending_orders = 0;
9495 vikram.rag 552
			try {
553
				snapdealitem = snapdealItemMap.get(inventory.getSellerSku());
554
				if(snapdealitem==null){
9501 vikram.rag 555
					notMappedItems.add("inventory.getSellerSku() "+inventory.getProductName());
9495 vikram.rag 556
					continue;
557
				}
558
				if(sku!=0){
9459 vikram.rag 559
					try{
9495 vikram.rag 560
						if(lastUpdatedInventoryTime > 0){
9499 vikram.rag 561
							System.out.println("Fetching created orders for " + sku);
562
							System.out.println("Last Updated on Time is  " + lastUpdatedInventoryTime);
9495 vikram.rag 563
							created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7, sku);
9404 vikram.rag 564
						}
565
					}
9495 vikram.rag 566
					catch(TTransportException e){
9501 vikram.rag 567
						if(lastUpdatedInventoryTime > 0){
568
							transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
569
							created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7, sku);
570
						}
9459 vikram.rag 571
					}
572
				}
9495 vikram.rag 573
				else{
574
					continue;
575
				}
576
			} catch (TException e) {
577
				// TODO Auto-generated catch block
578
				e.printStackTrace();
9404 vikram.rag 579
			}
9495 vikram.rag 580
			pending_orders = PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).getPendingOrders()+(inventory.getAvailableInventory() - PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).getInventoryHistory() - created_orders);
9456 vikram.rag 581
			itemIdpendingOrdersMap.put(sku, pending_orders);
9495 vikram.rag 582
			PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).setPendingOrders(pending_orders);
9404 vikram.rag 583
		}
9495 vikram.rag 584
		List<SnapdealInventoryItem> snapdealInventoryItemList = new ArrayList<SnapdealInventoryItem>();
585
		SnapdealInventoryItem snapdealInventoryItem;
586
		for(Entry<String, PendingOrderInventoryHistory> pendingOrderInventoryHistory:PendingOrdersInventoryHistoryMap.entrySet()){
587
			snapdealInventoryItem = new SnapdealInventoryItem();
588
			if(snapdealItemMap.containsKey(pendingOrderInventoryHistory.getKey())){
589
				snapdealInventoryItem.setItem_id(snapdealItemMap.get(pendingOrderInventoryHistory.getKey()).getItem_id());
590
				snapdealInventoryItem.setPendingOrders(pendingOrderInventoryHistory.getValue().getPendingOrders());
591
				snapdealInventoryItem.setAvailability(pendingOrderInventoryHistory.getValue().getInventoryHistory());
592
				snapdealInventoryItem.setLastUpdatedOnSnapdeal(pendingOrderInventoryHistory.getValue().getLastUpdatedTimestamp());
593
				snapdealInventoryItemList.add(snapdealInventoryItem);
594
			}
595
		}
596
		InventoryClient inventoryServiceClient = new InventoryClient();
597
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
598
		try {
599
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
600
		} catch (TException e) {
601
			// TODO Auto-generated catch block
602
			e.printStackTrace();
603
			inventoryClient = inventoryServiceClient.getClient();
604
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
605
		}
606
 
9404 vikram.rag 607
	}
608
 
609
	@SuppressWarnings("deprecation")
610
	public static void main(String[] args) throws NumberFormatException, TException, ClientProtocolException, IOException {
9456 vikram.rag 611
		fetchinventoryhistoryfromsnapdeal();
9495 vikram.rag 612
		fetchcurrentinventoryfromsnapdeal();
9404 vikram.rag 613
		calculateinventory();
614
		in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
615
		try {
616
			catalogServiceClient = new CatalogClient().getClient();
617
		} catch (TTransportException e) {
618
			// TODO Auto-generated catch block
619
			e.printStackTrace();
620
		}
621
		Client inventoryClient = new InventoryClient().getClient();
9420 vikram.rag 622
		FileInputStream fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerInventory.xls");
9413 vikram.rag 623
		Workbook hwb = new HSSFWorkbook(fis);
624
		Sheet sheet = hwb.getSheetAt(0);
625
		Row row;
9404 vikram.rag 626
		int iterator=1;
9456 vikram.rag 627
		long availability,reserve,defaultinventory,holdinventory,actualavailability,heldorders=0,sent_inventory;
9404 vikram.rag 628
		SnapdealItemForInventory  inventoryItem;
9456 vikram.rag 629
		StringBuffer outOfStockItems =new StringBuffer();
630
		StringBuffer backInStockItems =new StringBuffer();
631
		long sku = 0;
9502 vikram.rag 632
		SnapdealItemDetails snapdealitem;
9501 vikram.rag 633
		for(Inventory inventory:currentInventoryItemList){
9456 vikram.rag 634
			//System.out.println(inventory.getSupc()+" "+inventory.getSellerSku()+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+inventory.isLive()+" "+itemIdpendingOrdersMap.get(Long.parseLong(inventory.getSellerSku())));
9508 vikram.rag 635
			if(snapdealItemMap.containsKey(inventory.getSellerSku())){
636
				snapdealitem = snapdealItemMap.get(inventory.getSellerSku()); 
637
				sku =  snapdealitem.getItem_id();
638
			}
639
			else{
640
				continue;
641
			}
9404 vikram.rag 642
			if(snapdealitem.getItem_id()!=0 && snapdealitem.isIsListedOnSnapdeal() && !snapdealitem.isSuppressInventoryFeed()){
9495 vikram.rag 643
				inventoryItem = allItemsInventoryMap.get(sku);
9404 vikram.rag 644
				if(inventoryItem==null){
645
					continue;
646
				}
647
				availability = inventoryItem.getAvailability(); 
648
				reserve = inventoryItem.getReserve();
649
				defaultinventory = inventoryItem.getDefaultInventory();
650
				holdinventory = inventoryItem.getHoldInventory();
651
				actualavailability = availability - reserve;
9495 vikram.rag 652
				if(itemIdpendingOrdersMap.containsKey(sku)){
653
					heldorders = itemIdpendingOrdersMap.get(sku);
9458 vikram.rag 654
					if(heldorders < 0){
655
						heldorders = 0;
656
					}
9456 vikram.rag 657
				}
9413 vikram.rag 658
				System.out.println("itemId:" + inventoryItem.getId() + "\tavailable: " + inventoryItem.getAvailability() + "\treserve" + inventoryItem.getReserve() + "\theldForSource:" + inventoryItem.getHeldForSource() + "\twebsite_hold:" + inventoryItem.getHoldInventory() + "\tdefault_inv:" +inventoryItem.getDefaultInventory() + "\theldorders" + heldorders);
9404 vikram.rag 659
				row =   sheet.getRow((short) iterator);
660
				long inventoryForRiskyItem = actualavailability - holdinventory;
661
				if(inventoryItem.getRisky()){
662
					if(inventoryForRiskyItem > 0){
9413 vikram.rag 663
						if((Math.round(inventoryForRiskyItem*2/3) - heldorders + inventoryItem.getHeldForSource()) > 0){
9415 vikram.rag 664
							sent_inventory = Math.round(inventoryForRiskyItem*2/3) - heldorders + inventoryItem.getHeldForSource();
9404 vikram.rag 665
						}
666
						else{
9415 vikram.rag 667
							sent_inventory = 0;
9404 vikram.rag 668
						}
669
					}
670
					else{
9415 vikram.rag 671
						sent_inventory = 0;
9404 vikram.rag 672
					}
673
				}
674
				else{
675
					if(actualavailability > defaultinventory){
9413 vikram.rag 676
						if((Math.round(actualavailability*2/3) +  inventoryItem.getHeldForSource()) > heldorders){
677
							System.out.println("actual" + actualavailability + "\t2/3actual" + Math.round(actualavailability*2/3) +  "\theld for source" + inventoryItem.getHeldForSource() + "\theldorders" +  heldorders + "\tFinal Value is : " + (Math.round(actualavailability*2/3) +  inventoryItem.getHeldForSource() - heldorders));
9415 vikram.rag 678
							sent_inventory = Math.round(actualavailability*2/3) +  inventoryItem.getHeldForSource() - heldorders;
9404 vikram.rag 679
						}
680
						else{
9415 vikram.rag 681
							sent_inventory = 0;
9404 vikram.rag 682
						}
683
					}
684
					else{
685
						if(defaultinventory > heldorders){
9415 vikram.rag 686
							sent_inventory = defaultinventory - heldorders;
9404 vikram.rag 687
						}
688
						else{
9415 vikram.rag 689
							sent_inventory = 0;
9404 vikram.rag 690
						}
691
					}
692
				}
9456 vikram.rag 693
				if(inventory.getAvailableInventory()!= sent_inventory){
694
					row.getCell((short) 0).setCellValue(inventory.getSupc());
695
					row.getCell((short) 1).setCellValue(inventory.getSellerSku());
696
					row.getCell((short) 2).setCellValue(inventory.getProductName());
697
					row.getCell((short) 3).setCellValue(inventory.getAvailableInventory());
698
					row.getCell((short) 4).setCellValue(sent_inventory);
699
					if(inventory.getAvailableInventory()!=0 && sent_inventory==0){
9459 vikram.rag 700
						outOfStockItems.append(sku+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+sent_inventory+"\n");
9456 vikram.rag 701
					}
702
					if(inventory.getAvailableInventory()==0 && sent_inventory!=0){
9459 vikram.rag 703
						backInStockItems.append(sku+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+sent_inventory+"\n");
9456 vikram.rag 704
					}
705
					if(inventory.isLive()){
706
						row.getCell((short) 5).setCellValue("Yes");
707
					}
708
					else{
709
						row.getCell((short) 5).setCellValue("No");
710
					}
711
					iterator++;
9404 vikram.rag 712
				}
713
			}
714
			else{
715
				continue;
716
			}
717
		}
9516 vikram.rag 718
		if(iterator > 1){
719
			FileOutputStream fileOut = null;
720
			fis.close();
721
			try {
722
				System.out.println("Before writing file ");
723
				fileOut = new FileOutputStream(SNAPDEAL_INVENTORY_SHEET);
724
			} catch (FileNotFoundException e) {
725
				// TODO Auto-generated catch block
726
				e.printStackTrace();
727
			}
728
			try {
9459 vikram.rag 729
 
9516 vikram.rag 730
				hwb.write(fileOut);
731
			} catch (IOException e) {
732
				// TODO Auto-generated catch block
733
				e.printStackTrace();
9404 vikram.rag 734
			}
9516 vikram.rag 735
			HttpClient client = new DefaultHttpClient();
736
			HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
737
			BufferedReader rd= null;
738
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
739
			nameValuePairs.add(new BasicNameValuePair("j_username",
740
			"khushal.bhatia@saholic.com"));
741
			nameValuePairs.add(new BasicNameValuePair("j_password",
742
			"sonline"));
743
			post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
744
			HttpResponse response = null;
745
			String line;
746
			try {
747
				response = client.execute(post);
748
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
749
				while ((line = rd.readLine()) != null) {
750
					System.out.println(line);
751
				}
9404 vikram.rag 752
 
9516 vikram.rag 753
			} catch (ClientProtocolException e) {
754
				// TODO Auto-generated catch block
755
				e.printStackTrace();
756
			} catch (IOException e) {
757
				// TODO Auto-generated catch block
758
				e.printStackTrace();
9404 vikram.rag 759
			}
9516 vikram.rag 760
			post = new HttpPost("http://seller.snapdeal.com/inventory/upload");
761
			File file = new File("/root/code/trunk/SnapDealFeeds/SellerInventory.xls");
762
			MultipartEntity mpEntity = new MultipartEntity();
763
			ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
764
			mpEntity.addPart("file", cbFile);
765
			post.setEntity(mpEntity);
766
			response = client.execute(post);
9495 vikram.rag 767
			try {
9516 vikram.rag 768
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
769
			} catch (IllegalStateException e1) {
770
				// TODO Auto-generated catch block
771
				e1.printStackTrace();
772
			} catch (IOException e1) {
773
				// TODO Auto-generated catch block
774
				e1.printStackTrace();
775
			}
776
			line = "";
777
			String feedresponse = null;
778
			try {
779
				while ((line = rd.readLine()) != null) {
780
					System.out.println(line);
781
					feedresponse = line;
782
				}
783
			} catch (IOException e) {
784
				// TODO Auto-generated catch block
785
				e.printStackTrace();
786
			}
787
			in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
788
			long lastSentInventoryTime = System.currentTimeMillis();
789
			try {
9497 vikram.rag 790
				transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9495 vikram.rag 791
				transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
9516 vikram.rag 792
			} catch (Exception e) {
793
				try {
794
					transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
795
					transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
796
				} catch (Exception ex) {
797
					ex.printStackTrace();
798
				}
9495 vikram.rag 799
			}
9516 vikram.rag 800
			java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
801
			String emailFromAddress = "build@shop2020.in";
802
			String password = "cafe@nes";
803
			GmailUtils mailer = new GmailUtils();
804
			String sendTo[] = new String[]{"vikram.raghav@shop2020.in","rajveer.singh@shop2020.in"};
805
			//String sendTo[] = new String[]{"vikram.raghav@shop2020.in","kshitij.sood@shop2020.in"};
806
			/*String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
9459 vikram.rag 807
				"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
808
				"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
9516 vikram.rag 809
			 */
810
			String emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime);
811
			String text = backInStockItems.toString();
812
			if(text.length() > 0){
813
				try {
814
					mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
815
				} catch (MessagingException e) {
816
					e.printStackTrace();
817
				}
9459 vikram.rag 818
			}
9516 vikram.rag 819
			emailSubjectTxt = "Products out of stock on Snapdeal "+sdf.format(lastSentInventoryTime);
820
			text = outOfStockItems.toString();
821
			if(text.length() > 0){
822
				try {
823
					mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
824
				} catch (MessagingException e) {
825
					e.printStackTrace();
826
				}
827
			}
828
			List<File> files = new ArrayList<File>();
829
			files.add(new File(SNAPDEAL_INVENTORY_SHEET));
9459 vikram.rag 830
			try {
9516 vikram.rag 831
				mailer.sendSSLMessage(sendTo,"Inventory File",feedresponse, emailFromAddress, password, files);
9459 vikram.rag 832
			} catch (MessagingException e) {
833
				e.printStackTrace();
834
			}
835
		}
836
 
9495 vikram.rag 837
 
9404 vikram.rag 838
	}
839
 
840
}