Rev 9490 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.amazonaws.mws.samples;import in.shop2020.model.v1.inventory.AmazonFCWarehouseLocation;import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;import in.shop2020.thrift.clients.InventoryClient;import java.io.BufferedReader;import java.io.FileReader;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.IOException;import java.io.OutputStream;import java.util.ArrayList;import java.util.Arrays;import java.util.GregorianCalendar;import java.util.List;import java.util.Map;import javax.xml.datatype.DatatypeConfigurationException;import javax.xml.datatype.DatatypeFactory;import javax.xml.datatype.XMLGregorianCalendar;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;import au.com.bytecode.opencsv.CSVReader;import com.amazonaws.mws.MarketplaceWebService;import com.amazonaws.mws.MarketplaceWebServiceClient;import com.amazonaws.mws.MarketplaceWebServiceConfig;import com.amazonaws.mws.MarketplaceWebServiceException;import com.amazonaws.mws.model.GetReportListRequest;import com.amazonaws.mws.model.GetReportRequest;import com.amazonaws.mws.model.IdList;import com.amazonaws.mws.model.RequestReportRequest;public class FetchAmazonInventoryfromFile {public static void main(String... args){/************************************************************************* Access Key ID and Secret Access Key ID, obtained from:* http://aws.amazon.com***********************************************************************/final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";final String secretAccessKey = "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";final String appName = "Test";final String appVersion = "1.0";final String merchantId = "AF6E3O0VE0X4D";MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();/************************************************************************* Uncomment to set the appropriate MWS endpoint.************************************************************************/// US// config.setServiceURL("https://mws.amazonservices.com");// UK// config.setServiceURL("https://mws.amazonservices.co.uk");// Germany// config.setServiceURL("https://mws.amazonservices.de");// France// config.setServiceURL("https://mws.amazonservices.fr");// Italy// config.setServiceURL("https://mws.amazonservices.it");// Japan// config.setServiceURL("https://mws.amazonservices.jp");// China// config.setServiceURL("https://mws.amazonservices.com.cn");// Canada// config.setServiceURL("https://mws.amazonservices.ca");// Indiaconfig.setServiceURL("https://mws.amazonservices.in");/************************************************************************* You can also try advanced configuration options. Available options are:** - Signature Version* - Proxy Host and Proxy Port* - User Agent String to be sent to Marketplace Web Service************************************************************************//************************************************************************* Instantiate Http Client Implementation of Marketplace Web Service***********************************************************************/MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, appName, appVersion, config);/************************************************************************* Uncomment to try out Mock Service that simulates Marketplace Web Service* responses without calling Marketplace Web Service service.** Responses are loaded from local XML files. You can tweak XML files to* experiment with various outputs during development** XML files available under com/amazonaws/mws/mock tree************************************************************************/// MarketplaceWebService service = new MarketplaceWebServiceMock();/************************************************************************* Setup request parameters and uncomment invoke to try out* sample for Request Report***********************************************************************//************************************************************************* Marketplace and Merchant IDs are required parameters for all* Marketplace Web Service calls.***********************************************************************/// marketplaces from which data should be included in the report; look at the// API reference document on the MWS website to see which marketplaces are// included if you do not specify the list yourself/*CSVReader reader = null;try {//reader = new CSVReader(new FileReader("/home/vikram/Desktop/amazoninventoryreport.txt"),'\t');reader = new CSVReader(new FileReader("/home/amazoninventoryreport.csv"),'\t');} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}*/BufferedReader reader = null;try {reader = new BufferedReader(new FileReader("/home/amazoninventoryreport.csv"));} catch (FileNotFoundException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}String[] nextLine = null;String Line;List<AmazonFbaInventorySnapshot> allamazoninventory = new ArrayList<AmazonFbaInventorySnapshot>();try {while ((Line = reader.readLine()) != null) {nextLine = Line.split("\t");System.out.println("SKU " + nextLine[0] + " "+ nextLine[10] +" "+nextLine[11]+" "+nextLine[12]+" "+nextLine[16]);if(nextLine[0].startsWith("FBA")){AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;if(!nextLine[10].isEmpty())amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[10]));else{amazonfbainventorysnapshot.setAvailability(0);}amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));amazonfbainventorysnapshot.setLocation(AmazonFCWarehouseLocation.Mumbai);if(nextLine[12].length()>0){amazonfbainventorysnapshot.setReserved(Long.parseLong(nextLine[12]));}else{amazonfbainventorysnapshot.setReserved(0);}if(nextLine[11].length()>0){amazonfbainventorysnapshot.setUnfulfillable(Long.parseLong(nextLine[11]));}else{amazonfbainventorysnapshot.setUnfulfillable(0);}if(nextLine[16].length()>0){amazonfbainventorysnapshot.setInbound(Long.parseLong(nextLine[16]));}else{amazonfbainventorysnapshot.setInbound(0);}allamazoninventory.add(amazonfbainventorysnapshot);}else if(nextLine[0].startsWith("FBB")){AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[10]));amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBB","")));amazonfbainventorysnapshot.setLocation(AmazonFCWarehouseLocation.Bangalore);amazonfbainventorysnapshot.setReserved(Long.parseLong(nextLine[12]));amazonfbainventorysnapshot.setUnfulfillable(Long.parseLong(nextLine[11]));amazonfbainventorysnapshot.setInbound(Long.parseLong(nextLine[16]));allamazoninventory.add(amazonfbainventorysnapshot);}}new InventoryClient().getClient().addOrUpdateAllAmazonFbaInventory(allamazoninventory);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (TException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}