Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
8285 kshitij.so 1
package com.amazonaws.mws.samples;
2
 
3
import in.shop2020.model.v1.catalog.Amazonlisted;
4
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
5
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
6
import in.shop2020.thrift.clients.CatalogClient;
7
import in.shop2020.thrift.clients.InventoryClient;
8
import in.shop2020.thrift.clients.TransactionClient;
8363 vikram.rag 9
import in.shop2020.utils.GmailUtils;
8285 kshitij.so 10
 
11
import java.io.FileNotFoundException;
12
import java.io.FileOutputStream;
13
import java.io.FileReader;
14
import java.io.IOException;
15
import java.io.OutputStream;
16
import java.text.ParseException;
17
import java.text.SimpleDateFormat;
18
import java.util.Arrays;
19
import java.util.Calendar;
20
import java.util.Date;
21
import java.util.GregorianCalendar;
22
import java.util.HashMap;
23
import java.util.List;
24
import java.util.Map;
8363 vikram.rag 25
import java.util.Map.Entry;
8285 kshitij.so 26
import java.util.TimeZone;
27
 
28
import javax.xml.datatype.DatatypeConfigurationException;
29
import javax.xml.datatype.DatatypeFactory;
30
import javax.xml.datatype.Duration;
31
import javax.xml.datatype.XMLGregorianCalendar;
32
 
33
import org.apache.thrift.TException;
34
import org.apache.thrift.transport.TTransportException;
35
 
36
import au.com.bytecode.opencsv.CSVReader;
37
 
38
import com.amazonaws.mws.MarketplaceWebService;
39
import com.amazonaws.mws.MarketplaceWebServiceClient;
40
import com.amazonaws.mws.MarketplaceWebServiceConfig;
8363 vikram.rag 41
import com.amazonaws.mws.MarketplaceWebServiceException;
8285 kshitij.so 42
import com.amazonaws.mws.model.GetReportListRequest;
43
import com.amazonaws.mws.model.GetReportRequest;
44
import com.amazonaws.mws.model.IdList;
45
import com.amazonaws.mws.model.RequestReportRequest;
46
 
47
public class FetchAmazonSalesSnapshot {
48
	public static void main(String... args){
49
		/************************************************************************
50
		 * Access Key ID and Secret Access Key ID, obtained from:
51
		 * http://aws.amazon.com
52
		 ***********************************************************************/
53
		final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
54
		final String secretAccessKey = "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";
55
 
56
		final String appName = "Test";
57
		final String appVersion = "1.0";
58
		final String merchantId = "AF6E3O0VE0X4D";
59
 
60
		MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
61
 
62
		/************************************************************************
63
		 * Uncomment to set the appropriate MWS endpoint.
64
		 ************************************************************************/
65
		// US
66
		// config.setServiceURL("https://mws.amazonservices.com");
67
		// UK
68
		// config.setServiceURL("https://mws.amazonservices.co.uk");
69
		// Germany
70
		// config.setServiceURL("https://mws.amazonservices.de");
71
		// France
72
		// config.setServiceURL("https://mws.amazonservices.fr");
73
		// Italy
74
		// config.setServiceURL("https://mws.amazonservices.it");
75
		// Japan
76
		// config.setServiceURL("https://mws.amazonservices.jp");
77
		// China
78
		// config.setServiceURL("https://mws.amazonservices.com.cn");
79
		// Canada
80
		// config.setServiceURL("https://mws.amazonservices.ca");
81
		// India
82
		config.setServiceURL("https://mws.amazonservices.in");
83
 
84
		/************************************************************************
85
		 * You can also try advanced configuration options. Available options are:
86
		 *
87
		 *  - Signature Version
88
		 *  - Proxy Host and Proxy Port
89
		 *  - User Agent String to be sent to Marketplace Web Service
90
		 *
91
		 ***********************************************************************/
92
 
93
		/************************************************************************
94
		 * Instantiate Http Client Implementation of Marketplace Web Service        
95
		 ***********************************************************************/
96
 
97
		MarketplaceWebService service = new MarketplaceWebServiceClient(
98
				accessKeyId, secretAccessKey, appName, appVersion, config);
99
 
100
		/************************************************************************
101
		 * Uncomment to try out Mock Service that simulates Marketplace Web Service 
102
		 * responses without calling Marketplace Web Service  service.
103
		 *
104
		 * Responses are loaded from local XML files. You can tweak XML files to
105
		 * experiment with various outputs during development
106
		 *
107
		 * XML files available under com/amazonaws/mws/mock tree
108
		 *
109
		 ***********************************************************************/
110
		// MarketplaceWebService service = new MarketplaceWebServiceMock();
111
 
112
		/************************************************************************
113
		 * Setup request parameters and uncomment invoke to try out 
114
		 * sample for Request Report 
115
		 ***********************************************************************/
116
 
117
		/************************************************************************
118
		 * Marketplace and Merchant IDs are required parameters for all 
119
		 * Marketplace Web Service calls.
120
		 ***********************************************************************/
121
		// marketplaces from which data should be included in the report; look at the
122
		// API reference document on the MWS website to see which marketplaces are
123
		// included if you do not specify the list yourself
124
		final IdList marketplaces = new IdList(Arrays.asList(
125
		"A21TJRUUN4KGV"));        
126
		RequestReportRequest orderreportrequest = new RequestReportRequest()
127
		.withMerchant(merchantId)
128
		.withMarketplaceIdList(marketplaces)
129
		.withReportType("_GET_FLAT_FILE_ALL_ORDERS_DATA_BY_ORDER_DATE_")
130
		.withReportOptions("ShowSalesChannel=true");
131
 
132
		RequestReportRequest inventoryhealthreportrequest = new RequestReportRequest()
133
		.withMerchant(merchantId)
134
		.withMarketplaceIdList(marketplaces)
135
		.withReportType("_GET_FBA_FULFILLMENT_INVENTORY_HEALTH_DATA_")
136
		.withReportOptions("ShowSalesChannel=true");
137
 
138
		DatatypeFactory df = null;
139
		try {
140
			df = DatatypeFactory.newInstance();
141
		} catch (DatatypeConfigurationException e) {
142
			e.printStackTrace();
143
			throw new RuntimeException(e);
144
		}
145
		long ordertimediff = System.currentTimeMillis() - 7*24*60*60*1000;
146
		GregorianCalendar ost = new GregorianCalendar();
147
		ost.setTimeInMillis(ordertimediff);
148
		XMLGregorianCalendar  orderStartDate = df.newXMLGregorianCalendar(ost);
149
		XMLGregorianCalendar orderEndDate = df.newXMLGregorianCalendar(new GregorianCalendar());
150
		System.out.println("Order Start Date  " + orderStartDate  + "Order End Date  " + orderEndDate);
151
		orderreportrequest.setStartDate(orderStartDate);
152
		orderreportrequest.setEndDate(orderEndDate);
153
		long inventorytimediff = System.currentTimeMillis() - 7*24*60*60*1000;
154
		GregorianCalendar ist = new GregorianCalendar();
155
		ist.setTimeInMillis(inventorytimediff);
156
		ist.setTimeInMillis(ordertimediff);
157
		XMLGregorianCalendar  inventoryStartDate = df.newXMLGregorianCalendar(ist);
158
		XMLGregorianCalendar inventoryEndDate = df.newXMLGregorianCalendar(new GregorianCalendar());
159
		System.out.println("Inventory Start Date  " + inventoryStartDate  + "Inventory End Date  " + inventoryEndDate);
160
		inventoryhealthreportrequest.setStartDate(inventoryStartDate);
161
		inventoryhealthreportrequest.setEndDate(inventoryEndDate);
162
		Map<String,String> requestIdreportIdmap;
8363 vikram.rag 163
		String orderreportrequestId = null;
164
		String inventoryhealthreportrequestId = null;
165
		boolean retry=true;
166
		int retryCount =0;
167
		while(retry && retryCount!=5){
168
			if(retryCount==4){
169
				String emailFromAddress = "build@shop2020.in";
170
				String password = "cafe@nes";
171
				String[] sendTo = new String[]{ "vikram.raghav@shop2020.in"};
172
				String emailSubjectTxt = "FBA Stock Estimation Sheet Failure";
173
 
174
				try {
175
					GmailUtils mailer = new GmailUtils();
176
					mailer.sendSSLMessage(sendTo, emailSubjectTxt, "", emailFromAddress, password,"");
177
				}
178
				catch (Exception ex) {
179
					ex.printStackTrace();
180
				}
181
 
182
				System.exit(1);
183
			}
184
			try {
185
				orderreportrequestId = RequestReportSample.invokeRequestReport(service, orderreportrequest);
186
				inventoryhealthreportrequestId = RequestReportSample.invokeRequestReport(service, inventoryhealthreportrequest);
187
				retry = false;
188
			} catch (MarketplaceWebServiceException e) {
189
				// TODO Auto-generated catch block
190
				e.printStackTrace();
191
				try {
192
					Thread.sleep(10*60*1000);
193
					retryCount++;
194
				} catch (InterruptedException e1) {
195
					// TODO Auto-generated catch block
196
					e1.printStackTrace();
197
				}
198
			}
199
		}
8285 kshitij.so 200
		while(true){
8363 vikram.rag 201
			GetReportListRequest requestreportlist = new GetReportListRequest();
202
			requestreportlist.setMerchant( merchantId );
203
			final IdList requestIdList = new IdList(Arrays.asList(orderreportrequestId,inventoryhealthreportrequestId));        
204
			requestreportlist.setReportRequestIdList(requestIdList);
205
			requestIdreportIdmap = GetReportListSample.invokeGetReportList(service, requestreportlist);
206
			if(requestIdreportIdmap.get(orderreportrequestId)!=null && requestIdreportIdmap.get(inventoryhealthreportrequestId)!=null){
207
				GetReportRequest requestorderreport = new GetReportRequest();
208
				GetReportRequest requestinventoryhealthreport = new GetReportRequest();
209
				requestorderreport.setMerchant( merchantId );
210
				requestinventoryhealthreport.setMerchant(merchantId);
211
				requestorderreport.setReportId( requestIdreportIdmap.get(orderreportrequestId));
212
				requestinventoryhealthreport.setReportId(requestIdreportIdmap.get(inventoryhealthreportrequestId));
213
				OutputStream orderreport=null;
214
				OutputStream inventoryhealthreport=null;
215
				try {
216
					orderreport = new FileOutputStream( "/home/amazonorderreport.csv" );
217
					inventoryhealthreport = new FileOutputStream( "/home/inventoryhealthreport.csv" );
218
				} catch (FileNotFoundException e) {
219
					// TODO Auto-generated catch block
220
					e.printStackTrace();
221
				}
222
				requestorderreport.setReportOutputStream(orderreport);
223
				requestinventoryhealthreport.setReportOutputStream(inventoryhealthreport);
224
				GetReportSample.invokeGetReport(service, requestorderreport);
225
				GetReportSample.invokeGetReport(service, requestinventoryhealthreport);
226
				System.out.println("Order and Inventory Reports are ready please check");
227
				CSVReader orderreportreader = null;
228
				CSVReader inventoryhealthreportreader = null;
229
				try {
230
					orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');
231
					inventoryhealthreportreader = new CSVReader(new FileReader("/home/inventoryhealthreport.csv"),'\t');
232
				} catch (FileNotFoundException e) {
233
					// TODO Auto-generated catch block
234
					e.printStackTrace();
235
				}
236
				String [] nextLine;
237
				try {
238
					int count =1;
239
					Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
240
					while ((nextLine = orderreportreader.readNext()) != null) {
241
						if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in") && (nextLine[13].equalsIgnoreCase("Unshipped") || nextLine[13].equalsIgnoreCase("Shipped"))){
242
							SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
243
							istFormatter .setLenient(false);
244
							TimeZone zone= TimeZone.getTimeZone("GMT");
245
							istFormatter.setTimeZone(zone);
246
							Date date = istFormatter.parse(nextLine[2]);
247
							SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
248
							Date date_key = dateFormat.parse(dateFormat.format(date));
249
							System.out.println(nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
250
							Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
8451 vikram.rag 251
 
8363 vikram.rag 252
							Integer qty = new Integer(nextLine[14]);
253
							Float itemSale = null;
254
							if(nextLine[16].length()!=0){
255
								itemSale = new Float(nextLine[16]);
8422 vikram.rag 256
							}
257
							else{
8363 vikram.rag 258
								continue;
259
							}
260
							Float itemDiscount; 
261
							if(nextLine[22].length()!=0){
262
								itemDiscount = new Float(nextLine[22]);
263
							}
264
							else{
265
								itemDiscount = new Float(0);
266
							}
267
							if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
268
								if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
269
									FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
270
									if(itemDiscount!=0){
8422 vikram.rag 271
										fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
272
										fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
8294 kshitij.so 273
									}
8363 vikram.rag 274
									fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
275
									fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale);
276
									orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
8285 kshitij.so 277
								}
8294 kshitij.so 278
								else{
8363 vikram.rag 279
									FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
280
									fbaSalesSnapshot.setTotalOrderCount(qty);
281
									fbaSalesSnapshot.setTotalSale(itemSale);
282
									if(itemDiscount!=0){
283
										fbaSalesSnapshot.setPromotionOrderCount(qty);
284
										fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
8294 kshitij.so 285
									}
8363 vikram.rag 286
									else{
287
										fbaSalesSnapshot.setPromotionOrderCount(0);
288
										fbaSalesSnapshot.setTotalPromotionSale((float) 0);
289
									}
290
									orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
8294 kshitij.so 291
								}
8363 vikram.rag 292
							}
293
							else{
294
								Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
295
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
296
								fbaSalesSnapshot.setTotalOrderCount(qty);
297
								fbaSalesSnapshot.setTotalSale(itemSale);
298
								if(itemDiscount!=0){
299
									fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
300
									fbaSalesSnapshot.setPromotionOrderCount(qty);
301
								}
8294 kshitij.so 302
								else{
8363 vikram.rag 303
									fbaSalesSnapshot.setTotalPromotionSale((float) 0);
304
									fbaSalesSnapshot.setPromotionOrderCount(0);
8294 kshitij.so 305
								}
8363 vikram.rag 306
								ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
307
								orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
8293 kshitij.so 308
							}
8363 vikram.rag 309
						} 
310
						count++;
311
					}
312
					InventoryClient inventoryServiceClient = null;
313
					TransactionClient transactionServiceClient = null;
314
					CatalogClient catalogServiceClient = null;
315
					try {
316
						inventoryServiceClient = new InventoryClient();
317
						transactionServiceClient = new TransactionClient();
8373 vikram.rag 318
						//catalogServiceClient = new CatalogClient();
319
						catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
8363 vikram.rag 320
					} catch (Exception e) {
321
						// TODO Auto-generated catch block
322
						e.printStackTrace();
323
					}	
324
					in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
325
					in.shop2020.model.v1.order.TransactionService.Client transactionClient   = transactionServiceClient.getClient();
326
					in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
327
					SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
328
					Date date_today = dateFormat.parse(dateFormat.format(new Date()));
329
					List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
330
					if(nonzeroFbaInventorySnapshotlist!=null){
331
						for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
332
							if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_today) ){ 
333
								if(!orderDateItemIdFbaSaleSnapshotMap.get(date_today).containsKey(amazonFbaInventory.getItem_id())){
334
									Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
335
									FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
336
									fbaSalesSnapshot.setTotalOrderCount(0);
337
									fbaSalesSnapshot.setPromotionOrderCount(0);
338
									fbaSalesSnapshot.setTotalPromotionSale((float) 0);
339
									fbaSalesSnapshot.setTotalSale((float) 0);
340
									ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
341
									orderDateItemIdFbaSaleSnapshotMap.get(date_today).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
342
								}
343
 
344
							}
345
							else{
346
								Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
347
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
348
								fbaSalesSnapshot.setTotalOrderCount(0);
349
								fbaSalesSnapshot.setPromotionOrderCount(0);
350
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
351
								fbaSalesSnapshot.setTotalSale((float) 0);
352
								ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
353
								orderDateItemIdFbaSaleSnapshotMap.put(date_today,ItemIdFbaSaleSnapshotMap);
354
							}
8285 kshitij.so 355
						}
8363 vikram.rag 356
					}
357
					else{
358
						System.out.println("No inventory in FBA");
359
					}
8445 vikram.rag 360
					Map<Long,Double> itemIdOurPriceMap = new HashMap<Long,Double>();
8363 vikram.rag 361
					Map<Long,Double> itemIdSalePriceMap = new HashMap<Long,Double>();
362
					Map<Long,Double> itemIdminFBAPriceMap = new HashMap<Long,Double>();
363
					Map<Long,Double> itemIdminMFNPriceMap = new HashMap<Long,Double>();
364
					count=1;
365
					while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
366
						if(count!=1){
367
							//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
368
							Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
8451 vikram.rag 369
							Double ourPrice = null;
370
							Double minFBAPrice= null;
371
							Double minMFNPrice= null;
372
							Double salePrice= null; 
373
 
374
							if(nextLine[30].length() >0){
375
								ourPrice = Double.parseDouble(nextLine[30]);
376
								itemIdOurPriceMap.put(item_id,ourPrice);
377
							}
378
							if(nextLine[31].length() >0){
379
								salePrice = Double.parseDouble(nextLine[31]);
380
								itemIdSalePriceMap.put(item_id,salePrice);
381
							}
382
							if(nextLine[32].length() >0){
383
								minFBAPrice = Double.parseDouble(nextLine[32]);
384
								itemIdminFBAPriceMap.put(item_id,minFBAPrice);
385
							}
386
							if(nextLine[32].length() >0){
387
								minMFNPrice = Double.parseDouble(nextLine[34]);
388
								itemIdminMFNPriceMap.put(item_id,minMFNPrice);
389
							}
8285 kshitij.so 390
						}
8363 vikram.rag 391
						count++;
392
					}
393
					boolean oos;
394
					for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
395
						Date orderDate = entry.getKey();
396
						for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
397
							System.out.println("Item ID is " + entry1.getKey());
398
							Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
399
 
400
							if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
401
								oos=true;
8285 kshitij.so 402
							}
8363 vikram.rag 403
							else{
8294 kshitij.so 404
								oos=false;
8285 kshitij.so 405
							}
8363 vikram.rag 406
							Long item_id = entry1.getKey();
407
							System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
408
							AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
409
							amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
410
							amazonfbasalessnapshot.setItem_id(entry1.getKey());
411
							amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
412
							amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
413
							amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
414
							amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
415
							amazonfbasalessnapshot.setIsOutOfStock(oos);
416
							Amazonlisted amazon_item=null;
417
							if(catalogClient.getAmazonItemDetails(item_id)!=null)
418
								amazon_item = catalogClient.getAmazonItemDetails(item_id);
419
							else 
420
								continue;
421
							if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id)!=0){
422
								amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id));
423
							}
424
							else{
425
								amazonfbasalessnapshot.setSalePrice(amazon_item.getFbaPrice());
426
							}
427
							if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id)!=0){
428
								amazonfbasalessnapshot.setMinFbaPrice(itemIdminMFNPriceMap.get(item_id));
429
							}
430
							else{
431
								amazonfbasalessnapshot.setMinFbaPrice(0.0);
432
							}
433
							if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id)!=0){
434
								amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id));
435
							}
436
							else{
437
								amazonfbasalessnapshot.setMinMfnPrice(0.0);
438
							}
8452 vikram.rag 439
							if(itemIdOurPriceMap.containsKey(item_id)){
8445 vikram.rag 440
								amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id));
441
							}
442
							else{
8453 vikram.rag 443
								amazonfbasalessnapshot.setOurPrice(0);
8445 vikram.rag 444
							}
8363 vikram.rag 445
							amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
446
							transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
8285 kshitij.so 447
						}
448
					}
8363 vikram.rag 449
				} catch (IOException e) {
450
					// TODO Auto-generated catch block
451
					e.printStackTrace();
452
				} catch (ParseException e) {
453
					// TODO Auto-generated catch block
454
					e.printStackTrace();
455
				} catch (TException e) {
456
					// TODO Auto-generated catch block
457
					e.printStackTrace();
458
					continue;
8285 kshitij.so 459
				}
8363 vikram.rag 460
				break;
461
 
462
			}
463
			else{ 
464
				System.out.println("Report not ready");
465
				try {
466
					Thread.sleep(5*60*1000);
467
				} catch (InterruptedException e) {
468
					// TODO Auto-generated catch block
469
					e.printStackTrace();
8294 kshitij.so 470
				}
471
			}
8285 kshitij.so 472
		}
473
 
474
		// Note that depending on the type of report being downloaded, a report can reach 
475
		// sizes greater than 1GB. For this reason we recommend that you _always_ program to
476
		// MWS in a streaming fashion. Otherwise, as your business grows you may silently reach
477
		// the in-memory size limit and have to re-work your solution.
478
		//
479
 
480
 
481
	}
482
 
483
}