| Line 1... |
Line 1... |
| 1 |
package com.amazonaws.mws.samples;
|
1 |
package com.amazonaws.mws.samples;
|
| 2 |
|
2 |
|
| - |
|
3 |
import in.shop2020.model.v1.inventory.AmazonFCWarehouseLocation;
|
| 3 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
4 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
| 4 |
import in.shop2020.thrift.clients.CatalogClient;
|
5 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 5 |
import in.shop2020.thrift.clients.InventoryClient;
|
6 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 6 |
|
7 |
|
| - |
|
8 |
import java.io.BufferedReader;
|
| 7 |
import java.io.FileNotFoundException;
|
9 |
import java.io.FileNotFoundException;
|
| 8 |
import java.io.FileOutputStream;
|
10 |
import java.io.FileOutputStream;
|
| 9 |
import java.io.FileReader;
|
11 |
import java.io.FileReader;
|
| 10 |
import java.io.IOException;
|
12 |
import java.io.IOException;
|
| 11 |
import java.io.OutputStream;
|
13 |
import java.io.OutputStream;
|
| Line 113... |
Line 115... |
| 113 |
final IdList marketplaces = new IdList(Arrays.asList(
|
115 |
final IdList marketplaces = new IdList(Arrays.asList(
|
| 114 |
"A21TJRUUN4KGV"));
|
116 |
"A21TJRUUN4KGV"));
|
| 115 |
RequestReportRequest request = new RequestReportRequest()
|
117 |
RequestReportRequest request = new RequestReportRequest()
|
| 116 |
.withMerchant(merchantId)
|
118 |
.withMerchant(merchantId)
|
| 117 |
.withMarketplaceIdList(marketplaces)
|
119 |
.withMarketplaceIdList(marketplaces)
|
| 118 |
.withReportType("_GET_AFN_INVENTORY_DATA_")
|
120 |
.withReportType("_GET_FBA_MYI_ALL_INVENTORY_DATA_")
|
| 119 |
.withReportOptions("ShowSalesChannel=true");
|
121 |
.withReportOptions("ShowSalesChannel=true");
|
| 120 |
|
122 |
|
| 121 |
// demonstrates how to set the date range
|
123 |
// demonstrates how to set the date range
|
| 122 |
DatatypeFactory df = null;
|
124 |
DatatypeFactory df = null;
|
| 123 |
try {
|
125 |
try {
|
| Line 164... |
Line 166... |
| 164 |
e.printStackTrace();
|
166 |
e.printStackTrace();
|
| 165 |
}
|
167 |
}
|
| 166 |
requestreport.setReportOutputStream( report );
|
168 |
requestreport.setReportOutputStream( report );
|
| 167 |
GetReportSample.invokeGetReport(service, requestreport);
|
169 |
GetReportSample.invokeGetReport(service, requestreport);
|
| 168 |
//System.out.println("Report ready please check");
|
170 |
//System.out.println("Report ready please check");
|
| 169 |
CSVReader reader = null;
|
171 |
BufferedReader reader = null;
|
| 170 |
try {
|
172 |
try {
|
| 171 |
//reader = new CSVReader(new FileReader("/home/vikram/Desktop/amazoninventoryreport.txt"),'\t');
|
- |
|
| 172 |
reader = new CSVReader(new FileReader("/home/amazoninventoryreport.csv"),'\t');
|
173 |
reader = new BufferedReader(new FileReader("/home/amazoninventoryreport.csv"));
|
| 173 |
} catch (FileNotFoundException e) {
|
174 |
} catch (FileNotFoundException e1) {
|
| 174 |
// TODO Auto-generated catch block
|
175 |
// TODO Auto-generated catch block
|
| 175 |
e.printStackTrace();
|
176 |
e1.printStackTrace();
|
| 176 |
}
|
177 |
}
|
| 177 |
String [] nextLine;
|
178 |
String[] nextLine = null;
|
| 178 |
//CatalogClient catalogServiceClient = null;
|
- |
|
| 179 |
InventoryClient inventoryServiceClient = null;
|
- |
|
| 180 |
try {
|
179 |
String Line;
|
| 181 |
inventoryServiceClient = new InventoryClient();
|
- |
|
| 182 |
//catalogServiceClient = new CatalogClient();
|
- |
|
| 183 |
//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
- |
|
| 184 |
} catch (Exception e) {
|
- |
|
| 185 |
// TODO Auto-generated catch block
|
- |
|
| 186 |
e.printStackTrace();
|
- |
|
| 187 |
}
|
- |
|
| 188 |
//in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
- |
|
| 189 |
List<AmazonFbaInventorySnapshot> allamazoninventory = new ArrayList<AmazonFbaInventorySnapshot>();
|
180 |
List<AmazonFbaInventorySnapshot> allamazoninventory = new ArrayList<AmazonFbaInventorySnapshot>();
|
| 190 |
try {
|
181 |
try {
|
| 191 |
while ((nextLine = reader.readNext()) != null) {
|
182 |
while ((Line = reader.readLine()) != null) {
|
| 192 |
// nextLine[] is an array of values from the line
|
183 |
nextLine = Line.split("\t");
|
| 193 |
//System.out.println(nextLine[0] +" "+ nextLine[1]+" " + nextLine[2]+" " + nextLine[3] +" "+ nextLine[4] +" " + nextLine[5]);
|
184 |
System.out.println("SKU " + nextLine[0] + " "+ nextLine[10] +" "+nextLine[11]+" "+nextLine[12]+" "+nextLine[16]);
|
| 194 |
if(nextLine[0].startsWith("FBA") && nextLine[4].equalsIgnoreCase("SELLABLE") ){
|
185 |
if(nextLine[0].startsWith("FBA")){
|
| 195 |
//System.out.println("Item ID" + nextLine[0].replaceAll("FBA","") + "---"+"Inventory" + nextLine[5]);
|
186 |
AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
|
| - |
|
187 |
if(!nextLine[10].isEmpty())
|
| - |
|
188 |
amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[10]));
|
| - |
|
189 |
else{
|
| - |
|
190 |
amazonfbainventorysnapshot.setAvailability(0);
|
| - |
|
191 |
}
|
| 196 |
//if(catalogClient.getAmazonItemDetails(Long.parseLong(nextLine[0].replaceAll("FBA",""))).getItemid()!=0){
|
192 |
amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));
|
| - |
|
193 |
amazonfbainventorysnapshot.setLocation(AmazonFCWarehouseLocation.Mumbai);
|
| - |
|
194 |
if(nextLine[12].length()>0){
|
| 197 |
AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
|
195 |
amazonfbainventorysnapshot.setReserved(Long.parseLong(nextLine[12]));
|
| - |
|
196 |
}
|
| - |
|
197 |
else{
|
| - |
|
198 |
amazonfbainventorysnapshot.setReserved(0);
|
| - |
|
199 |
}
|
| - |
|
200 |
if(nextLine[11].length()>0){
|
| 198 |
amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[5]));
|
201 |
amazonfbainventorysnapshot.setUnfulfillable(Long.parseLong(nextLine[11]));
|
| - |
|
202 |
}
|
| - |
|
203 |
else{
|
| - |
|
204 |
amazonfbainventorysnapshot.setUnfulfillable(0);
|
| - |
|
205 |
}
|
| - |
|
206 |
if(nextLine[16].length()>0){
|
| 199 |
amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));
|
207 |
amazonfbainventorysnapshot.setInbound(Long.parseLong(nextLine[16]));
|
| - |
|
208 |
}
|
| - |
|
209 |
else{
|
| - |
|
210 |
amazonfbainventorysnapshot.setInbound(0);
|
| - |
|
211 |
}
|
| 200 |
allamazoninventory.add(amazonfbainventorysnapshot);
|
212 |
allamazoninventory.add(amazonfbainventorysnapshot);
|
| 201 |
|
213 |
|
| 202 |
// }
|
214 |
}
|
| - |
|
215 |
else if(nextLine[0].startsWith("FBB")){
|
| - |
|
216 |
AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
|
| - |
|
217 |
amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[10]));
|
| - |
|
218 |
amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBB","")));
|
| - |
|
219 |
amazonfbainventorysnapshot.setLocation(AmazonFCWarehouseLocation.Bangalore);
|
| - |
|
220 |
amazonfbainventorysnapshot.setReserved(Long.parseLong(nextLine[12]));
|
| - |
|
221 |
amazonfbainventorysnapshot.setUnfulfillable(Long.parseLong(nextLine[11]));
|
| - |
|
222 |
amazonfbainventorysnapshot.setInbound(Long.parseLong(nextLine[16]));
|
| - |
|
223 |
allamazoninventory.add(amazonfbainventorysnapshot);
|
| 203 |
}
|
224 |
}
|
| 204 |
}
|
225 |
}
|
| 205 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
- |
|
| 206 |
inventoryClient.addOrUpdateAllAmazonFbaInventory(allamazoninventory);
|
226 |
new InventoryClient().getClient().addOrUpdateAllAmazonFbaInventory(allamazoninventory);
|
| 207 |
} catch (IOException e) {
|
227 |
} catch (IOException e) {
|
| 208 |
// TODO Auto-generated catch block
|
228 |
// TODO Auto-generated catch block
|
| 209 |
e.printStackTrace();
|
229 |
e.printStackTrace();
|
| 210 |
} catch (TException e) {
|
230 |
} catch (TException e) {
|
| 211 |
// TODO Auto-generated catch block
|
231 |
// TODO Auto-generated catch block
|