Subversion Repositories SmartDukaan

Rev

Rev 8260 | Rev 8269 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8224 manish.sha 1
package com.amazonaws.mws.samples;
2
 
3
import in.shop2020.thrift.clients.HelperClient;
4
import in.shop2020.thrift.clients.TransactionClient;
5
 
6
import java.io.FileNotFoundException;
7
import java.io.FileOutputStream;
8
import java.io.FileReader;
9
import java.io.IOException;
10
import java.io.OutputStream;
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.Calendar;
14
import java.util.GregorianCalendar;
15
import java.util.List;
16
import java.util.Map;
17
 
18
import javax.xml.datatype.DatatypeConfigurationException;
19
import javax.xml.datatype.DatatypeFactory;
20
import javax.xml.datatype.XMLGregorianCalendar;
21
 
22
 
23
import org.apache.log4j.Logger;
24
 
25
import au.com.bytecode.opencsv.CSVReader;
26
 
27
import com.amazonaws.mws.MarketplaceWebService;
28
import com.amazonaws.mws.MarketplaceWebServiceClient;
29
import com.amazonaws.mws.MarketplaceWebServiceConfig;
30
import com.amazonaws.mws.model.GetReportListRequest;
31
import com.amazonaws.mws.model.GetReportRequest;
32
import com.amazonaws.mws.model.IdList;
33
import com.amazonaws.mws.model.RequestReportRequest;
34
import com.amazonaws.mws.samples.GetReportSample;
35
 
36
public class FeedbackRequestEmailSender {
37
 
38
	protected static Logger log = Logger.getLogger(FeedbackRequestEmailSender.class);
39
	public static void main(String... args){
40
		/************************************************************************
41
		 * Access Key ID and Secret Access Key ID, obtained from:
42
		 * http://aws.amazon.com
43
		 ***********************************************************************/
8267 manish.sha 44
		/*final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
8224 manish.sha 45
		final String secretAccessKey = "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";
46
 
47
		final String appName = "Test";
48
		final String appVersion = "1.0";
49
		final String merchantId = "AF6E3O0VE0X4D";
50
 
51
		MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
52
 
8267 manish.sha 53
		*//************************************************************************
8224 manish.sha 54
		 * Uncomment to set the appropriate MWS endpoint.
8267 manish.sha 55
		 ************************************************************************//*
8224 manish.sha 56
		// US
57
		// config.setServiceURL("https://mws.amazonservices.com");
58
		// UK
59
		// config.setServiceURL("https://mws.amazonservices.co.uk");
60
		// Germany
61
		// config.setServiceURL("https://mws.amazonservices.de");
62
		// France
63
		// config.setServiceURL("https://mws.amazonservices.fr");
64
		// Italy
65
		// config.setServiceURL("https://mws.amazonservices.it");
66
		// Japan
67
		// config.setServiceURL("https://mws.amazonservices.jp");
68
		// China
69
		// config.setServiceURL("https://mws.amazonservices.com.cn");
70
		// Canada
71
		// config.setServiceURL("https://mws.amazonservices.ca");
72
		// India
73
		config.setServiceURL("https://mws.amazonservices.in");
74
 
8267 manish.sha 75
		*//************************************************************************
8224 manish.sha 76
		 * You can also try advanced configuration options. Available options are:
77
		 *
78
		 *  - Signature Version
79
		 *  - Proxy Host and Proxy Port
80
		 *  - User Agent String to be sent to Marketplace Web Service
81
		 *
8267 manish.sha 82
		 ***********************************************************************//*
8224 manish.sha 83
 
8267 manish.sha 84
		*//************************************************************************
8224 manish.sha 85
		 * Instantiate Http Client Implementation of Marketplace Web Service        
8267 manish.sha 86
		 ***********************************************************************//*
8224 manish.sha 87
 
88
		MarketplaceWebService service = new MarketplaceWebServiceClient(
89
				accessKeyId, secretAccessKey, appName, appVersion, config);
90
 
8267 manish.sha 91
		*//************************************************************************
8224 manish.sha 92
		 * Uncomment to try out Mock Service that simulates Marketplace Web Service 
93
		 * responses without calling Marketplace Web Service  service.
94
		 *
95
		 * Responses are loaded from local XML files. You can tweak XML files to
96
		 * experiment with various outputs during development
97
		 *
98
		 * XML files available under com/amazonaws/mws/mock tree
99
		 *
8267 manish.sha 100
		 ***********************************************************************//*
8224 manish.sha 101
		// MarketplaceWebService service = new MarketplaceWebServiceMock();
102
 
8267 manish.sha 103
		*//************************************************************************
8224 manish.sha 104
		 * Setup request parameters and uncomment invoke to try out 
105
		 * sample for Request Report 
8267 manish.sha 106
		 ***********************************************************************//*
8224 manish.sha 107
 
8267 manish.sha 108
		*//************************************************************************
8224 manish.sha 109
		 * Marketplace and Merchant IDs are required parameters for all 
110
		 * Marketplace Web Service calls.
8267 manish.sha 111
		 ***********************************************************************//*
8224 manish.sha 112
		// marketplaces from which data should be included in the report; look at the
113
		// API reference document on the MWS website to see which marketplaces are
114
		// included if you do not specify the list yourself
115
		final IdList marketplaces = new IdList(Arrays.asList(
116
		"A21TJRUUN4KGV"));        
117
		RequestReportRequest fullfilledShipmentReportRequest = new RequestReportRequest()
118
		.withMerchant(merchantId)
119
		.withMarketplaceIdList(marketplaces)
120
		.withReportType("_GET_AMAZON_FULFILLED_SHIPMENTS_DATA_")
121
		.withReportOptions("ShowSalesChannel=true");
122
 
123
		RequestReportRequest returnsReportRequest = new RequestReportRequest()
124
		.withMerchant(merchantId)
125
		.withMarketplaceIdList(marketplaces)
126
		.withReportType("_GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA_")
127
		.withReportOptions("ShowSalesChannel=true");
128
 
129
		// demonstrates how to set the date range
130
		DatatypeFactory df = null;
131
		try {
132
			df = DatatypeFactory.newInstance();
133
		} catch (DatatypeConfigurationException e) {
134
			e.printStackTrace();
135
			throw new RuntimeException(e);
136
		}
137
		Calendar start_Date= new GregorianCalendar();
138
 
139
		XMLGregorianCalendar endDate2 = df.newXMLGregorianCalendar(new GregorianCalendar(start_Date.get(Calendar.YEAR),start_Date.get(Calendar.MONTH),start_Date.get(Calendar.DAY_OF_MONTH)));
140
 
141
		start_Date.add(Calendar.DAY_OF_MONTH, -21);
142
 
143
		XMLGregorianCalendar startDate = df.newXMLGregorianCalendar(new GregorianCalendar(start_Date.get(Calendar.YEAR),start_Date.get(Calendar.MONTH),start_Date.get(Calendar.DAY_OF_MONTH)));
144
		start_Date.add(Calendar.DAY_OF_MONTH, 1);
145
 
146
		XMLGregorianCalendar endDate1 = df.newXMLGregorianCalendar(new GregorianCalendar(start_Date.get(Calendar.YEAR),start_Date.get(Calendar.MONTH),start_Date.get(Calendar.DAY_OF_MONTH)));
147
 
148
		fullfilledShipmentReportRequest.setStartDate(startDate);
149
		fullfilledShipmentReportRequest.setEndDate(endDate1);
150
 
151
		// @TODO: set additional request parameters here
152
		Map<String,String> requestIdShipmentReportIdmap;
153
 
154
		returnsReportRequest.setStartDate(startDate);
155
		returnsReportRequest.setEndDate(endDate2);
156
 
157
		Map<String,String> requestIdReturnsReportIdmap;
158
 
8267 manish.sha 159
		List<String> fbaCustomersEmails  = new ArrayList<String>();*/
8224 manish.sha 160
		///Request report
161
 
162
		String emailBody= "Dear Customer, <br><br>" +
163
		"Thank you very much for shopping with Saholic at Amazon.in .<br><br>"+
164
		"We hope that you are happy with your purchase and if you are, please spare some time to leave positive feedback for us.<br><br>" +
165
		"Kindly follow below mentioned steps:-<br><br>" +
166
		"1. Login into your Amazon account<br>" +
167
		"2. Go to Your Order Section<br>" +
168
		"3. Click on Seller Feedback<br><br>" +
169
		"Your comments and feedback help us improve our products and services for other customers.<br><br>" +
170
		"Please do not leave any negative feedback. If you have any problems or concerns about your recent purchase, please get in touch with our customer service as soon as possible and we will do everything we can to help.<br><br>" +
171
		"Yours Sincerely,<br>" +
172
		"Saholic Team<br>";
173
 
174
		String emailIdFrom= "help@saholic.com";
8267 manish.sha 175
 
176
		/*
8224 manish.sha 177
		String shipmentReportRequestId = RequestReportSample.invokeRequestReport(service, fullfilledShipmentReportRequest);
178
		String returnsReportRequestId = RequestReportSample.invokeRequestReport(service, returnsReportRequest);
179
		while(true){
180
			GetReportListRequest requestShipmentReportList = new GetReportListRequest();
181
			requestShipmentReportList.setMerchant( merchantId );
182
 
183
			GetReportListRequest requestReturnsReportList = new GetReportListRequest();
184
			requestReturnsReportList.setMerchant( merchantId );
185
 
186
			final IdList shipmentReportRequestIdList = new IdList(Arrays.asList(shipmentReportRequestId));        
187
			requestShipmentReportList.setReportRequestIdList(shipmentReportRequestIdList);
188
			///Request report status
189
			requestIdShipmentReportIdmap = GetReportListSample.invokeGetReportList(service, requestShipmentReportList);
190
 
191
			final IdList returnsReportRequestIdList = new IdList(Arrays.asList(returnsReportRequestId));        
192
			requestReturnsReportList.setReportRequestIdList(returnsReportRequestIdList);
193
 
194
			requestIdReturnsReportIdmap= GetReportListSample.invokeGetReportList(service, requestReturnsReportList);
195
 
196
			GetReportRequest requestShipmentReport = new GetReportRequest();
197
			requestShipmentReport.setMerchant( merchantId );
198
 
199
			GetReportRequest requestReturnsReport = new GetReportRequest();
200
			requestReturnsReport.setMerchant( merchantId );
201
 
202
 
203
			///Fetch report only if it is ready
204
			if(requestIdShipmentReportIdmap.get(shipmentReportRequestId)!=null && requestIdReturnsReportIdmap.get(returnsReportRequestId)!=null){
205
				requestShipmentReport.setReportId( requestIdShipmentReportIdmap.get(shipmentReportRequestId) );
206
				OutputStream shipmentReport=null;
207
				try {
208
					shipmentReport = new FileOutputStream( "/tmp/AmazonFullFilledShipmentReport.txt" );
209
				} catch (FileNotFoundException e) {
210
					log.error("Error Getting Shipment Report :- ", e);
211
				}
212
				requestShipmentReport.setReportOutputStream( shipmentReport );
213
				GetReportSample.invokeGetReport(service, requestShipmentReport);
214
 
8267 manish.sha 215
				System.out.println("Shipment Report ready please check\n");
8224 manish.sha 216
				CSVReader shipmentReportReader = null; 
217
				try {
218
					shipmentReportReader = new CSVReader(new FileReader("/tmp/AmazonFullFilledShipmentReport.txt"),'\t');
219
				} catch (FileNotFoundException e) {
220
					log.error("Error Reading Shipment Report :- ", e);
221
				}
222
 
223
				requestReturnsReport.setReportId( requestIdReturnsReportIdmap.get(returnsReportRequestId) );
224
				OutputStream returnsReport=null;
225
				try {
226
					returnsReport = new FileOutputStream( "/tmp/AmazonReturnsReport.txt" );
227
				} catch (FileNotFoundException e) {
228
					log.error("Error Getting Returns Report :- ", e);
229
				}
230
				requestReturnsReport.setReportOutputStream( returnsReport );
231
				GetReportSample.invokeGetReport(service, requestReturnsReport);
232
 
8267 manish.sha 233
				System.out.println("Return Report ready please check\n");
8224 manish.sha 234
				CSVReader returnsReportReader = null; 
235
				try {
236
					returnsReportReader = new CSVReader(new FileReader("/tmp/AmazonReturnsReport.txt"),'\t');
237
				} catch (FileNotFoundException e) {
238
					log.error("Error Reading Returns Report :- ", e);
239
				}
240
 
241
 
242
				String [] shipmentReportData;
243
				String [] returnsReportData;
244
 
245
				boolean matchFoundInReturns= false;
246
 
247
				try {
248
					while ((shipmentReportData = shipmentReportReader.readNext()) != null) {
249
						if(!shipmentReportData[0].equalsIgnoreCase("amazon-order-id")){
250
							returnReportWhile:while((returnsReportData = returnsReportReader.readNext()) != null){
251
								if(!returnsReportData[1].equalsIgnoreCase("amazon-order-id")){
252
									if(shipmentReportData[0].equalsIgnoreCase(returnsReportData[1])){
253
										matchFoundInReturns= true;
254
										break returnReportWhile;
255
									}
256
									else{
257
										XMLGregorianCalendar shipmentDate= df.newXMLGregorianCalendar(shipmentReportData[8].substring(0, shipmentReportData[8].indexOf("T")));
258
										XMLGregorianCalendar estimatedDate= df.newXMLGregorianCalendar(shipmentReportData[44].substring(0, shipmentReportData[44].indexOf("T")));
259
										if(shipmentDate.compare(estimatedDate)==-1)
260
											matchFoundInReturns= false;
261
									}
262
								}
263
							}
264
 
265
						if(!matchFoundInReturns){
266
							fbaCustomersEmails.add(shipmentReportData[10]);
267
						}
268
						}
269
 
270
					}
271
				} catch (IOException e) {
272
					log.error("Error Reading IO operations :- ", e);
273
				} 
274
 
275
				break;
276
			}
277
			else{ 
278
				log.info("Report not ready\n");
279
				try {
280
					Thread.sleep(5*60*1000);
281
				} catch (InterruptedException e) {
282
					log.error("Error During getting Response :- ", e);
283
				}
284
			}
8267 manish.sha 285
		}*/
8224 manish.sha 286
 
8260 manish.sha 287
		HelperClient helperServiceClient;
8224 manish.sha 288
		try {
8260 manish.sha 289
			helperServiceClient = new HelperClient();
290
			in.shop2020.utils.HelperService.Client client = helperServiceClient.getClient();
8267 manish.sha 291
			System.out.print("Email Id List: \n");
292
			//for(int i=0; i<fbaCustomersEmails.size();i++){
293
				//System.out.print(fbaCustomersEmails.get(i)+"\n");
294
				client.saveUserEmailForSending(Arrays.asList(new String[] {"manish.sharma@shop2020.in"}), emailIdFrom, "Feedback Request", emailBody, "AmazonMFN", "AmazonFeedback", Arrays.asList(new String[] {" "}), Arrays.asList(new String[] {"manish.sharma@shop2020.in"}), 1);
295
			//}
8224 manish.sha 296
		} catch (Exception e) {
297
			log.error("Error Getting Helper Client :- ", e);
298
		}
299
 
300
 
301
 
302
		// Note that depending on the type of report being downloaded, a report can reach 
303
		// sizes greater than 1GB. For this reason we recommend that you _always_ program to
304
		// MWS in a streaming fashion. Otherwise, as your business grows you may silently reach
305
		// the in-memory size limit and have to re-work your solution.
306
		//
307
 
308
 
309
	}
310
 
311
}