Subversion Repositories SmartDukaan

Rev

Rev 10342 | Rev 11267 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10342 Rev 10859
Line 42... Line 42...
42
	//public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
42
	//public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
43
	private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
43
	private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
44
	public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
44
	public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
45
			"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",
46
			"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"};
47
	 public String emailFromAddress = "build@shop2020.in";
47
	public String emailFromAddress = "build@shop2020.in";
48
	 public String password = "cafe@nes";
48
	public String password = "cafe@nes";
49
	 public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
49
	public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
50
		 logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
50
		logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
51
		 this.price = price;
51
		this.price = price;
52
		 this.supc = supc;
52
		this.supc = supc;
53
		 this.item = item;
53
		this.item = item;
54
		 this.timestamp = timestamp; 
54
		this.timestamp = timestamp; 
55
	 }
55
	}
56
	 public UpdateSDPricingUsingPanel() {
56
	public UpdateSDPricingUsingPanel() {
57
	 }
57
	}
58
	 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{
59
		 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);
60
		 UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
60
		UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
61
		 logger.info("Calling Thread to update price at snapdeal");
61
		logger.info("Calling Thread to update price at snapdeal");
62
		 updatePriceOnSnapdeal.start();	
62
		updatePriceOnSnapdeal.start();	
63
 
63
 
64
	 }
64
	}
65
	 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{
66
		 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());
67
		 HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
67
		HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
68
		 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
68
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
69
		 nameValuePairs.add(new BasicNameValuePair("sellingPrice",
69
		nameValuePairs.add(new BasicNameValuePair("sellingPrice",
70
				 String.valueOf(price.intValue())));
70
				String.valueOf(price.intValue())));
71
		 nameValuePairs.add(new BasicNameValuePair("id",
71
		nameValuePairs.add(new BasicNameValuePair("id",
72
				 supc));
72
				supc));
73
		 nameValuePairs.add(new BasicNameValuePair("oper","edit"));
73
		nameValuePairs.add(new BasicNameValuePair("oper","edit"));
74
		 post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
74
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
75
		 HttpResponse response = httpClient.execute(post);
75
		HttpResponse response = httpClient.execute(post);
76
		 BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
76
		BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
77
		 String line = "";
77
		String line = "";
78
		 while ((line = rd.readLine()) != null) {
78
		while ((line = rd.readLine()) != null) {
79
			 System.out.println(line);
79
			System.out.println(line);
80
		 }
80
		}
81
		 return 1;
81
		return 1;
82
	 }
82
	}
83
 
83
 
84
	 public void handleLogin() throws ClientProtocolException, IOException{
84
	public void handleLogin() throws ClientProtocolException, IOException{
85
		 logger.info("----Inside Handle Login ----" );
85
		logger.info("----Inside Handle Login ----" );
86
		 HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
86
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
87
		 HttpResponse response = null;
87
		HttpResponse response = null;
88
		 try {
88
		boolean retry = true;
89
			 response = httpClient.execute(get);
89
		while(retry){
90
		 } catch (ClientProtocolException e) {
90
			try {
91
			 e.printStackTrace();
91
				response = httpClient.execute(get);
92
			 logger.error("Exception ",e);
92
				retry = false;
93
		 } catch (IOException e) {
93
			} catch (ClientProtocolException e) {
94
			 e.printStackTrace();
94
				e.printStackTrace();
95
			 logger.info("Exception " + e);
95
				logger.error("Exception ",e);
96
		 }
96
			} catch (IOException e) {
97
		 BufferedReader rd = null;
97
				e.printStackTrace();
98
		 try {
98
				logger.info("Exception " + e);
99
			 rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
99
			}
100
		 } catch (IllegalStateException e1) {
100
		}
101
			 e1.printStackTrace();
101
		BufferedReader rd = null;
102
		 } catch (IOException e1) {
102
		try {
103
			 e1.printStackTrace();
103
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
104
		 }
104
		} catch (IllegalStateException e1) {
105
		 String line = "";
105
			e1.printStackTrace();
106
		 StringBuffer sb = new StringBuffer();
106
		} catch (IOException e1) {
107
		 try {
107
			e1.printStackTrace();
108
			 while ((line = rd.readLine()) != null) {
108
		}
109
				 sb.append(line);
109
		String line = "";
110
			 }
110
		StringBuffer sb = new StringBuffer();
111
		 } catch (IOException e) {
111
		try {
112
			 e.printStackTrace();
112
			while ((line = rd.readLine()) != null) {
113
		 }
113
				sb.append(line);
114
		 int i= sb.toString().indexOf("name=\"lt\" value=");
114
			}
115
		 char[] charArray = sb.toString().toCharArray();
115
		} catch (IOException e) {
116
		 String lt = "";
116
			e.printStackTrace();
117
		 int j=0;
117
		}
118
		 for(j=i+16;j<=charArray.length;j++){
118
		int i= sb.toString().indexOf("name=\"lt\" value=");
119
 
119
		char[] charArray = sb.toString().toCharArray();
120
			 if(charArray[j]==' '){
120
		String lt = "";
121
				 break;
121
		int j=0;
122
			 }
122
		for(j=i+16;j<=charArray.length;j++){
123
		 }
123
 
124
		 lt = sb.substring(i+17,j-1);
124
			if(charArray[j]==' '){
125
		 System.out.println("LT VALUE " + lt);
125
				break;
126
		 i= sb.toString().indexOf("name=\"execution\" value=");
126
			}
127
		 charArray = sb.toString().toCharArray();
127
		}
128
		 String ex = "";
128
		lt = sb.substring(i+17,j-1);
129
		 j=0;
129
		System.out.println("LT VALUE " + lt);
130
		 for(j=i+24;j<=charArray.length;j++){
130
		i= sb.toString().indexOf("name=\"execution\" value=");
131
			 if(charArray[j]==' '){
131
		charArray = sb.toString().toCharArray();
132
				 break;
132
		String ex = "";
133
			 }
133
		j=0;
134
		 }
134
		for(j=i+24;j<=charArray.length;j++){
135
		 ex = sb.substring(i+24,j-1);
135
			if(charArray[j]==' '){
136
		 System.out.println("EXECUTION VALUE " + ex);
136
				break;
137
		 HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
137
			}
138
		 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
138
		}
139
		 nameValuePairs.add(new BasicNameValuePair("username",
139
		ex = sb.substring(i+24,j-1);
140
		 "saholic-snapdeal@saholic.com"));
140
		System.out.println("EXECUTION VALUE " + ex);
141
		 nameValuePairs.add(new BasicNameValuePair("password",
141
		HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
142
		 "bc452ce4"));
142
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
143
		 nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
143
		nameValuePairs.add(new BasicNameValuePair("username",
144
		 nameValuePairs.add(new BasicNameValuePair("execution",ex));
144
		"saholic-snapdeal@saholic.com"));
145
		 nameValuePairs.add(new BasicNameValuePair("lt",lt));
145
		nameValuePairs.add(new BasicNameValuePair("password",
146
		 nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
146
		"bc452ce4"));
147
		 post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
147
		nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
148
		 response = httpClient.execute(post);
148
		nameValuePairs.add(new BasicNameValuePair("execution",ex));
149
		 rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
149
		nameValuePairs.add(new BasicNameValuePair("lt",lt));
150
		 line = "";
150
		nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
151
		 while ((line = rd.readLine()) != null) {
151
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
152
			 System.out.println(line);
152
		response = httpClient.execute(post);
153
		 }
153
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
154
		 get = new HttpGet("http://seller.snapdeal.com/pricing");
154
		line = "";
155
		 response = httpClient.execute(get);
155
		while ((line = rd.readLine()) != null) {
156
		 rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
156
			System.out.println(line);
157
		 while ((line = rd.readLine()) != null) {
157
		}
158
			 //System.out.println(line);
158
		get = new HttpGet("http://seller.snapdeal.com/pricing");
159
		 }
159
		response = httpClient.execute(get);
160
		 logger.info("----Login Successful----" );
160
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
161
	 }
161
		while ((line = rd.readLine()) != null) {
162
	 public void run()
162
			//System.out.println(line);
163
	 {
163
		}
164
		 try {
164
		logger.info("----Login Successful----" );
165
			 this.handleLogin();
165
	}
166
			 this.updatePricing(this.price,this.supc,this.item,timestamp);
166
	public void run()
167
			 boolean retry =true;
167
	{
168
			 while(retry){
168
		try {
169
				 Thread.sleep(2*60*1000);
169
			this.handleLogin();
170
				 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");
170
			this.updatePricing(this.price,this.supc,this.item,timestamp);
171
				 HttpResponse response = httpClient.execute(get);
171
			boolean retry =true;
172
				 BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
172
			while(retry){
173
				 String line = "";
173
				Thread.sleep(2*60*1000);
174
				 while ((line = rd.readLine()) != null) {
174
				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");
175
					 logger.info(line);
175
				HttpResponse response = httpClient.execute(get);
176
					 if(line.contains("\"pendingUpdate\":false")){
176
				BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
177
						 retry =false;
177
				String line = "";
178
					 }
178
				while ((line = rd.readLine()) != null) {
179
				 }
179
					logger.info(line);
180
			 }
180
					if(line.contains("\"pendingUpdate\":false")){
181
			 GmailUtils mailer = new GmailUtils();
181
						retry =false;
182
			 String text = "Product : " +getProductName(this.item) +"\n"+ 
182
					}
183
			 "Item ID : " +this.item.getId() +"\n"+
183
				}
184
			 "SUPC : " +this.supc +"\n"+
184
			}
185
			 "Updated Price : " +this.price;
185
			GmailUtils mailer = new GmailUtils();
186
			 try{
186
			String text = "Product : " +getProductName(this.item) +"\n"+ 
187
			 mailer.sendSSLMessage(sendTo, "Price updated on Snapdeal ( Item ID " + this.item.getId()+ " )",text, emailFromAddress , password,new ArrayList<File>());
187
			"Item ID : " +this.item.getId() +"\n"+
188
			 }
188
			"SUPC : " +this.supc +"\n"+
189
			 catch(Exception e){
189
			"Updated Price : " +this.price;
190
				 logger.info("Exception"+e);
190
			try{
191
			 }
191
				mailer.sendSSLMessage(sendTo, "Price updated on Snapdeal ( Item ID " + this.item.getId()+ " )",text, emailFromAddress , password,new ArrayList<File>());
192
			 ArrayList<Long> updateList = new ArrayList<Long>();
192
			}
193
			 try {
193
			catch(Exception e){
194
				 Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
194
				logger.info("Exception"+e);
195
 
195
			}
196
				 updateList.add(this.item.getId());
196
			ArrayList<Long> updateList = new ArrayList<Long>();
197
				 catalogClient.updateMarketPlacePriceUpdateStatus(updateList,this.timestamp,OrderSource.SNAPDEAL.getValue());
197
			try {
198
			 } catch (TException e) {
198
				Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
199
				 try {
199
 
200
					 new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().updateMarketPlacePriceUpdateStatus(updateList, timestamp,OrderSource.SNAPDEAL.getValue());
200
				updateList.add(this.item.getId());
201
				 } catch (TTransportException e1) {
201
				catalogClient.updateMarketPlacePriceUpdateStatus(updateList,this.timestamp,OrderSource.SNAPDEAL.getValue());
202
					 e1.printStackTrace();
202
			} catch (TException e) {
203
					 logger.info("Exception" + e1);
203
				try {
204
				 } catch (TException e1) {
204
					new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().updateMarketPlacePriceUpdateStatus(updateList, timestamp,OrderSource.SNAPDEAL.getValue());
205
					 e1.printStackTrace();
205
				} catch (TTransportException e1) {
206
					 logger.info("Exception" + e1);
206
					e1.printStackTrace();
207
				 }
207
					logger.info("Exception" + e1);
208
				 logger.info("Exception" + e);
208
				} catch (TException e1) {
209
			 }
209
					e1.printStackTrace();
210
		 } catch (Exception e) {
210
					logger.info("Exception" + e1);
211
			 e.printStackTrace();
211
				}
212
			 //logger.error("Exception" + e);
212
				logger.info("Exception" + e);
213
			 GmailUtils mailer = new GmailUtils();
213
			}
214
			 String text = "Product       : " +getProductName(this.item) +"\n"+ 
214
		} catch (Exception e) {
215
			 "Item ID       : " +this.item.getId() +"\n"+
215
			e.printStackTrace();
216
			 "SUPC          : " +this.supc +"\n"+
216
			//logger.error("Exception" + e);
217
			 "Updated Price : " +this.price;
217
			GmailUtils mailer = new GmailUtils();
218
			 try {
218
			String text = "Product       : " +getProductName(this.item) +"\n"+ 
219
				 mailer.sendSSLMessage(sendTo, "Failed to update Price on Snapdeal ( Item ID " + this.item.getId()+" )",text, emailFromAddress , password,new ArrayList<File>());
219
			"Item ID       : " +this.item.getId() +"\n"+
220
			 } catch (MessagingException e1) {
220
			"SUPC          : " +this.supc +"\n"+
221
				 e1.printStackTrace();
221
			"Updated Price : " +this.price;
222
				 logger.info("Exception" + e1);
222
			try {
223
			 }
223
				mailer.sendSSLMessage(sendTo, "Failed to update Price on Snapdeal ( Item ID " + this.item.getId()+" )",text, emailFromAddress , password,new ArrayList<File>());
224
 
224
			} catch (MessagingException e1) {
225
		 } 
225
				e1.printStackTrace();
226
	 }
226
				logger.info("Exception" + e1);
227
	 String getProductName(Item item){
227
			}
228
		 return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor()); 
228
 
229
 
229
		} 
230
	 }
230
	}
231
	 String getName(String name){
231
	String getProductName(Item item){
232
		 if(name==null || name.length()==0){
232
		return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor()); 
233
			 return "";
233
 
234
		 }
234
	}
235
		 else{
235
	String getName(String name){
236
			 return name;
236
		if(name==null || name.length()==0){
237
		 }
237
			return "";
238
	 }
238
		}
-
 
239
		else{
-
 
240
			return name;
-
 
241
		}
-
 
242
	}
239
 
243
 
240
 
244
 
241
}
245
}