| Line 1... |
Line 1... |
| 1 |
package in.shop2020.support.utils;
|
1 |
package in.shop2020.support.utils;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.catalog.AmazonPromotion;
|
3 |
import in.shop2020.model.v1.catalog.AmazonPromotion;
|
| - |
|
4 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
| - |
|
5 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| - |
|
6 |
import in.shop2020.model.v1.catalog.Item;
|
| - |
|
7 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
8 |
import in.shop2020.utils.GmailUtils;
|
| 4 |
|
9 |
|
| 5 |
import java.io.BufferedReader;
|
10 |
import java.io.BufferedReader;
|
| 6 |
import java.io.BufferedWriter;
|
11 |
import java.io.BufferedWriter;
|
| - |
|
12 |
import java.io.File;
|
| 7 |
import java.io.FileInputStream;
|
13 |
import java.io.FileInputStream;
|
| 8 |
import java.io.FileNotFoundException;
|
14 |
import java.io.FileNotFoundException;
|
| 9 |
import java.io.FileReader;
|
15 |
import java.io.FileReader;
|
| 10 |
import java.io.FileWriter;
|
16 |
import java.io.FileWriter;
|
| 11 |
import java.io.IOException;
|
17 |
import java.io.IOException;
|
| 12 |
import java.security.DigestInputStream;
|
18 |
import java.security.DigestInputStream;
|
| 13 |
import java.security.MessageDigest;
|
19 |
import java.security.MessageDigest;
|
| 14 |
import java.security.NoSuchAlgorithmException;
|
20 |
import java.security.NoSuchAlgorithmException;
|
| - |
|
21 |
import java.util.ArrayList;
|
| 15 |
import java.util.Arrays;
|
22 |
import java.util.Arrays;
|
| 16 |
import java.util.Calendar;
|
23 |
import java.util.Calendar;
|
| - |
|
24 |
import java.util.GregorianCalendar;
|
| 17 |
import java.util.List;
|
25 |
import java.util.List;
|
| 18 |
|
26 |
|
| 19 |
import org.apache.commons.codec.binary.Base64;
|
27 |
import org.apache.commons.codec.binary.Base64;
|
| - |
|
28 |
import org.apache.thrift.TException;
|
| - |
|
29 |
import org.apache.thrift.transport.TTransportException;
|
| - |
|
30 |
import org.slf4j.Logger;
|
| - |
|
31 |
import org.slf4j.LoggerFactory;
|
| 20 |
|
32 |
|
| 21 |
import com.amazonaws.mws.MarketplaceWebService;
|
33 |
import com.amazonaws.mws.MarketplaceWebService;
|
| 22 |
import com.amazonaws.mws.MarketplaceWebServiceClient;
|
34 |
import com.amazonaws.mws.MarketplaceWebServiceClient;
|
| 23 |
import com.amazonaws.mws.MarketplaceWebServiceConfig;
|
35 |
import com.amazonaws.mws.MarketplaceWebServiceConfig;
|
| 24 |
import com.amazonaws.mws.MarketplaceWebServiceException;
|
36 |
import com.amazonaws.mws.MarketplaceWebServiceException;
|
| 25 |
import com.amazonaws.mws.model.IdList;
|
37 |
import com.amazonaws.mws.model.IdList;
|
| 26 |
import com.amazonaws.mws.model.SubmitFeedRequest;
|
38 |
import com.amazonaws.mws.model.SubmitFeedRequest;
|
| 27 |
import com.amazonaws.mws.model.SubmitFeedResponse;
|
39 |
import com.amazonaws.mws.model.SubmitFeedResponse;
|
| 28 |
import com.ibm.icu.text.SimpleDateFormat;
|
40 |
import com.ibm.icu.text.SimpleDateFormat;
|
| - |
|
41 |
import com.amazonaws.mws.samples.CheckPromoFeedSubmission;
|
| 29 |
|
42 |
|
| 30 |
public class PromotionFeed {
|
43 |
public class PromotionFeed extends Thread{
|
| - |
|
44 |
|
| - |
|
45 |
private static Logger logger = LoggerFactory.getLogger(PromotionFeed.class);
|
| - |
|
46 |
private List<AmazonPromotion> amazonPromotions;
|
| - |
|
47 |
public String[] sendTo = new String[]{ "rajneesh.arora@shop2020.in","kshitij.sood@shop2020.in","anikendra.das@shop2020.in",
|
| - |
|
48 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com","chandan.kumar@shop2020.in"};
|
| - |
|
49 |
//public String[] sendTo = new String[]{ "kshitij.sood@saholic.com"};
|
| - |
|
50 |
public String emailFromAddress = "build-staging@shop2020.in";
|
| - |
|
51 |
public String password = "shop2020";
|
| - |
|
52 |
public String[] engineering = new String[]{ "eng@shop2020.in"};
|
| - |
|
53 |
|
| 31 |
public String CreatePromotionFeed(List<AmazonPromotion> amazonPromotions) throws IOException{
|
54 |
public PromotionFeed(List<AmazonPromotion> amazonPromotions){
|
| - |
|
55 |
this.amazonPromotions = amazonPromotions;
|
| - |
|
56 |
}
|
| - |
|
57 |
|
| - |
|
58 |
void CreatePromotionFeed(List<AmazonPromotion> amazonPromotions) throws IOException, InterruptedException, MarketplaceWebServiceException{
|
| 32 |
BufferedReader reader = null;
|
59 |
BufferedReader reader = null;
|
| 33 |
BufferedWriter writer = null;
|
60 |
BufferedWriter writer = null;
|
| 34 |
String promotionFilename = null;
|
61 |
String promotionFilename = null;
|
| 35 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
62 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
| 36 |
Calendar calendar = Calendar.getInstance();
|
63 |
Calendar calendar = Calendar.getInstance();
|
| 37 |
try {
|
64 |
try {
|
| 38 |
promotionFilename = "/tmp/Promotion-"+System.currentTimeMillis()+".txt";
|
65 |
promotionFilename = "/tmp/Promotion-"+System.currentTimeMillis()+".txt";
|
| 39 |
reader = new BufferedReader(new FileReader("/tmp/p.txt"));
|
66 |
reader = new BufferedReader(new FileReader("/temp-uploads/amazon-promo-flat-file.txt"));
|
| 40 |
writer = new BufferedWriter(new FileWriter(promotionFilename));
|
67 |
writer = new BufferedWriter(new FileWriter(promotionFilename));
|
| 41 |
String Line;
|
68 |
String Line;
|
| 42 |
while ((Line = reader.readLine()) != null) {
|
69 |
while ((Line = reader.readLine()) != null) {
|
| 43 |
writer.write(Line+"\n");
|
70 |
writer.write(Line+"\n");
|
| 44 |
}
|
71 |
}
|
| 45 |
for(AmazonPromotion am:amazonPromotions){
|
72 |
for(AmazonPromotion am:amazonPromotions){
|
| 46 |
calendar.setTimeInMillis(am.getStartDate());
|
73 |
calendar.setTimeInMillis(am.getStartDate());
|
| 47 |
String start = formatter.format(calendar.getTime());
|
74 |
String start = formatter.format(calendar.getTime());
|
| 48 |
calendar.setTimeInMillis(am.getEndDate());
|
75 |
calendar.setTimeInMillis(am.getEndDate());
|
| 49 |
String end = formatter.format(calendar.getTime());
|
76 |
String end = formatter.format(calendar.getTime());
|
| 50 |
writer.write(am.getSku()+"\t"+
|
- |
|
| 51 |
""+"\t"
|
- |
|
| 52 |
+""+"\t"
|
- |
|
| 53 |
+""+"\t"
|
- |
|
| 54 |
+""+"\t"
|
- |
|
| 55 |
+""+"\t"
|
- |
|
| 56 |
+"\t"
|
- |
|
| 57 |
+"\t"
|
- |
|
| 58 |
+"\t"
|
- |
|
| 59 |
+"\t"
|
- |
|
| 60 |
+"PartialUpdate"+"\t"
|
- |
|
| 61 |
+am.getStandardPrice()+"\t"
|
- |
|
| 62 |
+""+"\t"
|
- |
|
| 63 |
+""+"\t"
|
- |
|
| 64 |
+""+"\t"
|
- |
|
| 65 |
+""+"\t"
|
- |
|
| 66 |
+"1"+"\t"
|
- |
|
| 67 |
+am.getSalePrice()+"\t"
|
- |
|
| 68 |
+start+"\t"
|
- |
|
| 69 |
+end+"\t"
|
- |
|
| 70 |
+""+"\t"+"\n");
|
- |
|
| 71 |
}
|
- |
|
| 72 |
|
- |
|
| 73 |
} catch (FileNotFoundException e1) {
|
- |
|
| 74 |
e1.printStackTrace();
|
- |
|
| 75 |
}
|
- |
|
| 76 |
finally{
|
- |
|
| 77 |
writer.close();
|
- |
|
| 78 |
reader.close();
|
- |
|
| 79 |
System.out.println("Done");
|
- |
|
| 80 |
}
|
- |
|
| 81 |
return promotionFilename;
|
- |
|
| 82 |
}
|
- |
|
| 83 |
public String SubmitPromotionFeed(String file) throws FileNotFoundException, InterruptedException, MarketplaceWebServiceException{
|
- |
|
| 84 |
MarketplaceWebService service = getMarketplaceServiceInstance();
|
- |
|
| 85 |
SubmitFeedRequest requestPromotion = new SubmitFeedRequest();
|
- |
|
| 86 |
requestPromotion.setMerchant("AF6E3O0VE0X4D");
|
- |
|
| 87 |
requestPromotion.setMarketplaceIdList(new IdList(Arrays.asList("A21TJRUUN4KGV")));
|
- |
|
| 88 |
requestPromotion.setFeedType("_POST_FLAT_FILE_LISTINGS_DATA_");
|
- |
|
| 89 |
FileInputStream promotionfis = new FileInputStream(file);
|
- |
|
| 90 |
requestPromotion.setContentMD5(computeContentMD5HeaderValue(promotionfis));
|
- |
|
| 91 |
requestPromotion.setFeedContent(promotionfis);
|
- |
|
| 92 |
return invokeSubmitFeed(service,requestPromotion);
|
- |
|
| 93 |
}
|
- |
|
| 94 |
public MarketplaceWebService getMarketplaceServiceInstance(){
|
- |
|
| 95 |
final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
|
- |
|
| 96 |
final String secretAccessKey = "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg";
|
- |
|
| 97 |
final String appName = "Test";
|
- |
|
| 98 |
final String appVersion = "1.0";
|
- |
|
| 99 |
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
|
- |
|
| 100 |
config.setServiceURL("https://mws.amazonservices.in");
|
- |
|
| 101 |
return new MarketplaceWebServiceClient(
|
- |
|
| 102 |
accessKeyId, secretAccessKey, appName, appVersion, config);
|
- |
|
| 103 |
}
|
- |
|
| 104 |
public static String computeContentMD5HeaderValue(FileInputStream fis) {
|
- |
|
| 105 |
try {
|
- |
|
| 106 |
DigestInputStream dis = new DigestInputStream(fis,
|
- |
|
| 107 |
MessageDigest.getInstance("MD5"));
|
- |
|
| 108 |
byte[] buffer = new byte[8192];
|
- |
|
| 109 |
while (dis.read(buffer) > 0)
|
- |
|
| 110 |
;
|
- |
|
| 111 |
String md5Content = new String(Base64.encodeBase64(dis
|
- |
|
| 112 |
.getMessageDigest().digest()));
|
- |
|
| 113 |
// Effectively resets the stream to be beginning of the file via a
|
- |
|
| 114 |
fis.getChannel().position(0);
|
- |
|
| 115 |
return md5Content;
|
- |
|
| 116 |
} catch (NoSuchAlgorithmException e) {
|
- |
|
| 117 |
e.printStackTrace();
|
- |
|
| 118 |
} catch (IOException e) {
|
- |
|
| 119 |
e.printStackTrace();
|
- |
|
| 120 |
}
|
- |
|
| 121 |
return null;
|
- |
|
| 122 |
}
|
- |
|
| 123 |
public String invokeSubmitFeed(MarketplaceWebService service,SubmitFeedRequest request) throws InterruptedException, MarketplaceWebServiceException {
|
- |
|
| 124 |
SubmitFeedResponse response = service.submitFeed(request);
|
- |
|
| 125 |
return response.getSubmitFeedResult().getFeedSubmissionInfo().getFeedSubmissionId();
|
- |
|
| 126 |
}
|
- |
|
| 127 |
}
|
- |
|
| 128 |
|
77 |
writer.write(am.getSku()+"\t"+
|
| - |
|
78 |
""+"\t"
|
| - |
|
79 |
+""+"\t"
|
| - |
|
80 |
+""+"\t"
|
| - |
|
81 |
+""+"\t"
|
| - |
|
82 |
+""+"\t"
|
| - |
|
83 |
+"\t"
|
| - |
|
84 |
+"\t"
|
| - |
|
85 |
+"\t"
|
| - |
|
86 |
+"\t"
|
| - |
|
87 |
+"PartialUpdate"+"\t"
|
| - |
|
88 |
+am.getStandardPrice()+"\t"
|
| - |
|
89 |
+""+"\t"
|
| - |
|
90 |
+""+"\t"
|
| - |
|
91 |
+""+"\t"
|
| - |
|
92 |
+""+"\t"
|
| - |
|
93 |
+"1"+"\t"
|
| - |
|
94 |
+am.getSalePrice()+"\t"
|
| - |
|
95 |
+start+"\t"
|
| - |
|
96 |
+end+"\t"
|
| - |
|
97 |
+""+"\t"+"\n");
|
| - |
|
98 |
}
|
| - |
|
99 |
|
| - |
|
100 |
} catch (FileNotFoundException e1) {
|
| - |
|
101 |
e1.printStackTrace();
|
| - |
|
102 |
}
|
| - |
|
103 |
finally{
|
| - |
|
104 |
writer.close();
|
| - |
|
105 |
reader.close();
|
| - |
|
106 |
}
|
| - |
|
107 |
try {
|
| - |
|
108 |
SubmitPromotionFeed(promotionFilename,amazonPromotions);
|
| - |
|
109 |
} catch (TException e) {
|
| - |
|
110 |
logger.error("TException in subit promtiono feed ",e);
|
| - |
|
111 |
GmailUtils mailer = new GmailUtils();
|
| - |
|
112 |
try{
|
| - |
|
113 |
//mailer.sendSSLMessage(sendTo, "Amazon Promotion ( Submission Id " + feedSubmissionId + " )","", emailFromAddress , password, new ArrayList<File>(), tempFile);
|
| - |
|
114 |
mailer.sendSSLMessage(engineering,"Thrift Exception in configuring amazon promotion",emailFromAddress, password, "");
|
| - |
|
115 |
}
|
| - |
|
116 |
catch(Exception ex){
|
| - |
|
117 |
logger.info("Exception"+ex);
|
| - |
|
118 |
}
|
| - |
|
119 |
}
|
| - |
|
120 |
}
|
| - |
|
121 |
|
| - |
|
122 |
public void run(){
|
| - |
|
123 |
try {
|
| - |
|
124 |
this.CreatePromotionFeed(this.amazonPromotions);
|
| - |
|
125 |
} catch (IOException e) {
|
| - |
|
126 |
logger.error("IO exception while creating promo",e);
|
| - |
|
127 |
} catch (InterruptedException e) {
|
| - |
|
128 |
logger.error("IE exception while creating promo",e);
|
| - |
|
129 |
} catch (MarketplaceWebServiceException e) {
|
| - |
|
130 |
logger.error("MWS exception while creating promo",e);
|
| - |
|
131 |
}
|
| - |
|
132 |
}
|
| - |
|
133 |
|
| - |
|
134 |
public void SubmitPromotionFeed(String file,List<AmazonPromotion> amazonPromotions) throws InterruptedException, MarketplaceWebServiceException, IOException, TException{
|
| - |
|
135 |
MarketplaceWebService service = getMarketplaceServiceInstance();
|
| - |
|
136 |
SubmitFeedRequest requestPromotion = new SubmitFeedRequest();
|
| - |
|
137 |
requestPromotion.setMerchant("AF6E3O0VE0X4D");
|
| - |
|
138 |
requestPromotion.setMarketplaceIdList(new IdList(Arrays.asList("A21TJRUUN4KGV")));
|
| - |
|
139 |
requestPromotion.setFeedType("_POST_FLAT_FILE_LISTINGS_DATA_");
|
| - |
|
140 |
FileInputStream promotionfis = new FileInputStream(file);
|
| - |
|
141 |
requestPromotion.setContentMD5(computeContentMD5HeaderValue(promotionfis));
|
| - |
|
142 |
requestPromotion.setFeedContent(promotionfis);
|
| - |
|
143 |
String feedSubmissionId = invokeSubmitFeed(service,requestPromotion);
|
| - |
|
144 |
sendPromotionConfigurationEmail(feedSubmissionId);
|
| - |
|
145 |
CheckPromoFeedSubmission ck = new CheckPromoFeedSubmission();
|
| - |
|
146 |
int checkResultCount=0;
|
| - |
|
147 |
List<String> failedSkus=null;
|
| - |
|
148 |
List<AmazonPromotion> successfulPromo = new ArrayList<AmazonPromotion>();
|
| - |
|
149 |
while (failedSkus == null){
|
| - |
|
150 |
failedSkus = ck.ProcessFeed(feedSubmissionId);
|
| - |
|
151 |
if (failedSkus == null){
|
| - |
|
152 |
checkResultCount++;
|
| - |
|
153 |
if (checkResultCount == 7){
|
| - |
|
154 |
String text = "";
|
| - |
|
155 |
String[] sendTo = { "eng@shop2020.in" };
|
| - |
|
156 |
String emailSubjectTxt = "Unable To Receive Promo Feed Result.Submission Id "+feedSubmissionId;
|
| - |
|
157 |
String emailFromAddress = "build-staging@shop2020.in";
|
| - |
|
158 |
String password = "shop2020";
|
| - |
|
159 |
GmailUtils mailer = new GmailUtils();
|
| - |
|
160 |
try {
|
| - |
|
161 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
|
| - |
|
162 |
}
|
| - |
|
163 |
catch (Exception e) {
|
| - |
|
164 |
e.printStackTrace();
|
| - |
|
165 |
}
|
| - |
|
166 |
return;
|
| - |
|
167 |
}
|
| - |
|
168 |
logger.info("=====Feed Result Not Ready Retry Again After 3 Minutes=============");
|
| - |
|
169 |
Thread.sleep(180000);
|
| - |
|
170 |
}
|
| - |
|
171 |
else{
|
| - |
|
172 |
for (AmazonPromotion am :amazonPromotions){
|
| - |
|
173 |
if (!failedSkus.contains(am.getSku())){
|
| - |
|
174 |
successfulPromo.add(am);
|
| - |
|
175 |
}
|
| - |
|
176 |
}
|
| - |
|
177 |
Client catalogClient;
|
| - |
|
178 |
try {
|
| - |
|
179 |
catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| - |
|
180 |
} catch (TTransportException e) {
|
| - |
|
181 |
logger.error("Catalog Service ex ",e);
|
| - |
|
182 |
return;
|
| - |
|
183 |
}
|
| - |
|
184 |
catalogClient.updateAmazonPromotion(successfulPromo);
|
| - |
|
185 |
if (failedSkus.size()>0){
|
| - |
|
186 |
sendFailerMail(failedSkus,feedSubmissionId);
|
| - |
|
187 |
}
|
| - |
|
188 |
else{
|
| - |
|
189 |
sendSuccessMail(feedSubmissionId);
|
| - |
|
190 |
}
|
| - |
|
191 |
}
|
| - |
|
192 |
}
|
| - |
|
193 |
}
|
| - |
|
194 |
|
| - |
|
195 |
public void sendFailerMail(List<String> failedSkus,String feedSubmissionId){
|
| - |
|
196 |
Client catalogClient;
|
| - |
|
197 |
StringBuffer sb = new StringBuffer();
|
| - |
|
198 |
sb.append("<html><table border=\"1\" align=\"center\">"
|
| - |
|
199 |
+ "<caption><b>" + "Amazon Promotion Failure" + "</b></caption>"
|
| - |
|
200 |
+ "<tr>" + "<td style=\"text-align:center;\"><b>" + "AMAZON-SKU" + "</b></td>" +
|
| - |
|
201 |
"<td style=\"text-align:center;\"><b>"
|
| - |
|
202 |
+ "PRODUCT-NAME" + "</b>"
|
| - |
|
203 |
+ "</tr>");
|
| - |
|
204 |
try {
|
| - |
|
205 |
catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| - |
|
206 |
} catch (TTransportException e) {
|
| - |
|
207 |
logger.error("Catalog Service ex ",e);
|
| - |
|
208 |
return;
|
| - |
|
209 |
}
|
| - |
|
210 |
GmailUtils mailer = new GmailUtils();
|
| - |
|
211 |
for (String sku :failedSkus){
|
| - |
|
212 |
Item item = null;
|
| - |
|
213 |
try {
|
| - |
|
214 |
item = catalogClient.getItem(Long.valueOf(sku.substring(3)));
|
| - |
|
215 |
} catch (Exception e) {
|
| - |
|
216 |
logger.error("Exception while parsing sku ",e);
|
| - |
|
217 |
return;
|
| - |
|
218 |
}
|
| - |
|
219 |
sb.append("<tr>"+"<td style=\"text-align:center;\">"+sku+"</td>"
|
| - |
|
220 |
+"<td style=\"text-align:center;\">"+getVaildName(item.getBrand())+" "
|
| - |
|
221 |
+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor())+"</td>"
|
| - |
|
222 |
+"</tr>"
|
| - |
|
223 |
);
|
| - |
|
224 |
}
|
| - |
|
225 |
sb.append("</table></html>");
|
| - |
|
226 |
// String tempFile = "/tmp/"+getTimeInMilliseconds()+"-amazon-promo-mail.htm";
|
| - |
|
227 |
// BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
|
| - |
|
228 |
// out.write(sb.toString());
|
| - |
|
229 |
// out.flush();
|
| - |
|
230 |
// out.close();
|
| - |
|
231 |
try{
|
| - |
|
232 |
//mailer.sendSSLMessage(sendTo, "Amazon Promotion ( Submission Id " + feedSubmissionId + " )","", emailFromAddress , password, new ArrayList<File>(), tempFile);
|
| - |
|
233 |
mailer.sendSSLMessage(sendTo,"Amazon Promotion ( Submission Id " + feedSubmissionId + " )",emailFromAddress, password, sb.toString());
|
| - |
|
234 |
}
|
| - |
|
235 |
catch(Exception e){
|
| - |
|
236 |
logger.info("Exception"+e);
|
| - |
|
237 |
}
|
| - |
|
238 |
}
|
| - |
|
239 |
|
| - |
|
240 |
public void sendPromotionConfigurationEmail(String feedSubmissionId) throws IOException{
|
| - |
|
241 |
Client catalogClient;
|
| - |
|
242 |
StringBuffer sb = new StringBuffer();
|
| - |
|
243 |
sb.append("<html><table border=\"1\" align=\"center\">"
|
| - |
|
244 |
+ "<caption><b>" + "Amazon Promotion Details" + "</b></caption>"
|
| - |
|
245 |
+ "<tr>" + "<td style=\"text-align:center;\"><b>" + "AMAZON-SKU" + "</b></td>" +
|
| - |
|
246 |
"<td style=\"text-align:center;\"><b>"
|
| - |
|
247 |
+ "PRODUCT-NAME" + "</b></td>" + "<td style=\"text-align:center;\"><b>" + "STANDARD-PRICE"
|
| - |
|
248 |
+ "</b></td>" + "<td style=\"text-align:center;\"><b>" + "SALE-PRICE" + "</b></td>"
|
| - |
|
249 |
+ "<td style=\"text-align:center;\"><b>" + "SUBSIDY" + "</b></td>" +
|
| - |
|
250 |
"<td style=\"text-align:center;\"><b>"
|
| - |
|
251 |
+ "START-DATE" + "</b></td>" + "<td style=\"text-align:center;\"><b>" + "END-DATE"
|
| - |
|
252 |
+ "</tr>");
|
| - |
|
253 |
try {
|
| - |
|
254 |
catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| - |
|
255 |
} catch (TTransportException e) {
|
| - |
|
256 |
logger.error("Catalog Service ex ",e);
|
| - |
|
257 |
return;
|
| - |
|
258 |
}
|
| - |
|
259 |
GmailUtils mailer = new GmailUtils();
|
| - |
|
260 |
for (AmazonPromotion amPromotion : this.amazonPromotions){
|
| - |
|
261 |
Item item = null;
|
| - |
|
262 |
try {
|
| - |
|
263 |
item = catalogClient.getItem(Long.valueOf(amPromotion.getSku().substring(3)));
|
| - |
|
264 |
} catch (Exception e) {
|
| - |
|
265 |
logger.error("Exception while parsing sku ",e);
|
| - |
|
266 |
return;
|
| - |
|
267 |
}
|
| - |
|
268 |
sb.append("<tr>"+"<td style=\"text-align:center;\">"+amPromotion.getSku()+"</td>"
|
| - |
|
269 |
+"<td style=\"text-align:center;\">"+getVaildName(item.getBrand())+" "
|
| - |
|
270 |
+getVaildName(item.getModelName())+" "+getVaildName(item.getModelNumber())+" "+getVaildName(item.getColor())+"</td>"
|
| - |
|
271 |
+"<td style=\"text-align:center;\">"+amPromotion.getStandardPrice()+"</td>"
|
| - |
|
272 |
+"<td style=\"text-align:center;\">"+amPromotion.getSalePrice()+"</td>"
|
| - |
|
273 |
+"<td style=\"text-align:center;\">"+amPromotion.getSubsidyAmount()+"</td>"
|
| - |
|
274 |
+"<td style=\"text-align:center;\">"+getDate(amPromotion.getStartDate())+"</td>"
|
| - |
|
275 |
+"<td style=\"text-align:center;\">"+getDate(amPromotion.getEndDate())+"</td>"+"</tr>"
|
| - |
|
276 |
);
|
| - |
|
277 |
}
|
| - |
|
278 |
sb.append("</table></html>");
|
| - |
|
279 |
// String tempFile = "/tmp/"+getTimeInMilliseconds()+"-amazon-promo-mail.htm";
|
| - |
|
280 |
// BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
|
| - |
|
281 |
// out.write(sb.toString());
|
| - |
|
282 |
// out.flush();
|
| - |
|
283 |
// out.close();
|
| - |
|
284 |
try{
|
| - |
|
285 |
//mailer.sendSSLMessage(sendTo, "Amazon Promotion ( Submission Id " + feedSubmissionId + " )","", emailFromAddress , password, new ArrayList<File>(), tempFile);
|
| - |
|
286 |
mailer.sendSSLMessage(sendTo,"Amazon Promotion ( Submission Id " + feedSubmissionId + " )",emailFromAddress, password, sb.toString());
|
| - |
|
287 |
}
|
| - |
|
288 |
catch(Exception e){
|
| - |
|
289 |
logger.info("Exception"+e);
|
| - |
|
290 |
}
|
| - |
|
291 |
}
|
| - |
|
292 |
|
| - |
|
293 |
public void sendSuccessMail(String feedSubmissionId){
|
| - |
|
294 |
GmailUtils mailer = new GmailUtils();
|
| - |
|
295 |
try{
|
| - |
|
296 |
//mailer.sendSSLMessage(sendTo, "Amazon Promotion ( Submission Id " + feedSubmissionId + " )","", emailFromAddress , password, new ArrayList<File>(), tempFile);
|
| - |
|
297 |
mailer.sendSSLMessage(sendTo,"Amazon Promotion Successfully configured( Submission Id " + feedSubmissionId + " )",emailFromAddress, password, "");
|
| - |
|
298 |
}
|
| - |
|
299 |
catch(Exception e){
|
| - |
|
300 |
logger.info("Exception"+e);
|
| - |
|
301 |
}
|
| - |
|
302 |
}
|
| - |
|
303 |
|
| - |
|
304 |
public String getVaildName(String name){
|
| - |
|
305 |
return name!=null?name:"";
|
| - |
|
306 |
}
|
| - |
|
307 |
|
| - |
|
308 |
public String getDate(long timestamp){
|
| - |
|
309 |
return new java.util.Date(timestamp).toLocaleString();
|
| - |
|
310 |
}
|
| - |
|
311 |
|
| - |
|
312 |
public String getTimeInMilliseconds(){
|
| - |
|
313 |
Calendar cal=GregorianCalendar.getInstance();
|
| - |
|
314 |
return String.valueOf(cal.getTimeInMillis());
|
| - |
|
315 |
}
|
| - |
|
316 |
|
| - |
|
317 |
public MarketplaceWebService getMarketplaceServiceInstance(){
|
| - |
|
318 |
final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
|
| - |
|
319 |
final String secretAccessKey = "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg";
|
| - |
|
320 |
final String appName = "Test";
|
| - |
|
321 |
final String appVersion = "1.0";
|
| - |
|
322 |
MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
|
| - |
|
323 |
config.setServiceURL("https://mws.amazonservices.in");
|
| - |
|
324 |
return new MarketplaceWebServiceClient(
|
| - |
|
325 |
accessKeyId, secretAccessKey, appName, appVersion, config);
|
| - |
|
326 |
}
|
| - |
|
327 |
|
| - |
|
328 |
public static String computeContentMD5HeaderValue(FileInputStream fis) {
|
| - |
|
329 |
try {
|
| - |
|
330 |
DigestInputStream dis = new DigestInputStream(fis,
|
| - |
|
331 |
MessageDigest.getInstance("MD5"));
|
| - |
|
332 |
byte[] buffer = new byte[8192];
|
| - |
|
333 |
while (dis.read(buffer) > 0)
|
| - |
|
334 |
;
|
| - |
|
335 |
String md5Content = new String(Base64.encodeBase64(dis
|
| - |
|
336 |
.getMessageDigest().digest()));
|
| - |
|
337 |
// Effectively resets the stream to be beginning of the file via a
|
| - |
|
338 |
fis.getChannel().position(0);
|
| - |
|
339 |
return md5Content;
|
| - |
|
340 |
} catch (NoSuchAlgorithmException e) {
|
| - |
|
341 |
e.printStackTrace();
|
| - |
|
342 |
} catch (IOException e) {
|
| - |
|
343 |
e.printStackTrace();
|
| - |
|
344 |
}
|
| - |
|
345 |
return null;
|
| - |
|
346 |
}
|
| - |
|
347 |
|
| - |
|
348 |
public String invokeSubmitFeed(MarketplaceWebService service,SubmitFeedRequest request) throws InterruptedException, MarketplaceWebServiceException {
|
| - |
|
349 |
SubmitFeedResponse response = service.submitFeed(request);
|
| - |
|
350 |
return response.getSubmitFeedResult().getFeedSubmissionInfo().getFeedSubmissionId();
|
| - |
|
351 |
}
|
| - |
|
352 |
|
| - |
|
353 |
}
|
| - |
|
354 |
|