| 12662 |
kshitij.so |
1 |
package in.shop2020.support.utils;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.AmazonPromotion;
|
|
|
4 |
|
|
|
5 |
import java.io.BufferedReader;
|
|
|
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.Calendar;
|
|
|
13 |
import java.util.GregorianCalendar;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
|
|
|
16 |
import com.amazonaws.mws.*;
|
|
|
17 |
import com.amazonaws.mws.model.GetFeedSubmissionResultRequest;
|
|
|
18 |
import com.amazonaws.mws.model.GetFeedSubmissionResultResponse;
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
public class CheckPromoFeedSubmission{
|
|
|
22 |
|
|
|
23 |
public boolean ProcessFeed(String feedSubmissionId) throws NumberFormatException, IOException{
|
|
|
24 |
String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
|
|
|
25 |
String secretAccessKey = "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg";
|
|
|
26 |
String appName = "Test";
|
|
|
27 |
String appVersion = "1.0";
|
|
|
28 |
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
|
|
|
29 |
config.setServiceURL("https://mws.amazonservices.in");
|
|
|
30 |
MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, appName, appVersion, config);
|
|
|
31 |
GetFeedSubmissionResultRequest request = new GetFeedSubmissionResultRequest();
|
|
|
32 |
request.setMerchant("AF6E3O0VE0X4D");
|
|
|
33 |
request.setFeedSubmissionId(feedSubmissionId);
|
|
|
34 |
OutputStream processingResult = null;
|
|
|
35 |
String fileName = "";
|
|
|
36 |
try
|
|
|
37 |
{
|
|
|
38 |
fileName = "/home/amazon/feedSubmissionPromotion"+getTimeInMilliseconds()+"Result.xml";
|
|
|
39 |
processingResult = new FileOutputStream(fileName);
|
|
|
40 |
}
|
|
|
41 |
catch(FileNotFoundException e)
|
|
|
42 |
{
|
|
|
43 |
e.printStackTrace();
|
|
|
44 |
}
|
|
|
45 |
request.setFeedSubmissionResultOutputStream(processingResult);
|
|
|
46 |
try {
|
|
|
47 |
GetFeedSubmissionResultResponse response = service.getFeedSubmissionResult(request);
|
|
|
48 |
} catch (MarketplaceWebServiceException e) {
|
|
|
49 |
e.printStackTrace();
|
|
|
50 |
return false;
|
|
|
51 |
}
|
|
|
52 |
BufferedReader reader = null;
|
|
|
53 |
try {
|
|
|
54 |
reader = new BufferedReader(new FileReader(fileName));
|
|
|
55 |
} catch (FileNotFoundException e1) {
|
|
|
56 |
// TODO Auto-generated catch block
|
|
|
57 |
e1.printStackTrace();
|
|
|
58 |
}
|
|
|
59 |
String str="";
|
|
|
60 |
int lineNumber = 0;
|
|
|
61 |
int numberOfRecords = 0;
|
|
|
62 |
int numberOfRecordsSuccessful = 0;
|
|
|
63 |
List<String> failedSkus = new ArrayList<String>();
|
|
|
64 |
while ((str = reader.readLine()) != null) {
|
|
|
65 |
lineNumber++;
|
|
|
66 |
if (lineNumber<2) {
|
|
|
67 |
continue;
|
|
|
68 |
}
|
|
|
69 |
String[] values = str.split("\t");
|
|
|
70 |
if (lineNumber==2){
|
|
|
71 |
numberOfRecords = Integer.valueOf(values[3]);
|
|
|
72 |
continue;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
if (lineNumber==3){
|
|
|
76 |
numberOfRecordsSuccessful = Integer.valueOf(values[3]);
|
|
|
77 |
continue;
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
if (numberOfRecords==numberOfRecordsSuccessful && numberOfRecords>0){
|
|
|
81 |
//All Processed Successfully
|
|
|
82 |
}
|
|
|
83 |
else{
|
|
|
84 |
//Find the ones not processed
|
|
|
85 |
lineNumber = 0;
|
|
|
86 |
while ((str = reader.readLine()) != null) {
|
|
|
87 |
lineNumber++;
|
|
|
88 |
if (lineNumber<6) {
|
|
|
89 |
continue;
|
|
|
90 |
}
|
|
|
91 |
String[] values = str.split("\t");
|
|
|
92 |
if (values[1].length()==0){
|
|
|
93 |
continue;
|
|
|
94 |
}
|
|
|
95 |
failedSkus.add(values[1]);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
System.out.println(failedSkus);
|
|
|
99 |
return true;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public long getTimeInMilliseconds(){
|
|
|
103 |
Calendar cal=GregorianCalendar.getInstance();
|
|
|
104 |
return cal.getTimeInMillis();
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public static void main(String[] args) throws NumberFormatException, IOException{
|
|
|
108 |
CheckPromoFeedSubmission ck = new CheckPromoFeedSubmission();
|
|
|
109 |
ck.ProcessFeed("10360586988");
|
|
|
110 |
}
|
|
|
111 |
}
|