Subversion Repositories SmartDukaan

Rev

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

Rev 15223 Rev 15587
Line 26... Line 26...
26
import in.shop2020.thrift.clients.CatalogClient;
26
import in.shop2020.thrift.clients.CatalogClient;
27
import in.shop2020.thrift.clients.InventoryClient;
27
import in.shop2020.thrift.clients.InventoryClient;
28
import in.shop2020.thrift.clients.PaymentClient;
28
import in.shop2020.thrift.clients.PaymentClient;
29
import in.shop2020.thrift.clients.TransactionClient;
29
import in.shop2020.thrift.clients.TransactionClient;
30
import in.shop2020.thrift.clients.UserClient;
30
import in.shop2020.thrift.clients.UserClient;
-
 
31
import in.shop2020.utils.FlipkartConsumer;
31
import in.shop2020.utils.GmailUtils;
32
import in.shop2020.utils.GmailUtils;
32
 
33
 
33
import java.io.BufferedReader;
34
import java.io.BufferedReader;
34
import java.io.File;
35
import java.io.File;
35
import java.io.FileWriter;
36
import java.io.FileWriter;
Line 52... Line 53...
52
import org.apache.http.client.ClientProtocolException;
53
import org.apache.http.client.ClientProtocolException;
53
import org.apache.http.client.HttpClient;
54
import org.apache.http.client.HttpClient;
54
import org.apache.http.client.entity.UrlEncodedFormEntity;
55
import org.apache.http.client.entity.UrlEncodedFormEntity;
55
import org.apache.http.client.methods.HttpGet;
56
import org.apache.http.client.methods.HttpGet;
56
import org.apache.http.client.methods.HttpPost;
57
import org.apache.http.client.methods.HttpPost;
-
 
58
import org.apache.http.entity.mime.Header;
57
import org.apache.http.impl.client.DefaultHttpClient;
59
import org.apache.http.impl.client.DefaultHttpClient;
58
import org.apache.http.message.BasicNameValuePair;
60
import org.apache.http.message.BasicNameValuePair;
59
import org.apache.thrift.TException;
61
import org.apache.thrift.TException;
60
import org.apache.thrift.transport.TTransportException;
62
import org.apache.thrift.transport.TTransportException;
61
import org.json.JSONArray;
63
import org.json.JSONArray;
Line 80... Line 82...
80
	private static final int SNAPDEAL_SOURCE_ID = 7;
82
	private static final int SNAPDEAL_SOURCE_ID = 7;
81
	private static String transactionId;
83
	private static String transactionId;
82
	private static long paymentId;
84
	private static long paymentId;
83
	private static final int SNAPDEAL_GATEWAY_ID = 18;
85
	private static final int SNAPDEAL_GATEWAY_ID = 18;
84
	
86
	
-
 
87
	private static Map<String, String> headers = new HashMap<String, String>();
-
 
88
	
-
 
89
	static{
-
 
90
		headers.put("User-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11");
-
 
91
		headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
-
 
92
		headers.put("Accept-Language", "en-US,en;q=0.8");
-
 
93
		headers.put("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
-
 
94
	}
-
 
95
	
-
 
96
	/*
85
	public static void handleLogin() throws ClientProtocolException, IOException{
97
	public static void handleLogin() throws ClientProtocolException, IOException{
86
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
98
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
87
		HttpResponse response = null;
99
		HttpResponse response = null;
88
		try {
100
		try {
89
			response = client.execute(get);
101
			response = client.execute(get);
Line 166... Line 178...
166
				System.out.println(line);
178
				System.out.println(line);
167
			}
179
			}
168
		} catch (Exception e) {
180
		} catch (Exception e) {
169
			logger.error("Unable to extract Http Response for snapdeal seller portal login", e);
181
			logger.error("Unable to extract Http Response for snapdeal seller portal login", e);
170
		}
182
		}
171
	}
183
	}*/
172
	
184
	
173
	@SuppressWarnings("unchecked")
185
	@SuppressWarnings("unchecked")
174
	public static void fetchOrders() throws IllegalStateException, IOException, JSONException{
186
	public static void fetchOrders() throws IllegalStateException, IOException, JSONException{
175
		List<SnapdealOrderUnit> snapdealOrderUnitsList = new ArrayList<SnapdealOrderUnit>();
187
		List<SnapdealOrderUnit> snapdealOrderUnitsList = new ArrayList<SnapdealOrderUnit>();
176
		Map<String, SnapdealOrderUnit> snapdealOrderUnitListMap = new HashMap<String, SnapdealOrderUnit>();
188
		Map<String, SnapdealOrderUnit> snapdealOrderUnitListMap = new HashMap<String, SnapdealOrderUnit>();
177
		Map<String, Long> pendingSkuMap = new HashMap<String, Long>();
189
		Map<String, Long> pendingSkuMap = new HashMap<String, Long>();
178
		String pendingOrderSummaryUrl = "http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/pendingOrders/40?fulfillmentModelCode=ONESHIP";
190
		String pendingOrderSummaryUrl = "http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/pendingOrders/40?fulfillmentModelCode=ONESHIP";
-
 
191
		String cookie = "";
179
		HttpGet get = new HttpGet(pendingOrderSummaryUrl);
192
		HttpGet get = new HttpGet(pendingOrderSummaryUrl);
180
		
-
 
-
 
193
		for(String key:headers.keySet())
-
 
194
			get.addHeader(key, headers.get(key));
-
 
195
		get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
181
		HttpResponse response = null;
196
		HttpResponse response = null;
182
		Gson gson = new Gson();
197
		Gson gson = new Gson();
183
		BufferedReader rd= null;
198
		BufferedReader rd= null;
184
		String line = "";
199
		String line = "";
185
		try {
200
		try {
Line 195... Line 210...
195
		while((line=rd.readLine())!=null){
210
		while((line=rd.readLine())!=null){
196
			
211
			
197
		}
212
		}
198
		
213
		
199
		get = new HttpGet("http://shipping.snapdeal.com/json/vendor/ONESHIP/product-shipment/pendingOrders/PFF/ALL/pending");
214
		get = new HttpGet("http://shipping.snapdeal.com/json/vendor/ONESHIP/product-shipment/pendingOrders/PFF/ALL/pending");
-
 
215
		for(String key:headers.keySet())
-
 
216
			get.addHeader(key, headers.get(key));
-
 
217
		get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
200
		
218
		
201
		response = null;
219
		response = null;
202
		
220
		
203
		try {
221
		try {
204
			response = client.execute(get);
222
			response = client.execute(get);
Line 236... Line 254...
236
		
254
		
237
		productCodeToParse= URLEncoder.encode(productCodeToParse.toString(),"UTF-8"); 
255
		productCodeToParse= URLEncoder.encode(productCodeToParse.toString(),"UTF-8"); 
238
		pendingQuantityToParse = URLEncoder.encode(pendingQuantityToParse.toString(),"UTF-8"); 
256
		pendingQuantityToParse = URLEncoder.encode(pendingQuantityToParse.toString(),"UTF-8"); 
239
		
257
		
240
		get = new HttpGet("http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/pendingOrders/PFF/fetch?statusCode=PFF&packCategory=ALL&productCode="+productCodeToParse+"&maxPackagesToFetch="+pendingQuantityToParse+"&oneshipCenter=");
258
		get = new HttpGet("http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/pendingOrders/PFF/fetch?statusCode=PFF&packCategory=ALL&productCode="+productCodeToParse+"&maxPackagesToFetch="+pendingQuantityToParse+"&oneshipCenter=");
-
 
259
		for(String key:headers.keySet())
-
 
260
			get.addHeader(key, headers.get(key));
-
 
261
		get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
241
		
262
		
242
		response = null;
263
		response = null;
243
		
264
		
244
		try {
265
		try {
245
			response = client.execute(get);
266
			response = client.execute(get);
Line 264... Line 285...
264
			shipmentIdsToParse = shipmentIdsToParse + orderUnit.getSiId() + ",";
285
			shipmentIdsToParse = shipmentIdsToParse + orderUnit.getSiId() + ",";
265
			snapdealOrderUnitListMap.put(orderUnit.getSlpCode()+orderUnit.getSuborderCode(), orderUnit);
286
			snapdealOrderUnitListMap.put(orderUnit.getSlpCode()+orderUnit.getSuborderCode(), orderUnit);
266
		}
287
		}
267
		
288
		
268
		get = new HttpGet("http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/invoicedetails/VENDOR_READY?selectedShipments="+shipmentIdsToParse);
289
		get = new HttpGet("http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/invoicedetails/VENDOR_READY?selectedShipments="+shipmentIdsToParse);
-
 
290
		for(String key:headers.keySet())
-
 
291
			get.addHeader(key, headers.get(key));
-
 
292
		get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
269
		
293
		
270
		response = null;
294
		response = null;
271
		
295
		
272
		try {
296
		try {
273
			response = client.execute(get);
297
			response = client.execute(get);
Line 319... Line 343...
319
		}
343
		}
320
		processSnapdealOrders(snapdealOrderUnitsList);
344
		processSnapdealOrders(snapdealOrderUnitsList);
321
	}
345
	}
322
	public static void main(String[] args) {
346
	public static void main(String[] args) {
323
		try {
347
		try {
324
			handleLogin();
348
			//handleLogin();
325
			fetchOrders();
349
			fetchOrders();
326
		} catch (ClientProtocolException e2) {
350
		} catch (ClientProtocolException e2) {
327
			System.out.println("Handle login failed");
351
			System.out.println("Handle login failed");
328
			e2.printStackTrace();
352
			e2.printStackTrace();
329
		} catch (IOException e2) {
353
		} catch (IOException e2) {