Subversion Repositories SmartDukaan

Rev

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

Rev 8472 Rev 8532
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.AmazonFbaInventorySnapshot;
3
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
-
 
4
import in.shop2020.thrift.clients.CatalogClient;
4
import in.shop2020.thrift.clients.InventoryClient;
5
import in.shop2020.thrift.clients.InventoryClient;
5
 
6
 
6
import java.io.FileNotFoundException;
7
import java.io.FileNotFoundException;
7
import java.io.FileOutputStream;
8
import java.io.FileOutputStream;
8
import java.io.FileReader;
9
import java.io.FileReader;
Line 32... Line 33...
32
import com.amazonaws.mws.model.RequestReportRequest;
33
import com.amazonaws.mws.model.RequestReportRequest;
33
 
34
 
34
public class FetchAmazonInventory {
35
public class FetchAmazonInventory {
35
	public static void main(String... args){
36
	public static void main(String... args){
36
		/************************************************************************
37
		/************************************************************************
37
         * Access Key ID and Secret Access Key ID, obtained from:
38
		 * Access Key ID and Secret Access Key ID, obtained from:
38
         * http://aws.amazon.com
39
		 * http://aws.amazon.com
39
         ***********************************************************************/
40
		 ***********************************************************************/
40
		final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
41
		final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
41
		final String secretAccessKey = "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";
42
		final String secretAccessKey = "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg";
42
 
43
 
43
		final String appName = "Test";
44
		final String appName = "Test";
44
		final String appVersion = "1.0";
45
		final String appVersion = "1.0";
45
		final String merchantId = "AF6E3O0VE0X4D";
46
		final String merchantId = "AF6E3O0VE0X4D";
46
 
47
 
47
        MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
48
		MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
48
 
49
 
49
        /************************************************************************
50
		/************************************************************************
50
         * Uncomment to set the appropriate MWS endpoint.
51
		 * Uncomment to set the appropriate MWS endpoint.
51
         ************************************************************************/
52
		 ************************************************************************/
52
        // US
53
		// US
53
        // config.setServiceURL("https://mws.amazonservices.com");
54
		// config.setServiceURL("https://mws.amazonservices.com");
54
        // UK
55
		// UK
55
        // config.setServiceURL("https://mws.amazonservices.co.uk");
56
		// config.setServiceURL("https://mws.amazonservices.co.uk");
56
        // Germany
57
		// Germany
57
        // config.setServiceURL("https://mws.amazonservices.de");
58
		// config.setServiceURL("https://mws.amazonservices.de");
58
        // France
59
		// France
59
        // config.setServiceURL("https://mws.amazonservices.fr");
60
		// config.setServiceURL("https://mws.amazonservices.fr");
60
        // Italy
61
		// Italy
61
        // config.setServiceURL("https://mws.amazonservices.it");
62
		// config.setServiceURL("https://mws.amazonservices.it");
62
        // Japan
63
		// Japan
63
        // config.setServiceURL("https://mws.amazonservices.jp");
64
		// config.setServiceURL("https://mws.amazonservices.jp");
64
        // China
65
		// China
65
        // config.setServiceURL("https://mws.amazonservices.com.cn");
66
		// config.setServiceURL("https://mws.amazonservices.com.cn");
66
        // Canada
67
		// Canada
67
        // config.setServiceURL("https://mws.amazonservices.ca");
68
		// config.setServiceURL("https://mws.amazonservices.ca");
68
        // India
69
		// India
69
           config.setServiceURL("https://mws.amazonservices.in");
70
		config.setServiceURL("https://mws.amazonservices.in");
70
 
71
 
71
        /************************************************************************
72
		/************************************************************************
72
         * You can also try advanced configuration options. Available options are:
73
		 * You can also try advanced configuration options. Available options are:
73
         *
74
		 *
74
         *  - Signature Version
75
		 *  - Signature Version
75
         *  - Proxy Host and Proxy Port
76
		 *  - Proxy Host and Proxy Port
76
         *  - User Agent String to be sent to Marketplace Web Service
77
		 *  - User Agent String to be sent to Marketplace Web Service
77
         *
78
		 *
78
         ***********************************************************************/
79
		 ***********************************************************************/
79
 
80
 
80
        /************************************************************************
81
		/************************************************************************
81
         * Instantiate Http Client Implementation of Marketplace Web Service        
82
		 * Instantiate Http Client Implementation of Marketplace Web Service        
82
         ***********************************************************************/
83
		 ***********************************************************************/
83
        
84
 
84
        MarketplaceWebService service = new MarketplaceWebServiceClient(
85
		MarketplaceWebService service = new MarketplaceWebServiceClient(
85
                    accessKeyId, secretAccessKey, appName, appVersion, config);
86
				accessKeyId, secretAccessKey, appName, appVersion, config);
86
 
87
 
87
        /************************************************************************
88
		/************************************************************************
88
         * Uncomment to try out Mock Service that simulates Marketplace Web Service 
89
		 * Uncomment to try out Mock Service that simulates Marketplace Web Service 
89
         * responses without calling Marketplace Web Service  service.
90
		 * responses without calling Marketplace Web Service  service.
90
         *
91
		 *
91
         * Responses are loaded from local XML files. You can tweak XML files to
92
		 * Responses are loaded from local XML files. You can tweak XML files to
92
         * experiment with various outputs during development
93
		 * experiment with various outputs during development
93
         *
94
		 *
94
         * XML files available under com/amazonaws/mws/mock tree
95
		 * XML files available under com/amazonaws/mws/mock tree
95
         *
96
		 *
96
         ***********************************************************************/
97
		 ***********************************************************************/
97
        // MarketplaceWebService service = new MarketplaceWebServiceMock();
98
		// MarketplaceWebService service = new MarketplaceWebServiceMock();
98
 
99
 
99
        /************************************************************************
100
		/************************************************************************
100
         * Setup request parameters and uncomment invoke to try out 
101
		 * Setup request parameters and uncomment invoke to try out 
101
         * sample for Request Report 
102
		 * sample for Request Report 
102
         ***********************************************************************/
103
		 ***********************************************************************/
103
 
104
 
104
        /************************************************************************
105
		/************************************************************************
105
         * Marketplace and Merchant IDs are required parameters for all 
106
		 * Marketplace and Merchant IDs are required parameters for all 
106
         * Marketplace Web Service calls.
107
		 * Marketplace Web Service calls.
107
         ***********************************************************************/
108
		 ***********************************************************************/
108
        // marketplaces from which data should be included in the report; look at the
109
		// marketplaces from which data should be included in the report; look at the
109
        // API reference document on the MWS website to see which marketplaces are
110
		// API reference document on the MWS website to see which marketplaces are
110
        // included if you do not specify the list yourself
111
		// included if you do not specify the list yourself
111
    	final IdList marketplaces = new IdList(Arrays.asList(
112
		final IdList marketplaces = new IdList(Arrays.asList(
112
		"A21TJRUUN4KGV"));        
113
		"A21TJRUUN4KGV"));        
113
        RequestReportRequest request = new RequestReportRequest()
114
		RequestReportRequest request = new RequestReportRequest()
114
		        .withMerchant(merchantId)
115
		.withMerchant(merchantId)
115
		        .withMarketplaceIdList(marketplaces)
116
		.withMarketplaceIdList(marketplaces)
116
		        .withReportType("_GET_AFN_INVENTORY_DATA_")
117
		.withReportType("_GET_AFN_INVENTORY_DATA_")
117
		        .withReportOptions("ShowSalesChannel=true");
118
		.withReportOptions("ShowSalesChannel=true");
118
 
119
 
119
        // demonstrates how to set the date range
120
		// demonstrates how to set the date range
120
		DatatypeFactory df = null;
121
		DatatypeFactory df = null;
121
		try {
122
		try {
122
			df = DatatypeFactory.newInstance();
123
			df = DatatypeFactory.newInstance();
123
		} catch (DatatypeConfigurationException e) {
124
		} catch (DatatypeConfigurationException e) {
124
			e.printStackTrace();
125
			e.printStackTrace();
Line 126... Line 127...
126
		}
127
		}
127
		//XMLGregorianCalendar startDate = df.newXMLGregorianCalendar(new GregorianCalendar());
128
		//XMLGregorianCalendar startDate = df.newXMLGregorianCalendar(new GregorianCalendar());
128
		//XMLGregorianCalendar endDate = df.newXMLGregorianCalendar(new GregorianCalendar());
129
		//XMLGregorianCalendar endDate = df.newXMLGregorianCalendar(new GregorianCalendar());
129
		//request.setStartDate(startDate);
130
		//request.setStartDate(startDate);
130
		//request.setEndDate(endDate);
131
		//request.setEndDate(endDate);
131
	    // @TODO: set additional request parameters here
132
		// @TODO: set additional request parameters here
132
		Map<String,String> requestIdreportIdmap;
133
		Map<String,String> requestIdreportIdmap;
133
		///Request report
134
		///Request report
134
		while(true){
135
		while(true){
135
			String requestId = null;
136
			String requestId = null;
136
			try {
137
			try {
Line 171... Line 172...
171
					} catch (FileNotFoundException e) {
172
					} catch (FileNotFoundException e) {
172
						// TODO Auto-generated catch block
173
						// TODO Auto-generated catch block
173
						e.printStackTrace();
174
						e.printStackTrace();
174
					}
175
					}
175
					String [] nextLine;
176
					String [] nextLine;
-
 
177
					CatalogClient catalogServiceClient = null;
176
					InventoryClient inventoryServiceClient = null;
178
					InventoryClient inventoryServiceClient = null;
177
					try {
179
					try {
178
						inventoryServiceClient = new InventoryClient();
180
						inventoryServiceClient = new InventoryClient();
-
 
181
						//catalogServiceClient = new CatalogClient();
-
 
182
						catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
179
					} catch (Exception e) {
183
					} catch (Exception e) {
180
						// TODO Auto-generated catch block
184
						// TODO Auto-generated catch block
181
						e.printStackTrace();
185
						e.printStackTrace();
-
 
186
					}	
-
 
187
					in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
182
					}in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
188
					in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
183
					try {
189
					try {
184
						while ((nextLine = reader.readNext()) != null) {
190
						while ((nextLine = reader.readNext()) != null) {
185
							// nextLine[] is an array of values from the line
191
							// nextLine[] is an array of values from the line
186
							//System.out.println(nextLine[0] +" "+ nextLine[1]+" " + nextLine[2]+" " + nextLine[3] +" "+ nextLine[4] +" " + nextLine[5]);
192
							//System.out.println(nextLine[0] +" "+ nextLine[1]+" " + nextLine[2]+" " + nextLine[3] +" "+ nextLine[4] +" " + nextLine[5]);
187
							if(nextLine[0].startsWith("FBA") && nextLine[4].equalsIgnoreCase("SELLABLE") ){
193
							if(nextLine[0].startsWith("FBA") && nextLine[4].equalsIgnoreCase("SELLABLE") ){
188
								//System.out.println("Item ID" + nextLine[0].replaceAll("FBA","") + "---"+"Inventory" + nextLine[5]);
194
								//System.out.println("Item ID" + nextLine[0].replaceAll("FBA","") + "---"+"Inventory" + nextLine[5]);
-
 
195
								if(catalogClient.getAmazonItemDetails(Long.parseLong(nextLine[0].replaceAll("FBA",""))).getItemid()!=0){
189
								AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
196
									AmazonFbaInventorySnapshot amazonfbainventorysnapshot = new AmazonFbaInventorySnapshot() ;
190
								amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[5]));
197
									amazonfbainventorysnapshot.setAvailability(Long.parseLong(nextLine[5]));
191
								amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));
198
									amazonfbainventorysnapshot.setItem_id(Long.parseLong(nextLine[0].replaceAll("FBA","")));
192
								inventoryClient.addOrUpdateAmazonFbaInventory(amazonfbainventorysnapshot);
199
									inventoryClient.addOrUpdateAmazonFbaInventory(amazonfbainventorysnapshot);
193
 
200
								}
194
							}
201
							}
195
						}
202
						}
196
					} catch (IOException e) {
203
					} catch (IOException e) {
197
						// TODO Auto-generated catch block
204
						// TODO Auto-generated catch block
198
						e.printStackTrace();
205
						e.printStackTrace();
Line 218... Line 225...
218
				// TODO Auto-generated catch block
225
				// TODO Auto-generated catch block
219
				e.printStackTrace();
226
				e.printStackTrace();
220
			}
227
			}
221
		}
228
		}
222
 
229
 
223
        // Note that depending on the type of report being downloaded, a report can reach 
230
		// Note that depending on the type of report being downloaded, a report can reach 
224
        // sizes greater than 1GB. For this reason we recommend that you _always_ program to
231
		// sizes greater than 1GB. For this reason we recommend that you _always_ program to
225
        // MWS in a streaming fashion. Otherwise, as your business grows you may silently reach
232
		// MWS in a streaming fashion. Otherwise, as your business grows you may silently reach
226
        // the in-memory size limit and have to re-work your solution.
233
		// the in-memory size limit and have to re-work your solution.
227
        //
234
		//
228
       
235
 
229
 
236
 
230
	}
237
	}
231
 
238
 
232
}
239
}