Subversion Repositories SmartDukaan

Rev

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

Rev 10532 Rev 10905
Line 35... Line 35...
35
import javax.xml.datatype.DatatypeFactory;
35
import javax.xml.datatype.DatatypeFactory;
36
import javax.xml.datatype.XMLGregorianCalendar;
36
import javax.xml.datatype.XMLGregorianCalendar;
37
 
37
 
38
import org.apache.commons.io.IOUtils;
38
import org.apache.commons.io.IOUtils;
39
import org.apache.thrift.TException;
39
import org.apache.thrift.TException;
-
 
40
import org.apache.thrift.transport.TTransportException;
40
 
41
 
41
import au.com.bytecode.opencsv.CSVReader;
42
import au.com.bytecode.opencsv.CSVReader;
42
 
43
 
43
import com.amazonaws.mws.MarketplaceWebService;
44
import com.amazonaws.mws.MarketplaceWebService;
44
import com.amazonaws.mws.MarketplaceWebServiceClient;
45
import com.amazonaws.mws.MarketplaceWebServiceClient;
Line 230... Line 231...
230
				requestorderreport.setReportOutputStream(orderreport);
231
				requestorderreport.setReportOutputStream(orderreport);
231
				requestinventoryhealthreport.setReportOutputStream(inventoryhealthreport);
232
				requestinventoryhealthreport.setReportOutputStream(inventoryhealthreport);
232
				GetReportSample.invokeGetReport(service, requestorderreport);
233
				GetReportSample.invokeGetReport(service, requestorderreport);
233
				GetReportSample.invokeGetReport(service, requestinventoryhealthreport);
234
				GetReportSample.invokeGetReport(service, requestinventoryhealthreport);
234
				System.out.println("Order and Inventory Reports are ready please check");
235
				System.out.println("Order and Inventory Reports are ready please check");
235
				
236
 
236
				String toFind = "<AmazonEnvelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\">";
237
				String toFind = "<AmazonEnvelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\">";
237
				String toReplace = "<AmazonEnvelope xmlns=\"http://mws.amazonaws.com/doc/2009-01-01/\">";
238
				String toReplace = "<AmazonEnvelope xmlns=\"http://mws.amazonaws.com/doc/2009-01-01/\">";
238
				File orderReportFile = new File("/home/amazonorderreport.xml");
239
				File orderReportFile = new File("/home/amazonorderreport.xml");
239
				String content = "";
240
				String content = "";
240
				try {
241
				try {
Line 252... Line 253...
252
				} catch (FileNotFoundException e1) {
253
				} catch (FileNotFoundException e1) {
253
					e1.printStackTrace();
254
					e1.printStackTrace();
254
				} catch (IOException e1) {
255
				} catch (IOException e1) {
255
					e1.printStackTrace();
256
					e1.printStackTrace();
256
				}
257
				}
257
				
258
 
258
				JAXBContext jc = null;
259
				JAXBContext jc = null;
259
				Unmarshaller unmarshaller = null;
260
				Unmarshaller unmarshaller = null;
260
				AmazonEnvelope amazonOrderData = null;
261
				AmazonEnvelope amazonOrderData = null;
261
				try {
262
				try {
262
					jc = JAXBContext.newInstance(AmazonEnvelope.class);
263
					jc = JAXBContext.newInstance(AmazonEnvelope.class);
263
					unmarshaller = jc.createUnmarshaller();
264
					unmarshaller = jc.createUnmarshaller();
264
					amazonOrderData = (AmazonEnvelope)unmarshaller.unmarshal(orderReportFile);
265
					amazonOrderData = (AmazonEnvelope)unmarshaller.unmarshal(orderReportFile);
265
				} catch (JAXBException e1) {
266
				} catch (JAXBException e1) {
266
					e1.printStackTrace();
267
					e1.printStackTrace();
267
				}
268
				}
268
				
269
 
269
				/*CSVReader orderreportreader = null;*/
270
				/*CSVReader orderreportreader = null;*/
270
				CSVReader inventoryhealthreportreader = null;
271
				CSVReader inventoryhealthreportreader = null;
271
				try {
272
				try {
272
					/*orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');*/
273
					/*orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');*/
273
					inventoryhealthreportreader = new CSVReader(new FileReader("/home/inventoryhealthreport.csv"),'\t');
274
					inventoryhealthreportreader = new CSVReader(new FileReader("/home/inventoryhealthreport.csv"),'\t');
Line 277... Line 278...
277
				}
278
				}
278
				String [] nextLine;
279
				String [] nextLine;
279
				try {
280
				try {
280
					int count =1;
281
					int count =1;
281
					Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
282
					Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
282
					
283
 
283
					if(amazonOrderData!=null){
284
					if(amazonOrderData!=null){
284
						List<Message> orderMessageList = amazonOrderData.getMessage();
285
						List<Message> orderMessageList = amazonOrderData.getMessage();
285
						System.out.println("Amazon Order List ... "+orderMessageList.size());
286
						System.out.println("Amazon Order List ... "+orderMessageList.size());
286
						for(Message orderMessage : orderMessageList){
287
						for(Message orderMessage : orderMessageList){
287
							Order amazonOrder = orderMessage.getOrder();
288
							Order amazonOrder = orderMessage.getOrder();
Line 307... Line 308...
307
									}
308
									}
308
									else{
309
									else{
309
										continue;
310
										continue;
310
									}
311
									}
311
								}
312
								}
312
								
313
 
313
								else{
314
								else{
314
									continue;
315
									continue;
315
								}
316
								}
316
								
317
 
317
								Float itemDiscount; 
318
								Float itemDiscount; 
318
								if(amazonOrder.getOrderItem().get(0).getPromotion()!=null){
319
								if(amazonOrder.getOrderItem().get(0).getPromotion()!=null){
319
									if(amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount()!=null && amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount().floatValue()!=0.0f){
320
									if(amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount()!=null && amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount().floatValue()!=0.0f){
320
										itemDiscount = amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount();
321
										itemDiscount = amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount();
321
									}
322
									}
Line 324... Line 325...
324
									}
325
									}
325
								}
326
								}
326
								else{
327
								else{
327
									itemDiscount = new Float(0);
328
									itemDiscount = new Float(0);
328
								}
329
								}
329
								
330
 
330
								if(("Cancelled").equalsIgnoreCase(amazonOrder.getOrderStatus()) || ("Cancelled").equalsIgnoreCase(amazonOrder.getOrderItem().get(0).getItemStatus())){
331
								if(("Cancelled").equalsIgnoreCase(amazonOrder.getOrderStatus()) || ("Cancelled").equalsIgnoreCase(amazonOrder.getOrderItem().get(0).getItemStatus())){
331
									itemSale = (float) 0; 
332
									itemSale = (float) 0; 
332
									itemDiscount = (float) 0;
333
									itemDiscount = (float) 0;
333
									qty = 0;
334
									qty = 0;
334
								}
335
								}
Line 379... Line 380...
379
									orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
380
									orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
380
								}
381
								}
381
							}
382
							}
382
						}
383
						}
383
					}
384
					}
384
					
385
 
385
					/*while ((nextLine = orderreportreader.readNext()) != null) {
386
					/*while ((nextLine = orderreportreader.readNext()) != null) {
386
						try{
387
						try{
387
							if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
388
							if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
388
								SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
389
								SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
389
								istFormatter .setLenient(false);
390
								istFormatter .setLenient(false);
Line 643... Line 644...
643
							}
644
							}
644
							else{
645
							else{
645
								oos=false;
646
								oos=false;
646
							}
647
							}
647
							Long item_id = entry1.getKey();
648
							Long item_id = entry1.getKey();
-
 
649
							Amazonlisted amazon_item;
-
 
650
							try{
648
							Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
651
								amazon_item=catalogClient.getAmazonItemDetails(item_id);
-
 
652
							}
-
 
653
							catch(TTransportException e){
-
 
654
								catalogClient   = catalogServiceClient.getClient();
-
 
655
								amazon_item=catalogClient.getAmazonItemDetails(item_id);
-
 
656
							}
649
							if(amazon_item.getItemid()==0){
657
							if(amazon_item.getItemid()==0){
650
								continue;
658
								continue;
651
							}
659
							}
652
							System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
660
							System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
653
							AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
661
							AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
Line 703... Line 711...
703
					// TODO Auto-generated catch block
711
					// TODO Auto-generated catch block
704
					e.printStackTrace();
712
					e.printStackTrace();
705
				} catch (TException e) {
713
				} catch (TException e) {
706
					// TODO Auto-generated catch block
714
					// TODO Auto-generated catch block
707
					e.printStackTrace();
715
					e.printStackTrace();
708
					
716
 
709
				}
717
				}
710
				break;
718
				break;
711
 
719
 
712
			}
720
			}
713
			else{ 
721
			else{ 
Line 728... Line 736...
728
		//
736
		//
729
 
737
 
730
 
738
 
731
	}
739
	}
732
 
740
 
733
	
741
 
734
	
742
 
735
}
743
}
736
744