| 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.InventoryClient;
|
5 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 6 |
|
- |
|
| - |
|
6 |
import java.io.BufferedReader;
|
| - |
|
7 |
import java.io.FileReader;
|
| 7 |
import java.io.FileNotFoundException;
|
8 |
import java.io.FileNotFoundException;
|
| 8 |
import java.io.FileOutputStream;
|
9 |
import java.io.FileOutputStream;
|
| 9 |
import java.io.FileReader;
|
10 |
import java.io.FileReader;
|
| 10 |
import java.io.IOException;
|
11 |
import java.io.IOException;
|
| 11 |
import java.io.OutputStream;
|
12 |
import java.io.OutputStream;
|
| Line 108... |
Line 109... |
| 108 |
* Marketplace Web Service calls.
|
109 |
* Marketplace Web Service calls.
|
| 109 |
***********************************************************************/
|
110 |
***********************************************************************/
|
| 110 |
// marketplaces from which data should be included in the report; look at the
|
111 |
// marketplaces from which data should be included in the report; look at the
|
| 111 |
// API reference document on the MWS website to see which marketplaces are
|
112 |
// API reference document on the MWS website to see which marketplaces are
|
| 112 |
// included if you do not specify the list yourself
|
113 |
// included if you do not specify the list yourself
|
| 113 |
final IdList marketplaces = new IdList(Arrays.asList(
|
- |
|
| 114 |
"A21TJRUUN4KGV"));
|
- |
|
| 115 |
RequestReportRequest request = new RequestReportRequest()
|
- |
|
| 116 |
.withMerchant(merchantId)
|
- |
|
| 117 |
.withMarketplaceIdList(marketplaces)
|
- |
|
| 118 |
.withReportType("_GET_AFN_INVENTORY_DATA_")
|
- |
|
| 119 |
.withReportOptions("ShowSalesChannel=true");
|
- |
|
| 120 |
|
- |
|
| 121 |
// demonstrates how to set the date range
|
- |
|
| 122 |
DatatypeFactory df = null;
|
114 |
/*CSVReader reader = null;
|
| 123 |
try {
|
115 |
try {
|
| - |
|
116 |
//reader = new CSVReader(new FileReader("/home/vikram/Desktop/amazoninventoryreport.txt"),'\t');
|
| 124 |
df = DatatypeFactory.newInstance();
|
117 |
reader = new CSVReader(new FileReader("/home/amazoninventoryreport.csv"),'\t');
|
| 125 |
} catch (DatatypeConfigurationException e) {
|
118 |
} catch (FileNotFoundException e) {
|
| - |
|
119 |
// TODO Auto-generated catch block
|
| 126 |
e.printStackTrace();
|
120 |
e.printStackTrace();
|
| - |
|
121 |
}*/
|
| - |
|
122 |
BufferedReader reader = null;
|
| - |
|
123 |
try {
|
| - |
|
124 |
reader = new BufferedReader(new FileReader("/home/amazoninventoryreport.csv"));
|
| 127 |
throw new RuntimeException(e);
|
125 |
} catch (FileNotFoundException e1) {
|
| - |
|
126 |
// TODO Auto-generated catch block
|
| - |
|
127 |
e1.printStackTrace();
|
| 128 |
}
|
128 |
}
|
| 129 |
//System.out.println("Report ready please check");
|
- |
|
| 130 |
CSVReader reader = null;
|
129 |
String[] nextLine = null;
|
| 131 |
try {
|
- |
|
| 132 |
//reader = new CSVReader(new FileReader("/home/vikram/Desktop/amazoninventoryreport.txt"),'\t');
|
- |
|
| 133 |
reader = new CSVReader(new FileReader("/home/amazoninventoryreport.csv"),'\t');
|
- |
|
| 134 |
} catch (FileNotFoundException e) {
|
- |
|
| 135 |
// TODO Auto-generated catch block
|
- |
|
| 136 |
e.printStackTrace();
|
- |
|
| 137 |
}
|
- |
|
| 138 |
String [] nextLine;
|
130 |
String Line;
|
| 139 |
//CatalogClient catalogServiceClient = null;
|
- |
|
| 140 |
InventoryClient inventoryServiceClient = null;
|
- |
|
| 141 |
try {
|
- |
|
| 142 |
inventoryServiceClient = new InventoryClient();
|
- |
|
| 143 |
//catalogServiceClient = new CatalogClient();
|
- |
|
| 144 |
//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
- |
|
| 145 |
} catch (Exception e) {
|
- |
|
| 146 |
// TODO Auto-generated catch block
|
- |
|
| 147 |
e.printStackTrace();
|
- |
|
| 148 |
}
|
- |
|
| 149 |
//in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
- |
|
| 150 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
- |
|
| 151 |
List<AmazonFbaInventorySnapshot> allamazoninventory = new ArrayList<AmazonFbaInventorySnapshot>();
|
131 |
List<AmazonFbaInventorySnapshot> allamazoninventory = new ArrayList<AmazonFbaInventorySnapshot>();
|
| 152 |
try {
|
132 |
try {
|
| 153 |
while ((nextLine = reader.readNext()) != null) {
|
133 |
while ((Line = reader.readLine()) != null) {
|
| 154 |
// nextLine[] is an array of values from the line
|
134 |
nextLine = Line.split("\t");
|
| 155 |
//System.out.println(nextLine[0] +" "+ nextLine[1]+" " + nextLine[2]+" " + nextLine[3] +" "+ nextLine[4] +" " + nextLine[5]);
|
135 |
System.out.println("SKU " + nextLine[0] + " "+ nextLine[10] +" "+nextLine[11]+" "+nextLine[12]+" "+nextLine[16]);
|
| 156 |
if(nextLine[0].startsWith("FBA") && nextLine[4].equalsIgnoreCase("SELLABLE") ){
|
136 |
if(nextLine[0].startsWith("FBA")){
|
| 157 |
//System.out.println("Item ID" + nextLine[0].replaceAll("FBA","") + "---"+"Inventory" + nextLine[5]);
|
137 |
AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
|
| 158 |
//if(catalogClient.getAmazonItemDetails(Long.parseLong(nextLine[0].replaceAll("FBA",""))).getItemid()!=0){
|
138 |
if(!nextLine[10].isEmpty())
|
| 159 |
AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
|
139 |
amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[10]));
|
| - |
|
140 |
else{
|
| 160 |
amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[5]));
|
141 |
amazonfbainventorysnapshot.setAvailability(0);
|
| - |
|
142 |
}
|
| 161 |
amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));
|
143 |
amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));
|
| 162 |
allamazoninventory.add(amazonfbainventorysnapshot);
|
144 |
amazonfbainventorysnapshot.setLocation(AmazonFCWarehouseLocation.Mumbai);
|
| - |
|
145 |
if(nextLine[12].length()>0){
|
| 163 |
System.out.println("Adding item in list " + Long.parseLong(nextLine[0].replaceAll("FBA","")));
|
146 |
amazonfbainventorysnapshot.setReserved(Long.parseLong(nextLine[12]));
|
| 164 |
|
- |
|
| 165 |
// }
|
147 |
}
|
| 166 |
}
|
148 |
else{
|
| - |
|
149 |
amazonfbainventorysnapshot.setReserved(0);
|
| 167 |
}
|
150 |
}
|
| 168 |
inventoryClient.addOrUpdateAllAmazonFbaInventory(allamazoninventory);
|
- |
|
| 169 |
} catch (IOException e) {
|
151 |
if(nextLine[11].length()>0){
|
| 170 |
// TODO Auto-generated catch block
|
- |
|
| 171 |
e.printStackTrace();
|
- |
|
| 172 |
} catch (TException e) {
|
- |
|
| 173 |
// TODO Auto-generated catch block
|
152 |
amazonfbainventorysnapshot.setUnfulfillable(Long.parseLong(nextLine[11]));
|
| 174 |
e.printStackTrace();
|
- |
|
| 175 |
}
|
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);
|
| - |
|
164 |
|
| - |
|
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 |
}
|
| 176 |
}
|
185 |
}
|
| 177 |
}
|
186 |
}
|