| Line 28... |
Line 28... |
| 28 |
import org.apache.thrift.transport.TTransportException;
|
28 |
import org.apache.thrift.transport.TTransportException;
|
| 29 |
import org.slf4j.Logger;
|
29 |
import org.slf4j.Logger;
|
| 30 |
import org.slf4j.LoggerFactory;
|
30 |
import org.slf4j.LoggerFactory;
|
| 31 |
|
31 |
|
| 32 |
public class UpdateSDPricingUsingPanel extends Thread{
|
32 |
public class UpdateSDPricingUsingPanel extends Thread{
|
| 33 |
private static DefaultHttpClient client = new DefaultHttpClient();
|
33 |
private DefaultHttpClient client;
|
| 34 |
private Float price;
|
34 |
private Float price;
|
| 35 |
private String supc;
|
35 |
private String supc;
|
| 36 |
private Item item;
|
36 |
private Item item;
|
| 37 |
private Long timestamp;
|
37 |
private Long timestamp;
|
| 38 |
public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
|
38 |
public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
|
| 39 |
private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
|
39 |
private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
|
| 40 |
/*public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
40 |
/*public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
| 41 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
41 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
| 42 |
"yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in"};
|
42 |
"yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in"};
|
| 43 |
*/public String emailFromAddress = "build@shop2020.in";
|
43 |
*/public String emailFromAddress = "build@shop2020.in";
|
| 44 |
public String password = "cafe@nes";
|
44 |
public String password = "cafe@nes";
|
| 45 |
public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
|
45 |
public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
|
| 46 |
logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
|
46 |
logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
|
| 47 |
this.price = price;
|
47 |
this.price = price;
|
| 48 |
this.supc = supc;
|
48 |
this.supc = supc;
|
| 49 |
this.item = item;
|
49 |
this.item = item;
|
| 50 |
this.timestamp = timestamp;
|
50 |
this.timestamp = timestamp;
|
| 51 |
}
|
51 |
}
|
| 52 |
public UpdateSDPricingUsingPanel() {
|
52 |
public UpdateSDPricingUsingPanel() {
|
| 53 |
}
|
53 |
}
|
| 54 |
public static void main(String... args) throws ClientProtocolException, IOException{
|
54 |
public static void main(String... args) throws ClientProtocolException, IOException{
|
| 55 |
UpdateSDPricingUsingPanel UDSI = new UpdateSDPricingUsingPanel();
|
55 |
UpdateSDPricingUsingPanel UDSI = new UpdateSDPricingUsingPanel();
|
| 56 |
//UDSI.updatePricing(10131f,"SDL668125910","");
|
56 |
//UDSI.updatePricing(10131f,"SDL668125910","");
|
| 57 |
|
57 |
|
| 58 |
}
|
58 |
}
|
| 59 |
int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
|
59 |
int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
|
| 60 |
logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
|
60 |
logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
|
| 61 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
|
61 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
|
| 62 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
62 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
| 63 |
nameValuePairs.add(new BasicNameValuePair("sellingPrice",
|
63 |
nameValuePairs.add(new BasicNameValuePair("sellingPrice",
|
| 64 |
String.valueOf(price)));
|
64 |
String.valueOf(price)));
|
| 65 |
nameValuePairs.add(new BasicNameValuePair("id",
|
65 |
nameValuePairs.add(new BasicNameValuePair("id",
|
| 66 |
supc));
|
66 |
supc));
|
| 67 |
nameValuePairs.add(new BasicNameValuePair("oper","edit"));
|
67 |
nameValuePairs.add(new BasicNameValuePair("oper","edit"));
|
| 68 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
68 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
| 69 |
HttpResponse response = client.execute(post);
|
69 |
HttpResponse response = client.execute(post);
|
| 70 |
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
70 |
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 71 |
String line = "";
|
71 |
String line = "";
|
| 72 |
while ((line = rd.readLine()) != null) {
|
72 |
while ((line = rd.readLine()) != null) {
|
| 73 |
System.out.println(line);
|
73 |
System.out.println(line);
|
| 74 |
}
|
74 |
}
|
| 75 |
return 1;
|
75 |
return 1;
|
| 76 |
}
|
76 |
}
|
| 77 |
|
77 |
|
| 78 |
public void handleLogin() throws ClientProtocolException, IOException{
|
78 |
public void handleLogin() throws ClientProtocolException, IOException{
|
| 79 |
logger.info("----Inside Handle Login ----" );
|
79 |
logger.info("----Inside Handle Login ----" );
|
| 80 |
HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
|
80 |
HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
|
| 81 |
HttpResponse response = null;
|
81 |
HttpResponse response = null;
|
| 82 |
try {
|
82 |
client = new DefaultHttpClient();
|
| 83 |
response = client.execute(get);
|
83 |
try {
|
| 84 |
} catch (ClientProtocolException e) {
|
84 |
response = client.execute(get);
|
| 85 |
e.printStackTrace();
|
85 |
} catch (ClientProtocolException e) {
|
| 86 |
} catch (IOException e) {
|
86 |
e.printStackTrace();
|
| 87 |
e.printStackTrace();
|
87 |
} catch (IOException e) {
|
| 88 |
}
|
88 |
e.printStackTrace();
|
| 89 |
BufferedReader rd = null;
|
89 |
}
|
| 90 |
try {
|
90 |
BufferedReader rd = null;
|
| 91 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
91 |
try {
|
| 92 |
} catch (IllegalStateException e1) {
|
92 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 93 |
e1.printStackTrace();
|
93 |
} catch (IllegalStateException e1) {
|
| 94 |
} catch (IOException e1) {
|
94 |
e1.printStackTrace();
|
| 95 |
e1.printStackTrace();
|
95 |
} catch (IOException e1) {
|
| 96 |
}
|
96 |
e1.printStackTrace();
|
| 97 |
String line = "";
|
97 |
}
|
| 98 |
StringBuffer sb = new StringBuffer();
|
98 |
String line = "";
|
| 99 |
try {
|
99 |
StringBuffer sb = new StringBuffer();
|
| 100 |
while ((line = rd.readLine()) != null) {
|
100 |
try {
|
| 101 |
sb.append(line);
|
101 |
while ((line = rd.readLine()) != null) {
|
| 102 |
}
|
102 |
sb.append(line);
|
| 103 |
} catch (IOException e) {
|
103 |
}
|
| 104 |
e.printStackTrace();
|
104 |
} catch (IOException e) {
|
| 105 |
}
|
105 |
e.printStackTrace();
|
| 106 |
int i= sb.toString().indexOf("name=\"lt\" value=");
|
106 |
}
|
| 107 |
char[] charArray = sb.toString().toCharArray();
|
107 |
int i= sb.toString().indexOf("name=\"lt\" value=");
|
| 108 |
String lt = "";
|
108 |
char[] charArray = sb.toString().toCharArray();
|
| 109 |
int j=0;
|
109 |
String lt = "";
|
| 110 |
for(j=i+16;j<=charArray.length;j++){
|
110 |
int j=0;
|
| 111 |
|
111 |
for(j=i+16;j<=charArray.length;j++){
|
| 112 |
if(charArray[j]==' '){
|
112 |
|
| 113 |
break;
|
113 |
if(charArray[j]==' '){
|
| 114 |
}
|
114 |
break;
|
| 115 |
}
|
115 |
}
|
| 116 |
lt = sb.substring(i+17,j-1);
|
116 |
}
|
| 117 |
System.out.println("LT VALUE " + lt);
|
117 |
lt = sb.substring(i+17,j-1);
|
| 118 |
i= sb.toString().indexOf("name=\"execution\" value=");
|
118 |
System.out.println("LT VALUE " + lt);
|
| 119 |
charArray = sb.toString().toCharArray();
|
119 |
i= sb.toString().indexOf("name=\"execution\" value=");
|
| 120 |
String ex = "";
|
120 |
charArray = sb.toString().toCharArray();
|
| 121 |
j=0;
|
121 |
String ex = "";
|
| 122 |
for(j=i+24;j<=charArray.length;j++){
|
122 |
j=0;
|
| 123 |
if(charArray[j]==' '){
|
123 |
for(j=i+24;j<=charArray.length;j++){
|
| 124 |
break;
|
124 |
if(charArray[j]==' '){
|
| 125 |
}
|
125 |
break;
|
| 126 |
}
|
126 |
}
|
| 127 |
ex = sb.substring(i+24,j-1);
|
127 |
}
|
| 128 |
System.out.println("EXECUTION VALUE " + ex);
|
128 |
ex = sb.substring(i+24,j-1);
|
| 129 |
HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
129 |
System.out.println("EXECUTION VALUE " + ex);
|
| 130 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
130 |
HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
| 131 |
//nameValuePairs.add(new BasicNameValuePair("username",
|
131 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
| 132 |
//"khushal.bhatia@saholic.com"));
|
132 |
nameValuePairs.add(new BasicNameValuePair("username",
|
| 133 |
nameValuePairs.add(new BasicNameValuePair("username",
|
133 |
"saholic-snapdeal@saholic.com"));
|
| 134 |
"saholic-snapdeal@saholic.com"));
|
134 |
nameValuePairs.add(new BasicNameValuePair("password",
|
| 135 |
//nameValuePairs.add(new BasicNameValuePair("password",
|
135 |
"bc452ce4"));
|
| 136 |
//"sonline"));
|
136 |
nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
|
| 137 |
nameValuePairs.add(new BasicNameValuePair("password",
|
137 |
nameValuePairs.add(new BasicNameValuePair("execution",ex));
|
| 138 |
"bc452ce4"));
|
138 |
nameValuePairs.add(new BasicNameValuePair("lt",lt));
|
| 139 |
nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
|
139 |
nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
|
| 140 |
nameValuePairs.add(new BasicNameValuePair("execution",ex));
|
140 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
| 141 |
nameValuePairs.add(new BasicNameValuePair("lt",lt));
|
141 |
response = client.execute(post);
|
| 142 |
nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
|
142 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 143 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
143 |
line = "";
|
| 144 |
response = client.execute(post);
|
144 |
while ((line = rd.readLine()) != null) {
|
| 145 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
145 |
System.out.println(line);
|
| 146 |
line = "";
|
146 |
}
|
| 147 |
while ((line = rd.readLine()) != null) {
|
147 |
get = new HttpGet("http://seller.snapdeal.com/pricing");
|
| 148 |
System.out.println(line);
|
148 |
response = client.execute(get);
|
| 149 |
}
|
149 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 150 |
get = new HttpGet("http://seller.snapdeal.com/pricing/");
|
150 |
while ((line = rd.readLine()) != null) {
|
| 151 |
response = client.execute(get);
|
151 |
//System.out.println(line);
|
| 152 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
152 |
}
|
| 153 |
while ((line = rd.readLine()) != null) {
|
153 |
logger.info("----Login Successful----" );
|
| 154 |
//System.out.println(line);
|
154 |
}
|
| 155 |
}
|
155 |
public void run()
|
| 156 |
logger.info("Login Successful");
|
156 |
{
|
| 157 |
}
|
157 |
try {
|
| 158 |
public void run()
|
158 |
this.handleLogin();
|
| 159 |
{
|
159 |
this.updatePricing(this.price,this.supc,this.item,timestamp);
|
| 160 |
try {
|
160 |
GmailUtils mailer = new GmailUtils();
|
| 161 |
this.handleLogin();
|
161 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
| 162 |
this.updatePricing(this.price,this.supc,this.item,timestamp);
|
162 |
"Item ID : " +this.item.getId() +"\n"+
|
| 163 |
GmailUtils mailer = new GmailUtils();
|
163 |
"SUPC : " +this.supc +"\n"+
|
| 164 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
164 |
"Updated Price : " +this.price;
|
| 165 |
"Item ID : " +this.item.getId() +"\n"+
|
165 |
mailer.sendSSLMessage(sendTo, "Price updated on Snapdeal Item ID " + this.item.getId(),text, emailFromAddress , password,new ArrayList<File>());
|
| 166 |
"SUPC : " +this.supc +"\n"+
|
166 |
ArrayList<Long> updateList = new ArrayList<Long>();
|
| 167 |
"Updated Price : " +this.price;
|
167 |
try {
|
| 168 |
mailer.sendSSLMessage(sendTo, "Price updated on Snapdeal Item ID " + this.item.getId(),text, emailFromAddress , password,new ArrayList<File>());
|
168 |
Client catalogClient = new CatalogClient().getClient();
|
| 169 |
ArrayList<Long> updateList = new ArrayList<Long>();
|
169 |
|
| 170 |
try {
|
170 |
updateList.add(this.item.getId());
|
| 171 |
Client catalogClient = new CatalogClient().getClient();
|
171 |
catalogClient.updateMarketPlacePriceUpdateStatus(updateList,this.timestamp,7L);
|
| 172 |
|
172 |
} catch (TException e) {
|
| 173 |
updateList.add(this.item.getId());
|
173 |
try {
|
| 174 |
catalogClient.updateMarketPlacePriceUpdateStatus(updateList,this.timestamp,7L);
|
174 |
new CatalogClient().getClient().updateMarketPlacePriceUpdateStatus(updateList, timestamp,8);
|
| 175 |
} catch (TException e) {
|
175 |
} catch (TTransportException e1) {
|
| 176 |
try {
|
176 |
e1.printStackTrace();
|
| 177 |
new CatalogClient().getClient().updateMarketPlacePriceUpdateStatus(updateList, timestamp,8);
|
177 |
} catch (TException e1) {
|
| 178 |
} catch (TTransportException e1) {
|
178 |
e1.printStackTrace();
|
| 179 |
e1.printStackTrace();
|
179 |
}
|
| 180 |
} catch (TException e1) {
|
180 |
e.printStackTrace();
|
| 181 |
e1.printStackTrace();
|
181 |
}
|
| 182 |
}
|
182 |
} catch (Exception e) {
|
| 183 |
e.printStackTrace();
|
183 |
e.printStackTrace();
|
| 184 |
}
|
184 |
GmailUtils mailer = new GmailUtils();
|
| 185 |
} catch (Exception e) {
|
185 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
| 186 |
e.printStackTrace();
|
186 |
"Item ID : " +this.item.getId() +"\n"+
|
| 187 |
GmailUtils mailer = new GmailUtils();
|
187 |
"SUPC : " +this.supc +"\n"+
|
| 188 |
String text = "Product : " +getProductName(this.item) +"\n"+
|
188 |
"Updated Price : " +this.price;
|
| 189 |
"Item ID : " +this.item.getId() +"\n"+
|
189 |
try {
|
| 190 |
"SUPC : " +this.supc +"\n"+
|
190 |
mailer.sendSSLMessage(sendTo, "Failed to update Price on Snapdeal Item ID " + this.item.getId(),text, emailFromAddress , password,new ArrayList<File>());
|
| 191 |
"Updated Price : " +this.price;
|
191 |
} catch (MessagingException e1) {
|
| 192 |
try {
|
192 |
e1.printStackTrace();
|
| 193 |
mailer.sendSSLMessage(sendTo, "Failed to update Price on Snapdeal Item ID " + this.item.getId(),text, emailFromAddress , password,new ArrayList<File>());
|
193 |
}
|
| 194 |
} catch (MessagingException e1) {
|
194 |
|
| 195 |
e1.printStackTrace();
|
195 |
}
|
| 196 |
}
|
196 |
}
|
| 197 |
|
197 |
String getProductName(Item item){
|
| 198 |
}
|
198 |
return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor());
|
| 199 |
}
|
199 |
|
| 200 |
String getProductName(Item item){
|
200 |
}
|
| 201 |
return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor());
|
201 |
String getName(String name){
|
| 202 |
|
202 |
if(name==null || name.length()==0){
|
| 203 |
}
|
203 |
return "";
|
| 204 |
String getName(String name){
|
204 |
}
|
| 205 |
if(name==null || name.length()==0){
|
205 |
else{
|
| 206 |
return "";
|
206 |
return name;
|
| 207 |
}
|
207 |
}
|
| 208 |
else{
|
208 |
}
|
| 209 |
return name;
|
- |
|
| 210 |
}
|
- |
|
| 211 |
}
|
- |
|
| 212 |
|
209 |
|
| 213 |
|
210 |
|
| 214 |
}
|
211 |
}
|