| 9490 |
vikram.rag |
1 |
package com.amazonaws.mws.samples;
|
|
|
2 |
|
| 11172 |
vikram.rag |
3 |
import in.shop2020.model.v1.inventory.AmazonFCWarehouseLocation;
|
| 9490 |
vikram.rag |
4 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
|
|
5 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 11172 |
vikram.rag |
6 |
import java.io.BufferedReader;
|
|
|
7 |
import java.io.FileReader;
|
| 9490 |
vikram.rag |
8 |
import java.io.FileNotFoundException;
|
|
|
9 |
import java.io.FileOutputStream;
|
|
|
10 |
import java.io.FileReader;
|
|
|
11 |
import java.io.IOException;
|
|
|
12 |
import java.io.OutputStream;
|
|
|
13 |
import java.util.ArrayList;
|
|
|
14 |
import java.util.Arrays;
|
|
|
15 |
import java.util.GregorianCalendar;
|
|
|
16 |
import java.util.List;
|
|
|
17 |
import java.util.Map;
|
|
|
18 |
|
|
|
19 |
import javax.xml.datatype.DatatypeConfigurationException;
|
|
|
20 |
import javax.xml.datatype.DatatypeFactory;
|
|
|
21 |
import javax.xml.datatype.XMLGregorianCalendar;
|
|
|
22 |
|
|
|
23 |
import org.apache.thrift.TException;
|
|
|
24 |
import org.apache.thrift.transport.TTransportException;
|
|
|
25 |
|
|
|
26 |
import au.com.bytecode.opencsv.CSVReader;
|
|
|
27 |
|
|
|
28 |
import com.amazonaws.mws.MarketplaceWebService;
|
|
|
29 |
import com.amazonaws.mws.MarketplaceWebServiceClient;
|
|
|
30 |
import com.amazonaws.mws.MarketplaceWebServiceConfig;
|
|
|
31 |
import com.amazonaws.mws.MarketplaceWebServiceException;
|
|
|
32 |
import com.amazonaws.mws.model.GetReportListRequest;
|
|
|
33 |
import com.amazonaws.mws.model.GetReportRequest;
|
|
|
34 |
import com.amazonaws.mws.model.IdList;
|
|
|
35 |
import com.amazonaws.mws.model.RequestReportRequest;
|
|
|
36 |
|
|
|
37 |
public class FetchAmazonInventoryfromFile {
|
|
|
38 |
public static void main(String... args){
|
|
|
39 |
/************************************************************************
|
|
|
40 |
* Access Key ID and Secret Access Key ID, obtained from:
|
|
|
41 |
* http://aws.amazon.com
|
|
|
42 |
***********************************************************************/
|
|
|
43 |
final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
|
|
|
44 |
final String secretAccessKey = "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg";
|
|
|
45 |
|
|
|
46 |
final String appName = "Test";
|
|
|
47 |
final String appVersion = "1.0";
|
|
|
48 |
final String merchantId = "AF6E3O0VE0X4D";
|
|
|
49 |
|
|
|
50 |
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
|
|
|
51 |
|
|
|
52 |
/************************************************************************
|
|
|
53 |
* Uncomment to set the appropriate MWS endpoint.
|
|
|
54 |
************************************************************************/
|
|
|
55 |
// US
|
|
|
56 |
// config.setServiceURL("https://mws.amazonservices.com");
|
|
|
57 |
// UK
|
|
|
58 |
// config.setServiceURL("https://mws.amazonservices.co.uk");
|
|
|
59 |
// Germany
|
|
|
60 |
// config.setServiceURL("https://mws.amazonservices.de");
|
|
|
61 |
// France
|
|
|
62 |
// config.setServiceURL("https://mws.amazonservices.fr");
|
|
|
63 |
// Italy
|
|
|
64 |
// config.setServiceURL("https://mws.amazonservices.it");
|
|
|
65 |
// Japan
|
|
|
66 |
// config.setServiceURL("https://mws.amazonservices.jp");
|
|
|
67 |
// China
|
|
|
68 |
// config.setServiceURL("https://mws.amazonservices.com.cn");
|
|
|
69 |
// Canada
|
|
|
70 |
// config.setServiceURL("https://mws.amazonservices.ca");
|
|
|
71 |
// India
|
|
|
72 |
config.setServiceURL("https://mws.amazonservices.in");
|
|
|
73 |
|
|
|
74 |
/************************************************************************
|
|
|
75 |
* You can also try advanced configuration options. Available options are:
|
|
|
76 |
*
|
|
|
77 |
* - Signature Version
|
|
|
78 |
* - Proxy Host and Proxy Port
|
|
|
79 |
* - User Agent String to be sent to Marketplace Web Service
|
|
|
80 |
*
|
|
|
81 |
***********************************************************************/
|
|
|
82 |
|
|
|
83 |
/************************************************************************
|
|
|
84 |
* Instantiate Http Client Implementation of Marketplace Web Service
|
|
|
85 |
***********************************************************************/
|
|
|
86 |
|
|
|
87 |
MarketplaceWebService service = new MarketplaceWebServiceClient(
|
|
|
88 |
accessKeyId, secretAccessKey, appName, appVersion, config);
|
|
|
89 |
|
|
|
90 |
/************************************************************************
|
|
|
91 |
* Uncomment to try out Mock Service that simulates Marketplace Web Service
|
|
|
92 |
* responses without calling Marketplace Web Service service.
|
|
|
93 |
*
|
|
|
94 |
* Responses are loaded from local XML files. You can tweak XML files to
|
|
|
95 |
* experiment with various outputs during development
|
|
|
96 |
*
|
|
|
97 |
* XML files available under com/amazonaws/mws/mock tree
|
|
|
98 |
*
|
|
|
99 |
***********************************************************************/
|
|
|
100 |
// MarketplaceWebService service = new MarketplaceWebServiceMock();
|
|
|
101 |
|
|
|
102 |
/************************************************************************
|
|
|
103 |
* Setup request parameters and uncomment invoke to try out
|
|
|
104 |
* sample for Request Report
|
|
|
105 |
***********************************************************************/
|
|
|
106 |
|
|
|
107 |
/************************************************************************
|
|
|
108 |
* Marketplace and Merchant IDs are required parameters for all
|
|
|
109 |
* Marketplace Web Service calls.
|
|
|
110 |
***********************************************************************/
|
|
|
111 |
// marketplaces from which data should be included in the report; look at the
|
|
|
112 |
// API reference document on the MWS website to see which marketplaces are
|
|
|
113 |
// included if you do not specify the list yourself
|
| 11172 |
vikram.rag |
114 |
/*CSVReader reader = null;
|
| 9490 |
vikram.rag |
115 |
try {
|
| 11172 |
vikram.rag |
116 |
//reader = new CSVReader(new FileReader("/home/vikram/Desktop/amazoninventoryreport.txt"),'\t');
|
|
|
117 |
reader = new CSVReader(new FileReader("/home/amazoninventoryreport.csv"),'\t');
|
|
|
118 |
} catch (FileNotFoundException e) {
|
|
|
119 |
// TODO Auto-generated catch block
|
| 9490 |
vikram.rag |
120 |
e.printStackTrace();
|
| 11172 |
vikram.rag |
121 |
}*/
|
|
|
122 |
BufferedReader reader = null;
|
|
|
123 |
try {
|
|
|
124 |
reader = new BufferedReader(new FileReader("/home/amazoninventoryreport.csv"));
|
|
|
125 |
} catch (FileNotFoundException e1) {
|
|
|
126 |
// TODO Auto-generated catch block
|
|
|
127 |
e1.printStackTrace();
|
| 9490 |
vikram.rag |
128 |
}
|
| 11172 |
vikram.rag |
129 |
String[] nextLine = null;
|
|
|
130 |
String Line;
|
|
|
131 |
List<AmazonFbaInventorySnapshot> allamazoninventory = new ArrayList<AmazonFbaInventorySnapshot>();
|
|
|
132 |
try {
|
|
|
133 |
while ((Line = reader.readLine()) != null) {
|
|
|
134 |
nextLine = Line.split("\t");
|
|
|
135 |
System.out.println("SKU " + nextLine[0] + " "+ nextLine[10] +" "+nextLine[11]+" "+nextLine[12]+" "+nextLine[16]);
|
|
|
136 |
if(nextLine[0].startsWith("FBA")){
|
|
|
137 |
AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
|
|
|
138 |
if(!nextLine[10].isEmpty())
|
|
|
139 |
amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[10]));
|
|
|
140 |
else{
|
|
|
141 |
amazonfbainventorysnapshot.setAvailability(0);
|
| 9490 |
vikram.rag |
142 |
}
|
| 11172 |
vikram.rag |
143 |
amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));
|
|
|
144 |
amazonfbainventorysnapshot.setLocation(AmazonFCWarehouseLocation.Mumbai);
|
|
|
145 |
if(nextLine[12].length()>0){
|
|
|
146 |
amazonfbainventorysnapshot.setReserved(Long.parseLong(nextLine[12]));
|
|
|
147 |
}
|
|
|
148 |
else{
|
|
|
149 |
amazonfbainventorysnapshot.setReserved(0);
|
|
|
150 |
}
|
|
|
151 |
if(nextLine[11].length()>0){
|
|
|
152 |
amazonfbainventorysnapshot.setUnfulfillable(Long.parseLong(nextLine[11]));
|
|
|
153 |
}
|
|
|
154 |
else{
|
|
|
155 |
amazonfbainventorysnapshot.setUnfulfillable(0);
|
|
|
156 |
}
|
|
|
157 |
if(nextLine[16].length()>0){
|
|
|
158 |
amazonfbainventorysnapshot.setInbound(Long.parseLong(nextLine[16]));
|
|
|
159 |
}
|
|
|
160 |
else{
|
|
|
161 |
amazonfbainventorysnapshot.setInbound(0);
|
|
|
162 |
}
|
|
|
163 |
allamazoninventory.add(amazonfbainventorysnapshot);
|
| 9490 |
vikram.rag |
164 |
|
| 11172 |
vikram.rag |
165 |
}
|
|
|
166 |
else if(nextLine[0].startsWith("FBB")){
|
|
|
167 |
AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
|
|
|
168 |
amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[10]));
|
|
|
169 |
amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBB","")));
|
|
|
170 |
amazonfbainventorysnapshot.setLocation(AmazonFCWarehouseLocation.Bangalore);
|
|
|
171 |
amazonfbainventorysnapshot.setReserved(Long.parseLong(nextLine[12]));
|
|
|
172 |
amazonfbainventorysnapshot.setUnfulfillable(Long.parseLong(nextLine[11]));
|
|
|
173 |
amazonfbainventorysnapshot.setInbound(Long.parseLong(nextLine[16]));
|
|
|
174 |
allamazoninventory.add(amazonfbainventorysnapshot);
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
new InventoryClient().getClient().addOrUpdateAllAmazonFbaInventory(allamazoninventory);
|
|
|
178 |
} catch (IOException e) {
|
|
|
179 |
// TODO Auto-generated catch block
|
|
|
180 |
e.printStackTrace();
|
|
|
181 |
} catch (TException e) {
|
|
|
182 |
// TODO Auto-generated catch block
|
|
|
183 |
e.printStackTrace();
|
|
|
184 |
}
|
| 9490 |
vikram.rag |
185 |
}
|
|
|
186 |
}
|