Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
9947 vikram.rag 1
package in.shop2020;
2
 
3
import in.shop2020.logistics.DeliveryType;
4
import in.shop2020.logistics.LogisticsInfo;
5
import in.shop2020.logistics.LogisticsServiceException;
6
import in.shop2020.model.v1.catalog.CatalogService.Client;
7
import in.shop2020.model.v1.catalog.FlipkartItem;
8
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.catalog.status;
10
import in.shop2020.model.v1.inventory.InventoryType;
11
import in.shop2020.model.v1.inventory.ItemInventory;
12
import in.shop2020.model.v1.inventory.Warehouse;
13
import in.shop2020.model.v1.inventory.WarehouseLocation;
14
import in.shop2020.model.v1.inventory.WarehouseType;
15
import in.shop2020.model.v1.order.OrderSource;
16
import in.shop2020.serving.model.Order;
17
import in.shop2020.serving.model.OrderItems;
18
import in.shop2020.thrift.clients.CatalogClient;
19
import in.shop2020.thrift.clients.InventoryClient;
20
import in.shop2020.thrift.clients.LogisticsClient;
21
import in.shop2020.thrift.clients.TransactionClient;
22
import inventory.FlipkartInventoryItem;
23
 
24
import java.io.BufferedReader;
25
import java.io.IOException;
26
import java.io.InputStreamReader;
9968 vikram.rag 27
import java.io.UnsupportedEncodingException;
9947 vikram.rag 28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.List;
31
import java.util.Map;
32
import java.util.Map.Entry;
33
 
34
import org.apache.http.HttpResponse;
35
import org.apache.http.NameValuePair;
36
import org.apache.http.auth.AuthScope;
37
import org.apache.http.auth.UsernamePasswordCredentials;
38
import org.apache.http.client.ClientProtocolException;
39
import org.apache.http.client.HttpClient;
40
import org.apache.http.client.entity.UrlEncodedFormEntity;
41
import org.apache.http.client.methods.HttpGet;
42
import org.apache.http.client.methods.HttpPost;
43
import org.apache.http.entity.StringEntity;
44
import org.apache.http.impl.client.DefaultHttpClient;
45
import org.apache.http.message.BasicNameValuePair;
46
import org.apache.thrift.TException;
47
import org.apache.thrift.transport.TTransportException;
48
 
49
import com.google.gson.Gson;
50
 
51
 
52
 
53
public class CreateSubmitFlipkartInventoryFeed {
54
	private static Map<Long, FlipkartInventoryItem> flipkartItemsInventoryMap = new HashMap<Long, FlipkartInventoryItem>();
55
	private static List<FlipkartItem> flipkartItems;
56
	private static List<FlipkartItem> flipkartInventoryItems = new ArrayList<FlipkartItem>();
57
	private static Map<Long,Long> itemIdOrdersMap = new HashMap<Long,Long>();
58
	static
59
	{
60
		List<String> flipkartorderids = null;
61
		Client catalogServiceClient = null;
62
		try {
63
			catalogServiceClient = new CatalogClient().getClient();
64
		} catch (TTransportException e) {
65
			e.printStackTrace();
66
		}
67
		try {
68
			flipkartItems = catalogServiceClient.getAllFlipkartItems();
69
		} catch (TException e) {
70
			e.printStackTrace();
71
		}
72
		for(FlipkartItem flipkartItem:flipkartItems){
73
			if(flipkartItem.isIsListedOnFlipkart() && !flipkartItem.isSuppressInventoryFeed())
74
				flipkartInventoryItems.add(flipkartItem);
75
		}
76
		in.shop2020.model.v1.order.TransactionService.Client transactionClient;
77
		try {
78
			flipkartorderids = FetchOrders();
79
		} catch (ClientProtocolException e1) {
80
			e1.printStackTrace();
81
		} catch (IOException e1) {
82
			e1.printStackTrace();
83
		}
84
		try {
9948 vikram.rag 85
			transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9971 vikram.rag 86
			if(flipkartorderids!=null && flipkartorderids.size()>0){
87
				itemIdOrdersMap = transactionClient.getCreatedOrdersForFlipkart(flipkartorderids);
88
			}
9947 vikram.rag 89
		} catch (TTransportException e) {
90
			e.printStackTrace();
91
		}catch (TException e) {
92
			// TODO Auto-generated catch block
93
			e.printStackTrace();
94
		}
95
 
96
	}
97
 
9967 vikram.rag 98
	public static void main(String[] args) throws ClientProtocolException, TException{
9947 vikram.rag 99
		calculateinventory();
100
		DefaultHttpClient httpclient = new DefaultHttpClient();
9973 vikram.rag 101
		httpclient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpclient);
9974 vikram.rag 102
		//httpclient.getCredentialsProvider().setCredentials(
103
		//		new AuthScope("sandbox-api.flipkart.net", 443),
104
		//		new UsernamePasswordCredentials("og3yg5994bxbxxc1", "8a137068-417c-4e4f-ae95-9295ab938d88"));/// Test Server Access Keys
9951 vikram.rag 105
		httpclient.getCredentialsProvider().setCredentials(
9975 vikram.rag 106
				new AuthScope("api.flipkart.net", 443),
9974 vikram.rag 107
				new UsernamePasswordCredentials("m2z93iskuj81qiid","0c7ab6a5-98c0-4cdc-8be3-72c591e0add4")); //Prod Server Access Keys
9975 vikram.rag 108
		HttpPost httppost = new HttpPost("https://api.flipkart.net/sellers/skus/listings/bulk");
9947 vikram.rag 109
		StringBuffer jsonRequest = new StringBuffer();
110
		jsonRequest.append("{\"listings\":[");
111
		//System.out.println("JSON request  " + jsonRequest);
112
		LogisticsClient logisticsServiceClient;
113
		in.shop2020.logistics.LogisticsService.Client logisticsClient=null;
114
		LogisticsInfo logisticinfo = null;
115
		try {
116
			logisticsServiceClient = new LogisticsClient("logistics_service_prod_server_host","logistics_service_prod_server_port");
117
			logisticsClient = logisticsServiceClient.getClient();
118
 
119
		} catch (TTransportException e) {
120
			// TODO Auto-generated catch block
121
			e.printStackTrace();
122
		}
123
		long stock=0;
124
		int i=0;
125
		long available,reserve,heldforsource,totalheld,allocable,holdinventory,defaultinventory;
126
		for(Entry<Long, FlipkartInventoryItem> entry:flipkartItemsInventoryMap.entrySet()){
127
			available = entry.getValue().getAvailability();
128
			reserve = entry.getValue().getReserve();
129
			heldforsource = entry.getValue().getHeldForSource();
130
			totalheld = entry.getValue().getTotalHeldInventory();
131
			holdinventory = entry.getValue().getHoldInventory();
132
			defaultinventory = entry.getValue().getDefaultInventory();
133
			if(!entry.getValue().getStatus().equals(status.PAUSED)){
134
				if(entry.getValue().getRisky()){
135
					if((available - reserve) < totalheld && totalheld!=0){
136
						stock = (long) Math.floor(((available - reserve)*heldforsource/totalheld));
137
					}
138
					else{
139
						allocable = available - reserve - totalheld - holdinventory;
140
						if(allocable < 0){
141
							allocable = 0;
142
						}
143
						stock = Math.round(allocable*1/3) + heldforsource;
144
					}
145
 
146
				}
147
				else{
148
					allocable = available - reserve - totalheld;
149
					if(allocable < 0){
150
						allocable = 0;
151
					}
152
					if((allocable + heldforsource ) > defaultinventory){
153
						stock = Math.round(allocable*1/3) +  heldforsource;
154
					}
155
					else{
156
						stock = defaultinventory;
157
					}
158
				}
159
				System.out.println("Item ID " + entry.getKey()+" Stock "+stock +" Orders " + itemIdOrdersMap.get(entry.getKey()));
9971 vikram.rag 160
				if(itemIdOrdersMap!=null && itemIdOrdersMap.containsKey(entry.getKey())){
9947 vikram.rag 161
					stock = stock - itemIdOrdersMap.get(entry.getKey());  
162
				}
163
				if(stock<0){
164
					stock =0;
165
				}
166
			}
167
			else{
168
				stock =0;
169
			}
170
			try {
171
				System.out.println("Item Id " + entry.getValue().getId());
172
				logisticinfo = logisticsClient.getLogisticsEstimation(entry.getValue().getId(),"110001",DeliveryType.COD);
173
			} catch (LogisticsServiceException e) {
174
				e.printStackTrace();
175
				continue;
176
			}
177
			jsonRequest.append("{\"skuId\":"+"\""+entry.getValue().getSkuAtflipkart()+
178
					"\","+"\"attributeValues\""+":"+
179
					"{\"procurement_sla\""+":"+"\""+logisticinfo.getShippingTime()+
180
					"\","+"\"stock_count\""+":"+"\""+stock+"\""+"}}");
181
			if(flipkartItemsInventoryMap.entrySet().size()!=1 && (i!=flipkartItemsInventoryMap.entrySet().size() -1 ) ){
182
				jsonRequest.append(",");	
183
			}
184
			i++;
185
			if(i%10==0 || i==flipkartItemsInventoryMap.entrySet().size()){
186
				jsonRequest.append("]}");
9968 vikram.rag 187
				StringEntity input = null;
188
				try {
189
					input = new StringEntity(jsonRequest.toString());
190
				} catch (UnsupportedEncodingException e) {
191
					// TODO Auto-generated catch block
192
					e.printStackTrace();
193
				}
9947 vikram.rag 194
				input.setContentType("application/json");
195
				System.out.println("Json input " + jsonRequest.toString());
196
				httppost.setEntity(input);
9968 vikram.rag 197
				HttpResponse response = null;
198
				try {
9970 vikram.rag 199
					System.out.println("Before send " );
9968 vikram.rag 200
					response = httpclient.execute(httppost);
9970 vikram.rag 201
					System.out.println("After send " );
9968 vikram.rag 202
				} catch (IOException e) {
203
					// TODO Auto-generated catch block
204
					e.printStackTrace();
205
				}
9969 vikram.rag 206
				BufferedReader rd = null;
9968 vikram.rag 207
				try {
208
					rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
209
				} catch (IllegalStateException e) {
210
					// TODO Auto-generated catch block
211
					e.printStackTrace();
212
				} catch (IOException e) {
213
					// TODO Auto-generated catch block
214
					e.printStackTrace();
215
				}
9947 vikram.rag 216
				String line;
9969 vikram.rag 217
				try {
218
					while ((line = rd.readLine()) != null) {
219
						System.out.println("Response " + line);
220
					}
221
				} catch (IOException e) {
222
					// TODO Auto-generated catch block
223
					e.printStackTrace();
9947 vikram.rag 224
				}
225
			}
226
		}
227
	}
228
	private static void calculateinventory(){
229
		CatalogClient catalogServiceClient = null;
230
		Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
231
		try {
232
			catalogServiceClient = new CatalogClient();
233
		} catch (TTransportException e) {
234
			// TODO Auto-generated catch block
235
			e.printStackTrace();
236
		}
237
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
238
		try {
239
			List<Item> aliveItems = catalogClient.getAllAliveItems();
240
			Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>(); 
241
			for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
242
				aliveItemsMap.put(thriftItem.getId(), thriftItem);
243
 
244
			}
245
			InventoryClient inventoryServiceClient = new InventoryClient();
246
			try {
247
				inventoryServiceClient = new InventoryClient();
248
			} catch (TTransportException e) {
249
				e.printStackTrace();
250
			}
251
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
252
			List<in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems> ignoreItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
253
			availability = inventoryClient.getInventorySnapshot(0);
254
			List<Warehouse> allwarehouses = inventoryClient.getWarehouses(null,null,0,0,0);
255
			Map<Long,Warehouse> allWarehousesMap = new HashMap<Long,Warehouse>();
256
			for(Warehouse warehouse:allwarehouses){
257
				allWarehousesMap.put(warehouse.getId(),warehouse);
258
			}
259
			List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS_THIRDPARTY,null,0,0,0);
260
			List<Warehouse> ours_warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 0, 0, 0);
261
			List<Long> thirdpartywarehouseids = new ArrayList<Long>();
262
			List<Long> oursGoodWarehouse = new ArrayList<Long>();
263
			for(Warehouse warehouse:warehouses){
264
				thirdpartywarehouseids.add(warehouse.getId());
265
			}
266
			for (Warehouse warehouse:ours_warehouses){
267
				oursGoodWarehouse.add(warehouse.getId());
268
			}
269
			long available=0;
270
			long reserve=0;
271
			long total_warehouse_held=0;
272
			long heldForSource=0;
273
			long total_held=0;
274
			double nlc=0;
275
			double maxnlc=0;
276
			Item thriftItem;
277
			for(FlipkartItem flipkartItem:flipkartInventoryItems){
278
				if(aliveItemsMap.get(flipkartItem.getItem_id()) != null){
279
					thriftItem = aliveItemsMap.get(flipkartItem.getItem_id());	
280
				}
281
				else{
282
					continue;
283
				}
284
				available=0;
285
				reserve=0;
286
				total_warehouse_held=0;
287
				heldForSource=0;
288
				total_held=0;
289
				nlc=0;
290
				List<Warehouse> vendor_warehouses=null;
291
				FlipkartInventoryItem item;
292
				if(availability.get(thriftItem.getId())!=null){ 
293
					ItemInventory iteminventory = availability.get(thriftItem.getId());
294
					Map<Long,Long> itemavailability = new HashMap<Long,Long>();
295
					itemavailability = iteminventory.getAvailability();
296
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
297
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating availability)"+thriftItem.getPreferredVendor());						
298
						vendor_warehouses = inventoryClient.getWarehouses(WarehouseType.THIRD_PARTY,InventoryType.GOOD , thriftItem.getPreferredVendor(), 0, 0);
299
						vendor_warehouses.addAll(ours_warehouses);
300
						for (Warehouse warehouse:vendor_warehouses){
301
							if(warehouse.getBillingWarehouseId()!=7){
302
								if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
303
 
304
								}
305
								else{
306
									continue;
307
								}
308
							}
309
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
310
							ignoredItem.setItemId(thriftItem.getId());
311
							ignoredItem.setWarehouseId(warehouse.getId());
312
							if (itemavailability.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(ignoredItem)){
313
								try{
314
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
315
								}
316
								catch(TTransportException e){
317
									inventoryClient = inventoryServiceClient.getClient(); 
318
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
319
								}
320
								maxnlc = flipkartItem.getMaxNlc();
321
 
322
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
323
								if(nlc !=0 && (maxnlc >= nlc)){
324
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
325
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
326
									available = available + itemavailability.get(warehouse.getId());
327
									total_held = total_held + total_warehouse_held; 
328
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
329
								}
330
								else if(maxnlc==0){
331
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
332
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
333
									available = available + itemavailability.get(warehouse.getId());
334
									total_held = total_held + total_warehouse_held;
335
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
336
								}
337
							}
338
						}
339
					}
340
					else{
341
						for (Map.Entry<Long,Long> entry :  itemavailability.entrySet()) {
342
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
343
								if(allWarehousesMap.get(entry.getKey()).getLogisticsLocation().equals(WarehouseLocation.Delhi) && allWarehousesMap.get(entry.getKey()).getWarehouseType().equals(WarehouseType.THIRD_PARTY) && allWarehousesMap.get(entry.getKey()).getVendor().getId()!=1){
344
 
345
								}
346
								else{
347
									continue;
348
								}
349
							}
350
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
351
							ignoredItem.setItemId(thriftItem.getId());
352
							ignoredItem.setWarehouseId(entry.getKey());
353
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
354
 
355
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
356
								maxnlc = flipkartItem.getMaxNlc();
357
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
358
								if(nlc !=0 && (maxnlc >= nlc)){
359
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
360
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
361
									available =  available + entry.getValue();
362
									total_held = total_held + total_warehouse_held;
363
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
364
								}
365
								else if(maxnlc==0){
366
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
367
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
368
									available = available + itemavailability.get(entry.getKey());
369
									total_held = total_held + total_warehouse_held;
370
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
371
								}
372
 
373
							}
374
						}
375
					}
376
					Map<Long,Long> itemreserve = new HashMap<Long,Long>();
377
					itemreserve = iteminventory.getReserved();
378
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
379
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating Reserve)"+thriftItem.getPreferredVendor());
380
						for (Warehouse warehouse:vendor_warehouses){
381
							if(warehouse.getBillingWarehouseId()!=7){
382
								if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
383
 
384
								}
385
								else{
386
									continue;
387
								}
388
							}
389
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
390
							ignoredItem.setItemId(thriftItem.getId());
391
							ignoredItem.setWarehouseId(warehouse.getId());
392
							if (itemreserve.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(warehouse.getId())){
393
								nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
394
								maxnlc = flipkartItem.getMaxNlc();
395
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
396
								if(nlc !=0 && (maxnlc >= nlc)){
397
									reserve = reserve + itemreserve.get(warehouse.getId());
398
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
399
								}
400
								else if(maxnlc==0){
401
									reserve = reserve + itemreserve.get(warehouse.getId());
402
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
403
								}
404
 
405
							}
406
						}
407
					}else{
408
						for (Map.Entry<Long,Long> entry : itemreserve.entrySet()) {
409
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
410
								if(allWarehousesMap.get(entry.getKey()).getLogisticsLocation().equals(WarehouseLocation.Delhi) && allWarehousesMap.get(entry.getKey()).getWarehouseType().equals(WarehouseType.THIRD_PARTY) && allWarehousesMap.get(entry.getKey()).getVendor().getId()!=1){
411
 
412
								}
413
								else{
414
									continue;
415
								}
416
							}
417
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
418
							ignoredItem.setItemId(thriftItem.getId());
419
							ignoredItem.setWarehouseId(entry.getKey());
420
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
421
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
422
								maxnlc = flipkartItem.getMaxNlc();
423
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
424
								if(nlc !=0 && (maxnlc >= nlc)){
425
									reserve =  reserve + entry.getValue();
426
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
427
								}
428
								else if(maxnlc==0){
429
									reserve =  reserve + entry.getValue();
430
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
431
								}
432
 
433
							}
434
 
435
							else{
436
								//System.out.println("skipping inventory for warehouse id " + entry.getKey());
437
							}
438
						}
439
					}
440
					item= new FlipkartInventoryItem(thriftItem.getId(),available,reserve,heldForSource,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),total_held,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
441
					//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
442
				}
443
				else{
444
					item = new FlipkartInventoryItem(thriftItem.getId(),0,0,0,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),0,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
445
					//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
446
				}
447
 
448
				//System.out.println(" Item details are " + thriftItem.getId() +" " + available + " " + reserve + " " + thriftItem.getHoldInventory() + " "+ thriftItem.getDefaultInventory() + " " + thriftItem.isRisky());
449
				//System.out.println("+++++++++++++++++++++++");
450
				flipkartItemsInventoryMap.put(thriftItem.getId(),item);
451
 
452
			}
453
 
454
		} catch (TException e) {
455
			// TODO Auto-generated catch block
456
			e.printStackTrace();
457
		}
458
	}
459
 
460
	static List<String> FetchOrders() throws ClientProtocolException, IOException{
461
		HttpClient client = new DefaultHttpClient();
462
		HttpPost post = new HttpPost("https://seller.flipkart.com/login");
463
		BufferedReader rd= null;
464
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
465
		nameValuePairs.add(new BasicNameValuePair("authName",
466
		"flipkart"));
467
		nameValuePairs.add(new BasicNameValuePair("username",
468
		"flipkart-support@saholic.com"));
469
		nameValuePairs.add(new BasicNameValuePair("password",
470
		"076c27ee24d7596b06608a8ed2559f87"));
471
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
472
		HttpResponse response = client.execute(post);
473
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
474
		String line = "";
475
		Gson gson;
476
		List<Order> orders = new ArrayList<Order>(); 
477
		OrderItems new_orders;
478
		OrderItems conf_orders;
479
		HttpGet get_new;
480
		HttpGet get_conf; 
481
		long time;
482
		int i=1;
483
		while ((line = rd.readLine()) != null) {
484
			System.out.println(line);
485
		}
486
		time = System.currentTimeMillis();
487
		while(true){
488
			get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/new_order_items?status=on_hold%2Capproved.payment_approved&sort=confirm_by_date&page="+i+"&page_size=100&_="+time);
489
			response = client.execute(get_new);
490
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
491
			line = "";
492
			gson = new Gson();
493
			new_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
494
			if(new_orders.getOrder_items().size()>0){
495
				orders.addAll(new_orders.getOrder_items());
496
			}
497
			else{
498
				break;
499
			}
500
			i++;
501
		}
502
		i=1;
503
		time = System.currentTimeMillis();
504
		while(true){
505
			get_conf = new HttpGet("https://seller.flipkart.com/dashboard/som/confirmed_order_items?status=approved.seller_approved&sort=confirm_by_date&page="+i+"&page_size=100&_="+time);
506
			response = client.execute(get_conf);
507
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
508
			line = "";
509
			gson = new Gson();
510
			conf_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
511
			if(conf_orders.getOrder_items().size()>0){
512
				orders.addAll(conf_orders.getOrder_items());
513
			}
514
			else{
515
				break;
516
			}
517
			i++;
518
		}
519
		List<String> orderIdList = new ArrayList<String>();
520
		for(Order order:orders){
521
			System.out.println("Order  " + order.getExternalId() +" "+order.getOrderItemId() + " : "+ order.getStatus() + " "+order.getStatusDateMessage() + " "
522
					+ order.getStatusLabel() + " " + order.getPickup_by_date() + " "+ order.getTrackingId());
523
			orderIdList.add(order.getExternalId());
524
		}
525
		return orderIdList; 
526
	}
527
}