| Line 21... |
Line 21... |
| 21 |
import org.apache.http.entity.StringEntity;
|
21 |
import org.apache.http.entity.StringEntity;
|
| 22 |
import org.apache.http.impl.client.DefaultHttpClient;
|
22 |
import org.apache.http.impl.client.DefaultHttpClient;
|
| 23 |
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
23 |
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
| 24 |
import org.apache.thrift.TException;
|
24 |
import org.apache.thrift.TException;
|
| 25 |
import org.apache.thrift.transport.TTransportException;
|
25 |
import org.apache.thrift.transport.TTransportException;
|
| - |
|
26 |
import org.json.JSONException;
|
| - |
|
27 |
import org.json.JSONObject;
|
| 26 |
import org.slf4j.Logger;
|
28 |
import org.slf4j.Logger;
|
| 27 |
import org.slf4j.LoggerFactory;
|
29 |
import org.slf4j.LoggerFactory;
|
| 28 |
|
30 |
|
| 29 |
public class UpdateFlipkartPricing extends Thread{
|
31 |
public class UpdateFlipkartPricing extends Thread{
|
| 30 |
private Float price;
|
32 |
private Float price;
|
| Line 52... |
Line 54... |
| 52 |
UpdateFlipkartPricing updateFlipkartPricing = new UpdateFlipkartPricing(22200f,"1108903",item,System.currentTimeMillis());
|
54 |
UpdateFlipkartPricing updateFlipkartPricing = new UpdateFlipkartPricing(22200f,"1108903",item,System.currentTimeMillis());
|
| 53 |
logger.info("Calling Thread to update price at snapdeal");
|
55 |
logger.info("Calling Thread to update price at snapdeal");
|
| 54 |
updateFlipkartPricing.start();
|
56 |
updateFlipkartPricing.start();
|
| 55 |
|
57 |
|
| 56 |
}
|
58 |
}
|
| 57 |
int updatePricing(Float price,String fksku,Item item,Long timestamp){
|
59 |
int updatePricing(Float price,String fksku,Item item,Long timestamp) throws JSONException{
|
| 58 |
logger.info("Calling Update Flipkart Price Method --" + " Price :" +price + " Supc :"+fksku +" Item ID:" +item.getId());
|
60 |
logger.info("Calling Update Flipkart Price Method --" + " Price :" +price + " Supc :"+fksku +" Item ID:" +item.getId());
|
| 59 |
ClientConnectionManager connManager = new PoolingClientConnectionManager();
|
61 |
ClientConnectionManager connManager = new PoolingClientConnectionManager();
|
| 60 |
DefaultHttpClient httpclient = new DefaultHttpClient(connManager);
|
62 |
DefaultHttpClient httpclient = new DefaultHttpClient(connManager);
|
| 61 |
httpclient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpclient);
|
63 |
httpclient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpclient);
|
| 62 |
httpclient.getCredentialsProvider().setCredentials(
|
64 |
httpclient.getCredentialsProvider().setCredentials(
|
| 63 |
new AuthScope("api.flipkart.net", 443),
|
65 |
new AuthScope("api.flipkart.net", 443),
|
| 64 |
new UsernamePasswordCredentials("m2z93iskuj81qiid","0c7ab6a5-98c0-4cdc-8be3-72c591e0add4"));
|
66 |
new UsernamePasswordCredentials("m2z93iskuj81qiid","0c7ab6a5-98c0-4cdc-8be3-72c591e0add4"));
|
| 65 |
HttpPost httppost = new HttpPost("https://api.flipkart.net/sellers/skus/"+fksku+"/listings");
|
67 |
HttpPost httppost = new HttpPost("https://api.flipkart.net/sellers/skus/"+fksku+"/listings");
|
| 66 |
StringBuffer jsonRequest = new StringBuffer();
|
68 |
StringBuffer jsonRequest = new StringBuffer();
|
| - |
|
69 |
JSONObject outer = new JSONObject();
|
| - |
|
70 |
JSONObject inner = new JSONObject();
|
| - |
|
71 |
outer.put("skuId",fksku);
|
| - |
|
72 |
inner.put("selling_price", price);
|
| - |
|
73 |
outer.put("attributeValues", inner);
|
| 67 |
jsonRequest.append("{\"skuId\":"+"\""+fksku+
|
74 |
/*jsonRequest.append("{\"skuId\":"+"\""+fksku+
|
| 68 |
"\","+"\"attributeValues\""+":"+
|
75 |
"\","+"\"attributeValues\""+":"+
|
| 69 |
"{\"selling_price\""+":"+"\""+price+
|
76 |
"{\"selling_price\""+":"+"\""+price+
|
| 70 |
"\",}");
|
77 |
"\"}");*/
|
| 71 |
StringEntity input = null;
|
78 |
StringEntity input = null;
|
| 72 |
try {
|
79 |
try {
|
| 73 |
input = new StringEntity(jsonRequest.toString());
|
80 |
input = new StringEntity(outer.toString());
|
| 74 |
logger.info("Json input " + jsonRequest.toString());
|
81 |
logger.info("Json input " + jsonRequest.toString());
|
| 75 |
} catch (UnsupportedEncodingException e) {
|
82 |
} catch (UnsupportedEncodingException e) {
|
| 76 |
logger.error("Unable to create request",e);
|
83 |
logger.error("Unable to create request",e);
|
| 77 |
}
|
84 |
}
|
| 78 |
input.setContentType("application/json");
|
85 |
input.setContentType("application/json");
|
| Line 147... |
Line 154... |
| 147 |
return 1;
|
154 |
return 1;
|
| 148 |
}
|
155 |
}
|
| 149 |
|
156 |
|
| 150 |
public void run()
|
157 |
public void run()
|
| 151 |
{
|
158 |
{
|
| - |
|
159 |
try {
|
| 152 |
this.updatePricing(this.price,this.fksku,this.item,timestamp);
|
160 |
this.updatePricing(this.price,this.fksku,this.item,timestamp);
|
| - |
|
161 |
} catch (JSONException e) {
|
| - |
|
162 |
// TODO Auto-generated catch block
|
| - |
|
163 |
logger.error("Exception while updating prices",e);
|
| - |
|
164 |
}
|
| 153 |
|
165 |
|
| 154 |
}
|
166 |
}
|
| 155 |
String getProductName(Item item){
|
167 |
String getProductName(Item item){
|
| 156 |
return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor());
|
168 |
return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor());
|
| 157 |
|
169 |
|