Subversion Repositories SmartDukaan

Rev

Rev 11901 | Rev 12761 | 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;
10174 vikram.rag 9
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
9947 vikram.rag 10
import in.shop2020.model.v1.catalog.status;
10049 vikram.rag 11
import in.shop2020.model.v1.inventory.FlipkartInventorySnapshot;
9947 vikram.rag 12
import in.shop2020.model.v1.inventory.InventoryType;
13
import in.shop2020.model.v1.inventory.ItemInventory;
14
import in.shop2020.model.v1.inventory.Warehouse;
15
import in.shop2020.model.v1.inventory.WarehouseLocation;
16
import in.shop2020.model.v1.inventory.WarehouseType;
17
import in.shop2020.model.v1.order.OrderSource;
18
import in.shop2020.serving.model.Order;
19
import in.shop2020.serving.model.OrderItems;
20
import in.shop2020.thrift.clients.CatalogClient;
21
import in.shop2020.thrift.clients.InventoryClient;
22
import in.shop2020.thrift.clients.LogisticsClient;
23
import in.shop2020.thrift.clients.TransactionClient;
9983 vikram.rag 24
import in.shop2020.utils.GmailUtils;
9947 vikram.rag 25
import inventory.FlipkartInventoryItem;
26
 
27
import java.io.BufferedReader;
9983 vikram.rag 28
import java.io.File;
9947 vikram.rag 29
import java.io.IOException;
30
import java.io.InputStreamReader;
9968 vikram.rag 31
import java.io.UnsupportedEncodingException;
11442 vikram.rag 32
import java.nio.charset.Charset;
9947 vikram.rag 33
import java.util.ArrayList;
34
import java.util.HashMap;
35
import java.util.List;
36
import java.util.Map;
37
import java.util.Map.Entry;
38
 
9983 vikram.rag 39
import javax.mail.MessagingException;
40
 
11443 vikram.rag 41
import org.apache.commons.codec.binary.Base64;
11442 vikram.rag 42
import org.apache.http.HttpHeaders;
9947 vikram.rag 43
import org.apache.http.HttpResponse;
44
import org.apache.http.NameValuePair;
45
import org.apache.http.auth.AuthScope;
46
import org.apache.http.auth.UsernamePasswordCredentials;
47
import org.apache.http.client.ClientProtocolException;
48
import org.apache.http.client.HttpClient;
49
import org.apache.http.client.entity.UrlEncodedFormEntity;
50
import org.apache.http.client.methods.HttpGet;
51
import org.apache.http.client.methods.HttpPost;
52
import org.apache.http.entity.StringEntity;
53
import org.apache.http.impl.client.DefaultHttpClient;
54
import org.apache.http.message.BasicNameValuePair;
55
import org.apache.thrift.TException;
56
import org.apache.thrift.transport.TTransportException;
57
import com.google.gson.Gson;
58
 
59
 
60
 
61
public class CreateSubmitFlipkartInventoryFeed {
62
	private static Map<Long, FlipkartInventoryItem> flipkartItemsInventoryMap = new HashMap<Long, FlipkartInventoryItem>();
63
	private static List<FlipkartItem> flipkartItems;
64
	private static List<FlipkartItem> flipkartInventoryItems = new ArrayList<FlipkartItem>();
65
	private static Map<Long,Long> itemIdOrdersMap = new HashMap<Long,Long>();
9983 vikram.rag 66
	private static Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
10057 vikram.rag 67
	private static Map<String,Long> heldOrdersMap = new HashMap<String,Long>();
10122 vikram.rag 68
	private static Map<Long,Long>  updatedFlipkartInventoryMap = new HashMap<Long,Long>();
9983 vikram.rag 69
	static java.text.SimpleDateFormat sdf;
70
	static String emailFromAddress;
71
	static String password;
72
	static GmailUtils mailer;
73
	static String sendTo[];
10174 vikram.rag 74
	private static List<SnapdealItemDetails> snapdealItems = new ArrayList<SnapdealItemDetails>();
75
	private static Map<Long,SnapdealItemDetails> snapdealItemsMap = new HashMap<Long,SnapdealItemDetails>();
9947 vikram.rag 76
	static
77
	{
9983 vikram.rag 78
		sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
79
		emailFromAddress = "build@shop2020.in";
80
		password = "cafe@nes";
81
		mailer = new GmailUtils();
11448 vikram.rag 82
		//sendTo = new String[]{"vikram.raghav@shop2020.in"};
83
		sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
9983 vikram.rag 84
				"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
12595 manish.sha 85
				"yukti.jain@shop2020.in","manoj.pal@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","manish.sharma@shop2020.in","anikendra.das@shop2020.in"};
11448 vikram.rag 86
		List<String> flipkartorderids = null;
87
		Client catalogServiceClient = null;
88
		try {
89
			catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
90
		} catch (TTransportException e) {
91
			e.printStackTrace();
92
		}
93
		try {
94
			flipkartItems = catalogServiceClient.getAllFlipkartItems();
95
			snapdealItems = catalogServiceClient.getAllSnapdealItems();
96
		} catch (TException e) {
97
			e.printStackTrace();
98
		}
99
		for(FlipkartItem flipkartItem:flipkartItems){
100
			if(flipkartItem.isIsListedOnFlipkart() && !flipkartItem.isSuppressInventoryFeed())
101
				flipkartInventoryItems.add(flipkartItem);
102
		}
103
		for(SnapdealItemDetails snapdealItem:snapdealItems){
104
			snapdealItemsMap.put(snapdealItem.getItem_id(),snapdealItem);
105
		}
106
		if(flipkartInventoryItems.size()==0){
107
			String text = "";
108
			try {
109
				mailer.sendSSLMessage(sendTo,"No items to send inventory ", emailFromAddress, password, text);
110
				System.exit(0);
111
			} catch (MessagingException e) {
112
				e.printStackTrace();
113
			}
114
		}
115
		in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
116
		try {
117
			flipkartorderids = FetchOrders();
118
		} catch (ClientProtocolException e1) {
119
			e1.printStackTrace();
120
		} catch (IOException e1) {
121
			e1.printStackTrace();
122
		}
123
		try {
124
			transactionClient = new TransactionClient().getClient();
125
			if(flipkartorderids!=null && flipkartorderids.size()>0){
126
				itemIdOrdersMap = transactionClient.getCreatedOrdersForFlipkart(flipkartorderids);
127
			}
128
		} catch (TTransportException e) {
129
			try {
130
				itemIdOrdersMap = transactionClient.getCreatedOrdersForFlipkart(flipkartorderids);
131
			} catch (TException e1) {
132
				e1.printStackTrace();
133
			}
134
		}catch (TException e) {
135
			e.printStackTrace();
136
		}
137
		try {
138
			List<FlipkartInventorySnapshot> updatedFlipkartInventoryList = new InventoryClient().getClient().getFlipkartInventorySnapshot();
139
			for(FlipkartInventorySnapshot updatedFlipkartInventory:updatedFlipkartInventoryList){
140
				updatedFlipkartInventoryMap.put(updatedFlipkartInventory.getItem_id(),updatedFlipkartInventory.getAvailability());
141
			}
142
		} catch (TException e) {
143
			e.printStackTrace();
144
		}
145
		catch(Exception e){
146
			List<FlipkartInventorySnapshot> updatedFlipkartInventoryList = null;
147
			try {
148
				updatedFlipkartInventoryList = new InventoryClient().getClient().getFlipkartInventorySnapshot();
149
			} catch (TTransportException e1) {
150
				e1.printStackTrace();
151
			} catch (TException e1) {
152
				e1.printStackTrace();
153
			}
154
			if(updatedFlipkartInventoryList != null){
155
				for(FlipkartInventorySnapshot updatedFlipkartInventory:updatedFlipkartInventoryList){
156
					updatedFlipkartInventoryMap.put(updatedFlipkartInventory.getItem_id(),updatedFlipkartInventory.getAvailability());
157
				}
158
			}
159
		}
9947 vikram.rag 160
 
10122 vikram.rag 161
 
9947 vikram.rag 162
	}
163
 
9967 vikram.rag 164
	public static void main(String[] args) throws ClientProtocolException, TException{
9947 vikram.rag 165
		calculateinventory();
166
		DefaultHttpClient httpclient = new DefaultHttpClient();
11440 vikram.rag 167
		//httpclient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpclient);
10051 vikram.rag 168
		//httpclient.getCredentialsProvider().setCredentials(
169
		//		new AuthScope("sandbox-api.flipkart.net", 443),
170
		//		new UsernamePasswordCredentials("og3yg5994bxbxxc1", "8a137068-417c-4e4f-ae95-9295ab938d88"));/// Test Server Access Keys
11440 vikram.rag 171
		//httpclient.getCredentialsProvider().setCredentials(
172
		//		new AuthScope("api.flipkart.net", 443),
173
		//		new UsernamePasswordCredentials("m2z93iskuj81qiid","0c7ab6a5-98c0-4cdc-8be3-72c591e0add4")); //Prod Server Access Keys
11448 vikram.rag 174
 
10051 vikram.rag 175
		HttpPost httppost = new HttpPost("https://api.flipkart.net/sellers/skus/listings/bulk"); // PROD
11448 vikram.rag 176
 
11442 vikram.rag 177
		String auth = "m2z93iskuj81qiid"+":"+"0c7ab6a5-98c0-4cdc-8be3-72c591e0add4";
178
		byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
179
		String authHeader = "Basic " + new String(encodedAuth);
180
		httppost.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
10051 vikram.rag 181
		//HttpPost httppost = new HttpPost("https://sandbox-api.flipkart.net/sellers/skus/listings/bulk"); // TEST
9947 vikram.rag 182
		StringBuffer jsonRequest = new StringBuffer();
9983 vikram.rag 183
		StringBuffer jsonStart = new StringBuffer();
184
		jsonStart = jsonStart.append("{\"listings\":[");
185
		StringBuffer jsonEnd = new StringBuffer();
186
		jsonEnd.append("]}");
9947 vikram.rag 187
		//System.out.println("JSON request  " + jsonRequest);
188
		LogisticsClient logisticsServiceClient;
189
		in.shop2020.logistics.LogisticsService.Client logisticsClient=null;
190
		LogisticsInfo logisticinfo = null;
191
		try {
10154 vikram.rag 192
			logisticsServiceClient = new LogisticsClient();
9947 vikram.rag 193
			logisticsClient = logisticsServiceClient.getClient();
194
 
195
		} catch (TTransportException e) {
196
			e.printStackTrace();
197
		}
198
		long stock=0;
199
		int i=0;
10176 vikram.rag 200
		long available,reserve,heldforsource,totalheld,allocable,holdinventory,defaultinventory,actualstock = 0,orders,heldorders;
201
		float allocation;
9983 vikram.rag 202
		StringBuffer inventoryItems =new StringBuffer();
10122 vikram.rag 203
		StringBuffer backInStockItems =new StringBuffer();
204
		StringBuffer outOfStockItems =new StringBuffer();
9983 vikram.rag 205
		String tableHeader = "<html><table border=\"1\" align=\"center\"><tr>" 
206
			+ "<td><b>" + "Product Name" +"</b></td>"
11901 vikram.rag 207
			+ "<td><b>" + "SKU at Flipkart"+"</b></td>"
9983 vikram.rag 208
			+"<td><b>" + "Item ID" + "</b></td>"
209
			+"<td><b>" + "Inventory" + "</b></td>"
210
			+"<td><b>" + "Orders Added to Inventory" + "</b></td>"
211
			+"<td><b>" + "Sent Inventory" + "</b></td>"
10049 vikram.rag 212
			+"<td><b>" + "Procurement SLA" + "</b></td>"
213
			+"<td><b>" + "Orders on Hold" + "</b></td>"
9983 vikram.rag 214
			+"</tr>";
10159 vikram.rag 215
 
9983 vikram.rag 216
		String tableFooter = "</table></html>";
217
		Item item;
10027 vikram.rag 218
		StringBuffer feedResponse=  new StringBuffer();
10049 vikram.rag 219
		List<FlipkartInventorySnapshot> inventorysnapshotlist = new ArrayList<FlipkartInventorySnapshot>();
10450 vikram.rag 220
		long timestamp = System.currentTimeMillis();
9947 vikram.rag 221
		for(Entry<Long, FlipkartInventoryItem> entry:flipkartItemsInventoryMap.entrySet()){
10174 vikram.rag 222
			if(snapdealItemsMap.containsKey(entry.getKey()) && snapdealItemsMap.get(entry.getKey()).isIsListedOnSnapdeal()){
10306 vikram.rag 223
				allocation = (float) 0.33;
10174 vikram.rag 224
			}
225
			else{
10306 vikram.rag 226
				allocation = (float) 0.67;
10174 vikram.rag 227
			}
9985 vikram.rag 228
			actualstock=0;
229
			orders=0;
230
			stock=0;
10049 vikram.rag 231
			heldorders=0;
9947 vikram.rag 232
			available = entry.getValue().getAvailability();
233
			reserve = entry.getValue().getReserve();
234
			heldforsource = entry.getValue().getHeldForSource();
235
			totalheld = entry.getValue().getTotalHeldInventory();
236
			holdinventory = entry.getValue().getHoldInventory();
237
			defaultinventory = entry.getValue().getDefaultInventory();
9987 vikram.rag 238
			System.out.println("Item ID  " + entry.getKey());
239
			System.out.println("Available " + available);
240
			System.out.println("Reserve " + reserve);
241
			System.out.println("Held For Source " + heldforsource);
242
			System.out.println("Total Held " + totalheld);
243
			System.out.println("General Hold " + holdinventory );
244
			System.out.println("Default Inventory " + defaultinventory);
9947 vikram.rag 245
			if(!entry.getValue().getStatus().equals(status.PAUSED)){
246
				if(entry.getValue().getRisky()){
247
					if((available - reserve) < totalheld && totalheld!=0){
248
						stock = (long) Math.floor(((available - reserve)*heldforsource/totalheld));
249
					}
250
					else{
251
						allocable = available - reserve - totalheld - holdinventory;
252
						if(allocable < 0){
253
							allocable = 0;
254
						}
10174 vikram.rag 255
						stock = Math.round(allocable*allocation) + heldforsource;
9947 vikram.rag 256
					}
257
 
258
				}
259
				else{
260
					allocable = available - reserve - totalheld;
261
					if(allocable < 0){
262
						allocable = 0;
263
					}
264
					if((allocable + heldforsource ) > defaultinventory){
10174 vikram.rag 265
						stock = Math.round(allocable*allocation) +  heldforsource;
9947 vikram.rag 266
					}
267
					else{
268
						stock = defaultinventory;
269
					}
270
				}
271
				System.out.println("Item ID " + entry.getKey()+" Stock "+stock +" Orders " + itemIdOrdersMap.get(entry.getKey()));
9992 vikram.rag 272
				actualstock = stock;
12595 manish.sha 273
				if(stock >3){
274
					if(itemIdOrdersMap!=null && itemIdOrdersMap.containsKey(entry.getKey())){
275
						stock = stock + itemIdOrdersMap.get(entry.getKey());  
276
						orders = itemIdOrdersMap.get(entry.getKey());
277
					}
9947 vikram.rag 278
				}
279
				if(stock<0){
280
					stock =0;
281
				}
9977 vikram.rag 282
				else{
283
					if(stock > 25){
284
						stock=25;
285
					}
286
				}
9947 vikram.rag 287
			}
288
			else{
289
				stock =0;
290
			}
291
			try {
292
				logisticinfo = logisticsClient.getLogisticsEstimation(entry.getValue().getId(),"110001",DeliveryType.COD);
293
			} catch (LogisticsServiceException e) {
294
				e.printStackTrace();
295
				continue;
296
			}
10029 vikram.rag 297
			catch (TTransportException e) {
10154 vikram.rag 298
				logisticsServiceClient = new LogisticsClient();
10029 vikram.rag 299
				logisticsClient = logisticsServiceClient.getClient();
300
			} 
10107 vikram.rag 301
			System.out.println("sku at flipkart " + entry.getValue().getSkuAtflipkart());
302
			System.out.println("shipping time " + logisticinfo.getShippingTime());
303
			System.out.println("stock " + stock);
11649 vikram.rag 304
			if(logisticinfo.getShippingTime() > 5 && stock > 0){
305
				jsonRequest.append("{\"skuId\":"+"\""+entry.getValue().getSkuAtflipkart()+
306
						"\","+"\"attributeValues\""+":"+
11650 vikram.rag 307
						"{\"procurement_sla\""+":"+"\""+"5"+
11649 vikram.rag 308
						"\","+"\"stock_count\""+":"+"\""+"0"+"\""+"}}");
309
			}
310
			else{
311
				jsonRequest.append("{\"skuId\":"+"\""+entry.getValue().getSkuAtflipkart()+
312
						"\","+"\"attributeValues\""+":"+
313
						"{\"procurement_sla\""+":"+"\""+logisticinfo.getShippingTime()+
314
						"\","+"\"stock_count\""+":"+"\""+stock+"\""+"}}");
315
			}
10049 vikram.rag 316
			FlipkartInventorySnapshot inventorySnapshot = new FlipkartInventorySnapshot();
317
			inventorySnapshot.setItem_id(entry.getKey());
318
			inventorySnapshot.setAvailability(stock);
10450 vikram.rag 319
			if(stock > 0){
320
				inventorySnapshot.setIs_oos(false);
321
			}
322
			else{
323
				inventorySnapshot.setIs_oos(true);
324
			}
10049 vikram.rag 325
			if(heldOrdersMap.containsKey(entry.getValue().getSkuAtflipkart())){
326
				inventorySnapshot.setHeldOrders(heldOrdersMap.get(entry.getValue().getSkuAtflipkart()));
10060 vikram.rag 327
				heldorders = heldOrdersMap.get(entry.getValue().getSkuAtflipkart());
10049 vikram.rag 328
			}
329
			else{
330
				inventorySnapshot.setHeldOrders(0);
331
			}
332
			inventorySnapshot.setCreatedOrders(orders);
333
			inventorysnapshotlist.add(inventorySnapshot);
9983 vikram.rag 334
			item = aliveItemsMap.get(entry.getValue().getId());
11004 vikram.rag 335
			System.out.println("++++++++++++++++++Before checking > 5 SLA+++++++++++++++++++++++++++++");
11000 vikram.rag 336
			if(logisticinfo.getShippingTime() > 5 && stock > 0){
11005 vikram.rag 337
				System.out.println("Product : "+getProductName(item)+" Item ID : " + item.getId() + " Stock : " +  stock +" "+ "  SLA : " + logisticinfo.getShippingTime());
338
				stock = 0;
11000 vikram.rag 339
			}
11004 vikram.rag 340
			System.out.println("++++++++++++++++++++After checking > 5 SLA++++++++++++++++++++++++");
11448 vikram.rag 341
 
10160 vikram.rag 342
			if(!updatedFlipkartInventoryMap.containsKey(entry.getKey())){
10122 vikram.rag 343
				inventoryItems.append("<tr>" 
344
						+ "<td>" +getProductName(item)+"</td>"
11901 vikram.rag 345
						+ "<td>" + entry.getValue().getSkuAtflipkart()+"</td>"
10122 vikram.rag 346
						+"<td>" + item.getId() + "</td>"
347
						+"<td>" + actualstock + "</td>"
348
						+"<td>" + orders + "</td>"
349
						+"<td>" + stock + "</td>"
350
						+"<td>" + logisticinfo.getShippingTime() + "</td>"
351
						+"<td>" + heldorders + "</td>"
352
						+"</tr>");
353
			}
11901 vikram.rag 354
			else if(updatedFlipkartInventoryMap.containsKey(entry.getKey())){
355
			//else if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) != stock){
10160 vikram.rag 356
				inventoryItems.append("<tr>" 
357
						+ "<td>" +getProductName(item)+"</td>"
11901 vikram.rag 358
						+ "<td>" + entry.getValue().getSkuAtflipkart()+"</td>"
10160 vikram.rag 359
						+"<td>" + item.getId() + "</td>"
360
						+"<td>" + actualstock + "</td>"
361
						+"<td>" + orders + "</td>"
362
						+"<td>" + stock + "</td>"
363
						+"<td>" + logisticinfo.getShippingTime() + "</td>"
364
						+"<td>" + heldorders + "</td>"
365
						+"</tr>");
366
			}
10122 vikram.rag 367
			if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) == 0 && stock!=0){
368
				backInStockItems.append("<tr>" 
369
						+ "<td>" +getProductName(item)+"</td>"
11901 vikram.rag 370
						+ "<td>" + entry.getValue().getSkuAtflipkart()+"</td>"
10122 vikram.rag 371
						+"<td>" + item.getId() + "</td>"
372
						+"<td>" + actualstock + "</td>"
373
						+"<td>" + orders + "</td>"
374
						+"<td>" + stock + "</td>"
375
						+"<td>" + logisticinfo.getShippingTime() + "</td>"
376
						+"<td>" + heldorders + "</td>"
377
						+"</tr>");
378
			}
379
			if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) != 0 && stock==0){
380
				outOfStockItems.append("<tr>" 
381
						+ "<td>" +getProductName(item)+"</td>"
11901 vikram.rag 382
						+ "<td>" + entry.getValue().getSkuAtflipkart()+"</td>"
10122 vikram.rag 383
						+"<td>" + item.getId() + "</td>"
384
						+"<td>" + actualstock + "</td>"
385
						+"<td>" + orders + "</td>"
386
						+"<td>" + stock + "</td>"
387
						+"<td>" + logisticinfo.getShippingTime() + "</td>"
388
						+"<td>" + heldorders + "</td>"
389
						+"</tr>");
390
			}
10028 vikram.rag 391
			i++;
392
			if(flipkartItemsInventoryMap.entrySet().size()!=1 && (i!=flipkartItemsInventoryMap.entrySet().size()) ){
11862 vikram.rag 393
				if(i%10!=0){
10026 vikram.rag 394
					jsonRequest.append(",");
395
				}
9947 vikram.rag 396
			}
11862 vikram.rag 397
			if(i%10==0 || i==flipkartItemsInventoryMap.entrySet().size()){
9968 vikram.rag 398
				StringEntity input = null;
399
				try {
9983 vikram.rag 400
					input = new StringEntity(jsonStart+jsonRequest.toString()+jsonEnd);
401
					System.out.println("Json input " + jsonStart+jsonRequest.toString()+jsonEnd);
402
					jsonRequest = new StringBuffer();
9968 vikram.rag 403
				} catch (UnsupportedEncodingException e) {
404
					e.printStackTrace();
405
				}
9947 vikram.rag 406
				input.setContentType("application/json");
10049 vikram.rag 407
 
9947 vikram.rag 408
				httppost.setEntity(input);
9968 vikram.rag 409
				HttpResponse response = null;
410
				try {
9970 vikram.rag 411
					System.out.println("Before send " );
9968 vikram.rag 412
					response = httpclient.execute(httppost);
9970 vikram.rag 413
					System.out.println("After send " );
9968 vikram.rag 414
				} catch (IOException e) {
415
					e.printStackTrace();
416
				}
9969 vikram.rag 417
				BufferedReader rd = null;
9968 vikram.rag 418
				try {
419
					rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
11866 vikram.rag 420
					/*if(!rd.readLine().equalsIgnoreCase("{\"status\":\"success\"}")){
11862 vikram.rag 421
						System.out.println("Before send " );
422
						httpclient = new DefaultHttpClient();
423
						response = httpclient.execute(httppost);
424
						rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
11866 vikram.rag 425
					}*/
9968 vikram.rag 426
				} catch (IllegalStateException e) {
427
					e.printStackTrace();
428
				} catch (IOException e) {
429
					e.printStackTrace();
430
				}
9947 vikram.rag 431
				String line;
10049 vikram.rag 432
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryServiceClient;
9969 vikram.rag 433
				try {
434
					while ((line = rd.readLine()) != null) {
435
						System.out.println("Response " + line);
9983 vikram.rag 436
						if(line.equalsIgnoreCase("{\"status\":\"success\"}")){
10154 vikram.rag 437
							inventoryServiceClient = new InventoryClient().getClient();
10158 vikram.rag 438
							try{
10450 vikram.rag 439
								inventoryServiceClient.addOrUpdateFlipkartInventorySnapshot(inventorysnapshotlist,timestamp);
10158 vikram.rag 440
							}
441
							catch(TTransportException e){
442
								inventoryServiceClient = new InventoryClient().getClient();
10450 vikram.rag 443
								inventoryServiceClient.addOrUpdateFlipkartInventorySnapshot(inventorysnapshotlist,timestamp);
10158 vikram.rag 444
							}
10049 vikram.rag 445
							inventorysnapshotlist = new ArrayList<FlipkartInventorySnapshot>();
9983 vikram.rag 446
						}
447
						else{
448
							feedResponse.append(line);
449
						}
10049 vikram.rag 450
 
9969 vikram.rag 451
					}
452
				} catch (IOException e) {
453
					e.printStackTrace();
9947 vikram.rag 454
				}
455
			}
456
		}
9983 vikram.rag 457
		System.out.println("Before sending email");
10179 vikram.rag 458
		if(feedResponse.toString().length()>0){
459
			try {
460
				mailer.sendSSLMessage(sendTo, "Flipkart Inventory could not be updated " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
10181 vikram.rag 461
			} catch (Exception e) {
10183 vikram.rag 462
				emailFromAddress = "build-staging@shop2020.in"; 
463
				password = "shop2020";
10179 vikram.rag 464
				try {
465
					mailer.sendSSLMessage(sendTo, "Flipkart Inventory could not be updated " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
466
				} catch (MessagingException e1) {
467
					e1.printStackTrace();
468
				}
469
				e.printStackTrace();
470
			}
471
		}
472
		else{
473
			try {
474
				mailer.sendSSLMessage(sendTo, "Flipkart Inventory updated successfully " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
475
			} catch (MessagingException e) {
10183 vikram.rag 476
				emailFromAddress = "build-staging@shop2020.in"; 
477
				password = "shop2020";
10179 vikram.rag 478
				try {
479
					mailer.sendSSLMessage(sendTo, "Flipkart Inventory updated successfully " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
480
				} catch (MessagingException e1) {
481
					e1.printStackTrace();
482
				}
483
				e.printStackTrace();
484
			}
485
		}
486
 
487
		String text;
10159 vikram.rag 488
		if(inventoryItems.toString().length()>0){
10179 vikram.rag 489
			text = tableHeader+inventoryItems.toString()+tableFooter;
10159 vikram.rag 490
			try {
491
				mailer.sendSSLMessage(sendTo,"Flipkart Inventory Sent Details " + sdf.format(System.currentTimeMillis()), emailFromAddress, password, text);
492
			} catch (MessagingException e) {
493
				e.printStackTrace();
494
			}
9983 vikram.rag 495
		}
10122 vikram.rag 496
		if(backInStockItems.toString().length()>0){
497
			try {
498
				text = tableHeader+backInStockItems.toString()+tableFooter;
10123 vikram.rag 499
				mailer.sendSSLMessage(sendTo,"Flipkart Inventory Back in Stock " + sdf.format(System.currentTimeMillis()), emailFromAddress, password, text);
10122 vikram.rag 500
			} catch (MessagingException e) {
501
				e.printStackTrace();
502
			}
10159 vikram.rag 503
 
10122 vikram.rag 504
		}
505
		if(outOfStockItems.toString().length()>0){
506
			try {
507
				text = tableHeader+outOfStockItems.toString()+tableFooter;
10123 vikram.rag 508
				mailer.sendSSLMessage(sendTo,"Flipkart Inventory Out of Stock " + sdf.format(System.currentTimeMillis()), emailFromAddress, password, text);
10122 vikram.rag 509
			} catch (MessagingException e) {
510
				e.printStackTrace();
511
			}
10159 vikram.rag 512
 
10122 vikram.rag 513
		}
9947 vikram.rag 514
	}
9983 vikram.rag 515
 
9947 vikram.rag 516
	private static void calculateinventory(){
517
		CatalogClient catalogServiceClient = null;
518
		Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
519
		try {
10154 vikram.rag 520
			catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
9947 vikram.rag 521
		} catch (TTransportException e) {
522
			e.printStackTrace();
523
		}
524
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
525
		try {
526
			List<Item> aliveItems = catalogClient.getAllAliveItems();
527
			for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
528
				aliveItemsMap.put(thriftItem.getId(), thriftItem);
529
 
530
			}
531
			InventoryClient inventoryServiceClient = new InventoryClient();
532
			try {
533
				inventoryServiceClient = new InventoryClient();
534
			} catch (TTransportException e) {
535
				e.printStackTrace();
536
			}
537
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
538
			List<in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems> ignoreItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
539
			availability = inventoryClient.getInventorySnapshot(0);
540
			List<Warehouse> allwarehouses = inventoryClient.getWarehouses(null,null,0,0,0);
541
			Map<Long,Warehouse> allWarehousesMap = new HashMap<Long,Warehouse>();
542
			for(Warehouse warehouse:allwarehouses){
543
				allWarehousesMap.put(warehouse.getId(),warehouse);
544
			}
545
			List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS_THIRDPARTY,null,0,0,0);
546
			List<Warehouse> ours_warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 0, 0, 0);
547
			List<Long> thirdpartywarehouseids = new ArrayList<Long>();
548
			List<Long> oursGoodWarehouse = new ArrayList<Long>();
549
			for(Warehouse warehouse:warehouses){
550
				thirdpartywarehouseids.add(warehouse.getId());
551
			}
552
			for (Warehouse warehouse:ours_warehouses){
553
				oursGoodWarehouse.add(warehouse.getId());
554
			}
555
			long available=0;
556
			long reserve=0;
557
			long total_warehouse_held=0;
558
			long heldForSource=0;
559
			long total_held=0;
560
			double nlc=0;
561
			double maxnlc=0;
562
			Item thriftItem;
563
			for(FlipkartItem flipkartItem:flipkartInventoryItems){
564
				if(aliveItemsMap.get(flipkartItem.getItem_id()) != null){
565
					thriftItem = aliveItemsMap.get(flipkartItem.getItem_id());	
566
				}
567
				else{
568
					continue;
569
				}
570
				available=0;
571
				reserve=0;
572
				total_warehouse_held=0;
573
				heldForSource=0;
574
				total_held=0;
575
				nlc=0;
576
				List<Warehouse> vendor_warehouses=null;
577
				FlipkartInventoryItem item;
578
				if(availability.get(thriftItem.getId())!=null){ 
579
					ItemInventory iteminventory = availability.get(thriftItem.getId());
580
					Map<Long,Long> itemavailability = new HashMap<Long,Long>();
581
					itemavailability = iteminventory.getAvailability();
582
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
583
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating availability)"+thriftItem.getPreferredVendor());						
584
						vendor_warehouses = inventoryClient.getWarehouses(WarehouseType.THIRD_PARTY,InventoryType.GOOD , thriftItem.getPreferredVendor(), 0, 0);
585
						vendor_warehouses.addAll(ours_warehouses);
586
						for (Warehouse warehouse:vendor_warehouses){
587
							if(warehouse.getBillingWarehouseId()!=7){
588
								if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
589
 
590
								}
591
								else{
592
									continue;
593
								}
594
							}
595
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
596
							ignoredItem.setItemId(thriftItem.getId());
597
							ignoredItem.setWarehouseId(warehouse.getId());
598
							if (itemavailability.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(ignoredItem)){
599
								try{
600
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
601
								}
602
								catch(TTransportException e){
603
									inventoryClient = inventoryServiceClient.getClient(); 
604
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
605
								}
606
								maxnlc = flipkartItem.getMaxNlc();
607
 
608
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
609
								if(nlc !=0 && (maxnlc >= nlc)){
610
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
611
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
612
									available = available + itemavailability.get(warehouse.getId());
613
									total_held = total_held + total_warehouse_held; 
614
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
615
								}
616
								else if(maxnlc==0){
617
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
618
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
619
									available = available + itemavailability.get(warehouse.getId());
620
									total_held = total_held + total_warehouse_held;
621
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
622
								}
623
							}
624
						}
625
					}
626
					else{
627
						for (Map.Entry<Long,Long> entry :  itemavailability.entrySet()) {
628
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
629
								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){
630
 
631
								}
632
								else{
633
									continue;
634
								}
635
							}
636
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
637
							ignoredItem.setItemId(thriftItem.getId());
638
							ignoredItem.setWarehouseId(entry.getKey());
639
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
640
 
641
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
642
								maxnlc = flipkartItem.getMaxNlc();
643
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
644
								if(nlc !=0 && (maxnlc >= nlc)){
645
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
646
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
647
									available =  available + entry.getValue();
648
									total_held = total_held + total_warehouse_held;
649
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
650
								}
651
								else if(maxnlc==0){
652
									total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
653
									heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
654
									available = available + itemavailability.get(entry.getKey());
655
									total_held = total_held + total_warehouse_held;
656
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
657
								}
658
 
659
							}
660
						}
661
					}
662
					Map<Long,Long> itemreserve = new HashMap<Long,Long>();
663
					itemreserve = iteminventory.getReserved();
664
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
665
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating Reserve)"+thriftItem.getPreferredVendor());
666
						for (Warehouse warehouse:vendor_warehouses){
667
							if(warehouse.getBillingWarehouseId()!=7){
668
								if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
669
 
670
								}
671
								else{
672
									continue;
673
								}
674
							}
675
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
676
							ignoredItem.setItemId(thriftItem.getId());
677
							ignoredItem.setWarehouseId(warehouse.getId());
678
							if (itemreserve.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(warehouse.getId())){
679
								nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
680
								maxnlc = flipkartItem.getMaxNlc();
681
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
682
								if(nlc !=0 && (maxnlc >= nlc)){
683
									reserve = reserve + itemreserve.get(warehouse.getId());
684
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
685
								}
686
								else if(maxnlc==0){
687
									reserve = reserve + itemreserve.get(warehouse.getId());
688
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
689
								}
690
 
691
							}
692
						}
693
					}else{
694
						for (Map.Entry<Long,Long> entry : itemreserve.entrySet()) {
695
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
696
								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){
697
 
698
								}
699
								else{
700
									continue;
701
								}
702
							}
703
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
704
							ignoredItem.setItemId(thriftItem.getId());
705
							ignoredItem.setWarehouseId(entry.getKey());
706
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
707
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
708
								maxnlc = flipkartItem.getMaxNlc();
709
								//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
710
								if(nlc !=0 && (maxnlc >= nlc)){
711
									reserve =  reserve + entry.getValue();
712
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
713
								}
714
								else if(maxnlc==0){
715
									reserve =  reserve + entry.getValue();
716
									//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
717
								}
718
 
719
							}
720
 
721
							else{
722
								//System.out.println("skipping inventory for warehouse id " + entry.getKey());
723
							}
724
						}
725
					}
726
					item= new FlipkartInventoryItem(thriftItem.getId(),available,reserve,heldForSource,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),total_held,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
727
					//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
728
				}
729
				else{
730
					item = new FlipkartInventoryItem(thriftItem.getId(),0,0,0,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),0,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
731
					//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
732
				}
733
 
734
				//System.out.println(" Item details are " + thriftItem.getId() +" " + available + " " + reserve + " " + thriftItem.getHoldInventory() + " "+ thriftItem.getDefaultInventory() + " " + thriftItem.isRisky());
735
				//System.out.println("+++++++++++++++++++++++");
736
				flipkartItemsInventoryMap.put(thriftItem.getId(),item);
737
 
738
			}
739
 
740
		} catch (TException e) {
741
			e.printStackTrace();
742
		}
743
	}
744
 
745
	static List<String> FetchOrders() throws ClientProtocolException, IOException{
746
		HttpClient client = new DefaultHttpClient();
747
		HttpPost post = new HttpPost("https://seller.flipkart.com/login");
748
		BufferedReader rd= null;
749
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
750
		nameValuePairs.add(new BasicNameValuePair("authName",
751
		"flipkart"));
752
		nameValuePairs.add(new BasicNameValuePair("username",
753
		"flipkart-support@saholic.com"));
754
		nameValuePairs.add(new BasicNameValuePair("password",
755
		"076c27ee24d7596b06608a8ed2559f87"));
756
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
757
		HttpResponse response = client.execute(post);
758
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
759
		String line = "";
760
		Gson gson;
761
		List<Order> orders = new ArrayList<Order>(); 
762
		OrderItems new_orders;
763
		OrderItems conf_orders;
764
		HttpGet get_new;
765
		HttpGet get_conf; 
766
		long time;
767
		int i=1;
768
		while ((line = rd.readLine()) != null) {
769
			System.out.println(line);
770
		}
771
		time = System.currentTimeMillis();
772
		while(true){
773
			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);
774
			response = client.execute(get_new);
775
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
776
			line = "";
777
			gson = new Gson();
778
			new_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
779
			if(new_orders.getOrder_items().size()>0){
780
				orders.addAll(new_orders.getOrder_items());
781
			}
782
			else{
783
				break;
784
			}
785
			i++;
786
		}
787
		i=1;
788
		time = System.currentTimeMillis();
789
		while(true){
790
			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);
791
			response = client.execute(get_conf);
792
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
793
			line = "";
794
			gson = new Gson();
795
			conf_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
11862 vikram.rag 796
			if(conf_orders!=null & conf_orders.getOrder_items().size()>0){
9947 vikram.rag 797
				orders.addAll(conf_orders.getOrder_items());
798
			}
799
			else{
800
				break;
801
			}
802
			i++;
803
		}
804
		List<String> orderIdList = new ArrayList<String>();
10054 vikram.rag 805
		Long heldOrders = 0L;
9947 vikram.rag 806
		for(Order order:orders){
10153 vikram.rag 807
			System.out.println("Order  " + order.getExternalId() +" "+order.getOrderItemId() + " : "+ order.getStatus() + " "+order.getStatusDateMessage() + " "
808
					+ order.getStatusLabel() + " " + order.getPickup_by_date() + " "+ order.getTrackingId());
9947 vikram.rag 809
			orderIdList.add(order.getExternalId());
10049 vikram.rag 810
			if(order.getStatus().equalsIgnoreCase("on_hold")){
10062 vikram.rag 811
				if(heldOrdersMap.containsKey(String.valueOf(order.getSku()))){
10057 vikram.rag 812
					heldOrders = heldOrdersMap.get(String.valueOf(order.getSku()))+order.getQuantity();
813
					heldOrdersMap.put(String.valueOf(order.getSku()),heldOrders);
10059 vikram.rag 814
					System.out.println("Item ID " + order.getSku() + " Held Orders " + heldOrdersMap.get(String.valueOf(order.getSku())));
10049 vikram.rag 815
				}
816
				else{
10054 vikram.rag 817
					heldOrders = (long) order.getQuantity();
10057 vikram.rag 818
					heldOrdersMap.put(String.valueOf(order.getSku()),heldOrders);
10059 vikram.rag 819
					System.out.println("Item ID " + order.getSku() + " Held Orders " + heldOrdersMap.get(String.valueOf(order.getSku())));
10049 vikram.rag 820
				}
821
			}
9947 vikram.rag 822
		}
823
		return orderIdList; 
824
	}
9983 vikram.rag 825
	static String getProductName(Item item){
826
		return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor()); 
827
 
828
	}
829
	static String getName(String name){
830
		if(name==null || name.length()==0){
831
			return "";
832
		}
833
		else{
834
			return name;
835
		}
836
	}
9947 vikram.rag 837
}