Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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