| Line 31... |
Line 31... |
| 31 |
import org.slf4j.Logger;
|
31 |
import org.slf4j.Logger;
|
| 32 |
import org.slf4j.LoggerFactory;
|
32 |
import org.slf4j.LoggerFactory;
|
| 33 |
|
33 |
|
| 34 |
public class UpdateSDPricingUsingPanel extends Thread{
|
34 |
public class UpdateSDPricingUsingPanel extends Thread{
|
| 35 |
static ClientConnectionManager connManager = new PoolingClientConnectionManager();
|
35 |
static ClientConnectionManager connManager = new PoolingClientConnectionManager();
|
| 36 |
|
- |
|
| 37 |
private static DefaultHttpClient httpClient = new DefaultHttpClient(connManager);
|
36 |
private static DefaultHttpClient httpClient = new DefaultHttpClient(connManager);
|
| 38 |
|
- |
|
| 39 |
//private static DefaultHttpClient httpClient = new DefaultHttpClient();
|
37 |
//private static DefaultHttpClient httpClient = new DefaultHttpClient();
|
| 40 |
private Float price;
|
38 |
private Float price;
|
| 41 |
private String supc;
|
39 |
private String supc;
|
| 42 |
private Item item;
|
40 |
private Item item;
|
| 43 |
private Long timestamp;
|
41 |
private Long timestamp;
|
| 44 |
public boolean voiUpdation;
|
- |
|
| 45 |
//public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
|
42 |
//public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
|
| 46 |
private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
|
43 |
private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
|
| 47 |
public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
|
44 |
public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
|
| 48 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
45 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
| 49 |
"yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","kshitij.sood@shop2020.in"};
|
46 |
"yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","kshitij.sood@shop2020.in"};
|
| Line 56... |
Line 53... |
| 56 |
this.item = item;
|
53 |
this.item = item;
|
| 57 |
this.timestamp = timestamp;
|
54 |
this.timestamp = timestamp;
|
| 58 |
}
|
55 |
}
|
| 59 |
public UpdateSDPricingUsingPanel() {
|
56 |
public UpdateSDPricingUsingPanel() {
|
| 60 |
}
|
57 |
}
|
| 61 |
|
- |
|
| 62 |
public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp, boolean voiUpdation){
|
- |
|
| 63 |
logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId()+" VOI Updation: "+voiUpdation);
|
- |
|
| 64 |
this.price = price;
|
- |
|
| 65 |
this.supc = supc;
|
- |
|
| 66 |
this.item = item;
|
- |
|
| 67 |
this.timestamp = timestamp;
|
- |
|
| 68 |
this.voiUpdation = voiUpdation;
|
- |
|
| 69 |
}
|
- |
|
| 70 |
public static void main(String... args) throws ClientProtocolException, IOException, TTransportException, CatalogServiceException, TException{
|
58 |
public static void main(String... args) throws ClientProtocolException, IOException, TTransportException, CatalogServiceException, TException{
|
| 71 |
Item item = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().getItem(2231);
|
59 |
Item item = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().getItem(2231);
|
| 72 |
UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
|
60 |
UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
|
| 73 |
logger.info("Calling Thread to update price at snapdeal");
|
61 |
logger.info("Calling Thread to update price at snapdeal");
|
| 74 |
updatePriceOnSnapdeal.start();
|
62 |
updatePriceOnSnapdeal.start();
|
| - |
|
63 |
|
| 75 |
}
|
64 |
}
|
| 76 |
int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
|
65 |
int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
|
| 77 |
logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
|
66 |
logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
|
| 78 |
long priceVal = (long)price.floatValue();
|
67 |
long priceVal = (long)price.floatValue();
|
| 79 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
|
68 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
|
| Line 175... |
Line 164... |
| 175 |
while ((line = rd.readLine()) != null) {
|
164 |
while ((line = rd.readLine()) != null) {
|
| 176 |
//System.out.println(line);
|
165 |
//System.out.println(line);
|
| 177 |
}
|
166 |
}
|
| 178 |
logger.info("----Login Successful----" );
|
167 |
logger.info("----Login Successful----" );
|
| 179 |
}
|
168 |
}
|
| 180 |
|
- |
|
| 181 |
public void handleVoiLogin() throws ClientProtocolException, IOException{
|
- |
|
| 182 |
logger.info("----Inside Handle Voi Login ----" );
|
- |
|
| 183 |
HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
- |
|
| 184 |
HttpResponse response = null;
|
- |
|
| 185 |
boolean retry = true;
|
- |
|
| 186 |
while(retry){
|
- |
|
| 187 |
try {
|
- |
|
| 188 |
response = httpClient.execute(get);
|
- |
|
| 189 |
retry = false;
|
- |
|
| 190 |
} catch (ClientProtocolException e) {
|
- |
|
| 191 |
e.printStackTrace();
|
- |
|
| 192 |
logger.error("Exception ",e);
|
- |
|
| 193 |
} catch (IOException e) {
|
- |
|
| 194 |
e.printStackTrace();
|
- |
|
| 195 |
logger.info("Exception " + e);
|
- |
|
| 196 |
}
|
- |
|
| 197 |
}
|
- |
|
| 198 |
BufferedReader rd = null;
|
- |
|
| 199 |
try {
|
- |
|
| 200 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 201 |
} catch (IllegalStateException e1) {
|
- |
|
| 202 |
e1.printStackTrace();
|
- |
|
| 203 |
} catch (IOException e1) {
|
- |
|
| 204 |
e1.printStackTrace();
|
- |
|
| 205 |
}
|
- |
|
| 206 |
String line = "";
|
- |
|
| 207 |
StringBuffer sb = new StringBuffer();
|
- |
|
| 208 |
try {
|
- |
|
| 209 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 210 |
sb.append(line);
|
- |
|
| 211 |
}
|
- |
|
| 212 |
} catch (IOException e) {
|
- |
|
| 213 |
e.printStackTrace();
|
- |
|
| 214 |
}
|
- |
|
| 215 |
int i= sb.toString().indexOf("name=\"lt\" value=");
|
- |
|
| 216 |
char[] charArray = sb.toString().toCharArray();
|
- |
|
| 217 |
String lt = "";
|
- |
|
| 218 |
int j=0;
|
- |
|
| 219 |
for(j=i+16;j<=charArray.length;j++){
|
- |
|
| 220 |
|
- |
|
| 221 |
if(charArray[j]==' '){
|
- |
|
| 222 |
break;
|
- |
|
| 223 |
}
|
- |
|
| 224 |
}
|
- |
|
| 225 |
lt = sb.substring(i+17,j-1);
|
- |
|
| 226 |
System.out.println("LT VALUE " + lt);
|
- |
|
| 227 |
i= sb.toString().indexOf("name=\"execution\" value=");
|
- |
|
| 228 |
charArray = sb.toString().toCharArray();
|
- |
|
| 229 |
String ex = "";
|
- |
|
| 230 |
j=0;
|
- |
|
| 231 |
for(j=i+24;j<=charArray.length;j++){
|
- |
|
| 232 |
if(charArray[j]==' '){
|
- |
|
| 233 |
break;
|
- |
|
| 234 |
}
|
- |
|
| 235 |
}
|
- |
|
| 236 |
ex = sb.substring(i+24,j-1);
|
- |
|
| 237 |
System.out.println("EXECUTION VALUE " + ex);
|
- |
|
| 238 |
HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
- |
|
| 239 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
- |
|
| 240 |
nameValuePairs.add(new BasicNameValuePair("username",
|
- |
|
| 241 |
"spiceonlineretailvoi@gmail.com"));
|
- |
|
| 242 |
nameValuePairs.add(new BasicNameValuePair("password",
|
- |
|
| 243 |
"snapdealsaholic"));
|
- |
|
| 244 |
nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
|
- |
|
| 245 |
nameValuePairs.add(new BasicNameValuePair("execution",ex));
|
- |
|
| 246 |
nameValuePairs.add(new BasicNameValuePair("lt",lt));
|
- |
|
| 247 |
nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
|
- |
|
| 248 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
- |
|
| 249 |
response = httpClient.execute(post);
|
- |
|
| 250 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 251 |
line = "";
|
- |
|
| 252 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 253 |
System.out.println(line);
|
- |
|
| 254 |
}
|
- |
|
| 255 |
get = new HttpGet("http://seller.snapdeal.com/pricing");
|
- |
|
| 256 |
response = httpClient.execute(get);
|
- |
|
| 257 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 258 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 259 |
//System.out.println(line);
|
- |
|
| 260 |
}
|
- |
|
| 261 |
logger.info("----Login Successful into Snapdeal VOI----" );
|
- |
|
| 262 |
}
|
- |
|
| 263 |
public void run()
|
169 |
public void run()
|
| 264 |
{
|
170 |
{
|
| 265 |
try {
|
171 |
try {
|
| 266 |
if(this.voiUpdation){
|
- |
|
| 267 |
this.handleVoiLogin();
|
- |
|
| 268 |
}else{
|
- |
|
| 269 |
this.handleLogin();
|
172 |
this.handleLogin();
|
| 270 |
}
|
- |
|
| 271 |
this.updatePricing(this.price,this.supc,this.item,timestamp);
|
173 |
this.updatePricing(this.price,this.supc,this.item,timestamp);
|
| 272 |
boolean retry =true;
|
174 |
boolean retry =true;
|
| 273 |
while(retry){
|
175 |
while(retry){
|
| 274 |
Thread.sleep(2*60*1000);
|
176 |
Thread.sleep(2*60*1000);
|
| 275 |
HttpGet get = new HttpGet("http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue="+this.supc+"&gridType=normal&_search=false&nd="+System.currentTimeMillis()+"&rows=30&page=1&sidx=&sord=asc");
|
177 |
HttpGet get = new HttpGet("http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue="+this.supc+"&gridType=normal&_search=false&nd="+System.currentTimeMillis()+"&rows=30&page=1&sidx=&sord=asc");
|
| Line 287... |
Line 189... |
| 287 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
189 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
| 288 |
"Item ID : " +this.item.getId() +"\n"+
|
190 |
"Item ID : " +this.item.getId() +"\n"+
|
| 289 |
"SUPC : " +this.supc +"\n"+
|
191 |
"SUPC : " +this.supc +"\n"+
|
| 290 |
"Updated Price : " +this.price;
|
192 |
"Updated Price : " +this.price;
|
| 291 |
try{
|
193 |
try{
|
| 292 |
if(voiUpdation){
|
- |
|
| 293 |
mailer.sendSSLMessage(sendTo, "Price updated on Snapdeal VOI ( Item ID " + this.item.getId()+ " )",text, emailFromAddress , password,new ArrayList<File>());
|
- |
|
| 294 |
}else{
|
- |
|
| 295 |
mailer.sendSSLMessage(sendTo, "Price updated on Snapdeal ( Item ID " + this.item.getId()+ " )",text, emailFromAddress , password,new ArrayList<File>());
|
194 |
mailer.sendSSLMessage(sendTo, "Price updated on Snapdeal ( Item ID " + this.item.getId()+ " )",text, emailFromAddress , password,new ArrayList<File>());
|
| 296 |
}
|
- |
|
| 297 |
}
|
195 |
}
|
| 298 |
catch(Exception e){
|
196 |
catch(Exception e){
|
| 299 |
logger.info("Exception"+e);
|
197 |
logger.info("Exception"+e);
|
| 300 |
}
|
198 |
}
|
| 301 |
ArrayList<Long> updateList = new ArrayList<Long>();
|
199 |
ArrayList<Long> updateList = new ArrayList<Long>();
|
| Line 323... |
Line 221... |
| 323 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
221 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
| 324 |
"Item ID : " +this.item.getId() +"\n"+
|
222 |
"Item ID : " +this.item.getId() +"\n"+
|
| 325 |
"SUPC : " +this.supc +"\n"+
|
223 |
"SUPC : " +this.supc +"\n"+
|
| 326 |
"Updated Price : " +this.price;
|
224 |
"Updated Price : " +this.price;
|
| 327 |
try {
|
225 |
try {
|
| 328 |
if(voiUpdation){
|
- |
|
| 329 |
mailer.sendSSLMessage(sendTo, "Failed to update Price on Snapdeal VOI ( Item ID " + this.item.getId()+" )",text, emailFromAddress , password,new ArrayList<File>());
|
- |
|
| 330 |
}else{
|
- |
|
| 331 |
mailer.sendSSLMessage(sendTo, "Failed to update Price on Snapdeal ( Item ID " + this.item.getId()+" )",text, emailFromAddress , password,new ArrayList<File>());
|
226 |
mailer.sendSSLMessage(sendTo, "Failed to update Price on Snapdeal ( Item ID " + this.item.getId()+" )",text, emailFromAddress , password,new ArrayList<File>());
|
| 332 |
}
|
- |
|
| 333 |
} catch (MessagingException e1) {
|
227 |
} catch (MessagingException e1) {
|
| 334 |
e1.printStackTrace();
|
228 |
e1.printStackTrace();
|
| 335 |
logger.info("Exception" + e1);
|
229 |
logger.info("Exception" + e1);
|
| 336 |
}
|
230 |
}
|
| 337 |
|
231 |
|