| Line 14... |
Line 14... |
| 14 |
import in.shop2020.model.v1.order.OrderStatus;
|
14 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 15 |
import in.shop2020.model.v1.order.OrderType;
|
15 |
import in.shop2020.model.v1.order.OrderType;
|
| 16 |
import in.shop2020.model.v1.order.SnapdealOrder;
|
16 |
import in.shop2020.model.v1.order.SnapdealOrder;
|
| 17 |
import in.shop2020.model.v1.order.SourceDetail;
|
17 |
import in.shop2020.model.v1.order.SourceDetail;
|
| 18 |
import in.shop2020.model.v1.order.Transaction;
|
18 |
import in.shop2020.model.v1.order.Transaction;
|
| - |
|
19 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| 19 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
20 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 20 |
import in.shop2020.model.v1.order.TransactionStatus;
|
21 |
import in.shop2020.model.v1.order.TransactionStatus;
|
| 21 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
- |
|
| 22 |
import in.shop2020.model.v1.user.User;
|
22 |
import in.shop2020.model.v1.user.User;
|
| 23 |
import in.shop2020.payments.PaymentException;
|
23 |
import in.shop2020.payments.PaymentException;
|
| 24 |
import in.shop2020.payments.PaymentStatus;
|
24 |
import in.shop2020.payments.PaymentStatus;
|
| 25 |
import in.shop2020.serving.model.OrderItems;
|
25 |
import in.shop2020.serving.services.SnapdealSessionCookie;
|
| 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;
|
- |
|
| 32 |
import in.shop2020.utils.GmailUtils;
|
31 |
import in.shop2020.utils.GmailUtils;
|
| 33 |
|
32 |
|
| 34 |
import java.io.BufferedReader;
|
33 |
import java.io.BufferedReader;
|
| 35 |
import java.io.File;
|
34 |
import java.io.File;
|
| 36 |
import java.io.FileWriter;
|
35 |
import java.io.FileWriter;
|
| 37 |
import java.io.IOException;
|
36 |
import java.io.IOException;
|
| 38 |
import java.io.InputStreamReader;
|
37 |
import java.io.InputStreamReader;
|
| 39 |
import java.net.URLEncoder;
|
38 |
import java.net.URLEncoder;
|
| 40 |
import java.text.ParseException;
|
- |
|
| 41 |
import java.text.SimpleDateFormat;
|
- |
|
| 42 |
import java.util.ArrayList;
|
39 |
import java.util.ArrayList;
|
| 43 |
import java.util.Calendar;
|
40 |
import java.util.Calendar;
|
| 44 |
import java.util.Collections;
|
41 |
import java.util.Collections;
|
| 45 |
import java.util.Date;
|
42 |
import java.util.Date;
|
| 46 |
import java.util.GregorianCalendar;
|
43 |
import java.util.GregorianCalendar;
|
| 47 |
import java.util.HashMap;
|
44 |
import java.util.HashMap;
|
| 48 |
import java.util.List;
|
45 |
import java.util.List;
|
| 49 |
import java.util.Map;
|
46 |
import java.util.Map;
|
| 50 |
|
47 |
|
| 51 |
import org.apache.http.HttpResponse;
|
48 |
import org.apache.http.HttpResponse;
|
| 52 |
import org.apache.http.NameValuePair;
|
- |
|
| 53 |
import org.apache.http.client.ClientProtocolException;
|
49 |
import org.apache.http.client.ClientProtocolException;
|
| 54 |
import org.apache.http.client.HttpClient;
|
- |
|
| 55 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
- |
|
| 56 |
import org.apache.http.client.methods.HttpGet;
|
50 |
import org.apache.http.client.methods.HttpGet;
|
| 57 |
import org.apache.http.client.methods.HttpPost;
|
- |
|
| 58 |
import org.apache.http.entity.mime.Header;
|
- |
|
| 59 |
import org.apache.http.impl.client.DefaultHttpClient;
|
51 |
import org.apache.http.impl.client.DefaultHttpClient;
|
| 60 |
import org.apache.http.message.BasicNameValuePair;
|
- |
|
| 61 |
import org.apache.thrift.TException;
|
52 |
import org.apache.thrift.TException;
|
| 62 |
import org.apache.thrift.transport.TTransportException;
|
53 |
import org.apache.thrift.transport.TTransportException;
|
| 63 |
import org.json.JSONArray;
|
54 |
import org.json.JSONArray;
|
| 64 |
import org.json.JSONException;
|
55 |
import org.json.JSONException;
|
| 65 |
import org.json.JSONObject;
|
56 |
import org.json.JSONObject;
|
| 66 |
import org.slf4j.Logger;
|
57 |
import org.slf4j.Logger;
|
| 67 |
import org.slf4j.LoggerFactory;
|
58 |
import org.slf4j.LoggerFactory;
|
| 68 |
|
59 |
|
| - |
|
60 |
import utilities.SnapdealOrderUnit;
|
| - |
|
61 |
import utilities.VendorPendingOrderSkuDetail;
|
| - |
|
62 |
import utilities.VendorPendingProductOfferDisplayDTO;
|
| 69 |
import au.com.bytecode.opencsv.CSVReader;
|
63 |
import au.com.bytecode.opencsv.CSVReader;
|
| 70 |
import au.com.bytecode.opencsv.CSVWriter;
|
64 |
import au.com.bytecode.opencsv.CSVWriter;
|
| 71 |
|
65 |
|
| 72 |
import com.google.gson.Gson;
|
66 |
import com.google.gson.Gson;
|
| 73 |
|
67 |
|
| 74 |
import utilities.SnapdealOrderUnit;
|
- |
|
| 75 |
import utilities.VendorPendingOrderSkuDetail;
|
- |
|
| 76 |
import utilities.VendorPendingProductOfferDisplayDTO;
|
- |
|
| 77 |
|
- |
|
| 78 |
public class SnapdealOrderCreator{
|
68 |
public class SnapdealOrderCreator{
|
| 79 |
private static DefaultHttpClient client = new DefaultHttpClient();
|
69 |
private static DefaultHttpClient client = new DefaultHttpClient();
|
| 80 |
private static Logger logger = LoggerFactory.getLogger(SnapdealOrderCreator.class);
|
70 |
private static Logger logger = LoggerFactory.getLogger(SnapdealOrderCreator.class);
|
| 81 |
private static List<VendorPendingProductOfferDisplayDTO> pendingOrdersSkuList = new ArrayList<VendorPendingProductOfferDisplayDTO> ();
|
71 |
private static List<VendorPendingProductOfferDisplayDTO> pendingOrdersSkuList = new ArrayList<VendorPendingProductOfferDisplayDTO> ();
|
| 82 |
private static final int SNAPDEAL_SOURCE_ID = 7;
|
72 |
private static final int SNAPDEAL_SOURCE_ID = 7;
|
| Line 91... |
Line 81... |
| 91 |
headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
81 |
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");
|
82 |
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");
|
83 |
headers.put("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
|
| 94 |
}
|
84 |
}
|
| 95 |
|
85 |
|
| 96 |
/*
|
- |
|
| 97 |
public static void handleLogin() throws ClientProtocolException, IOException{
|
- |
|
| 98 |
HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
|
- |
|
| 99 |
HttpResponse response = null;
|
- |
|
| 100 |
try {
|
- |
|
| 101 |
response = client.execute(get);
|
- |
|
| 102 |
} catch (Exception e) {
|
- |
|
| 103 |
e.printStackTrace();
|
- |
|
| 104 |
}
|
- |
|
| 105 |
|
- |
|
| 106 |
BufferedReader rd = null;
|
- |
|
| 107 |
try {
|
- |
|
| 108 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 109 |
} catch (Exception e1) {
|
- |
|
| 110 |
e1.printStackTrace();
|
- |
|
| 111 |
}
|
- |
|
| 112 |
String line = "";
|
- |
|
| 113 |
StringBuffer sb = new StringBuffer();
|
- |
|
| 114 |
try {
|
- |
|
| 115 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 116 |
sb.append(line);
|
- |
|
| 117 |
//System.out.println(line);
|
- |
|
| 118 |
}
|
- |
|
| 119 |
} catch (IOException e) {
|
- |
|
| 120 |
e.printStackTrace();
|
- |
|
| 121 |
}
|
- |
|
| 122 |
int i= sb.toString().indexOf("name=\"lt\" value=");
|
- |
|
| 123 |
char[] charArray = sb.toString().toCharArray();
|
- |
|
| 124 |
String lt = "";
|
- |
|
| 125 |
int j=0;
|
- |
|
| 126 |
for(j=i+16;j<=charArray.length;j++){
|
- |
|
| 127 |
|
- |
|
| 128 |
if(charArray[j]==' '){
|
- |
|
| 129 |
break;
|
- |
|
| 130 |
}
|
- |
|
| 131 |
}
|
- |
|
| 132 |
lt = sb.substring(i+17,j-1);
|
- |
|
| 133 |
System.out.println("LT VALUE " + lt);
|
- |
|
| 134 |
i= sb.toString().indexOf("name=\"execution\" value=");
|
- |
|
| 135 |
charArray = sb.toString().toCharArray();
|
- |
|
| 136 |
|
- |
|
| 137 |
String ex = "";
|
- |
|
| 138 |
j=0;
|
- |
|
| 139 |
for(j=i+24;j<=charArray.length;j++){
|
- |
|
| 140 |
if(charArray[j]==' '){
|
- |
|
| 141 |
break;
|
- |
|
| 142 |
}
|
- |
|
| 143 |
}
|
- |
|
| 144 |
ex = sb.substring(i+24,j-1);
|
- |
|
| 145 |
System.out.println("EXECUTION VALUE " + ex);
|
- |
|
| 146 |
|
- |
|
| 147 |
|
- |
|
| 148 |
HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fshipping.snapdeal.com%2Fj_spring_cas_security_check");
|
- |
|
| 149 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
- |
|
| 150 |
//nameValuePairs.add(new BasicNameValuePair("username",
|
- |
|
| 151 |
//"khushal.bhatia@saholic.com"));
|
- |
|
| 152 |
nameValuePairs.add(new BasicNameValuePair("username",
|
- |
|
| 153 |
"saholic-snapdeal@saholic.com"));
|
- |
|
| 154 |
//nameValuePairs.add(new BasicNameValuePair("password",
|
- |
|
| 155 |
//"sonline"));
|
- |
|
| 156 |
nameValuePairs.add(new BasicNameValuePair("password",
|
- |
|
| 157 |
"saholic15"));
|
- |
|
| 158 |
nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
|
- |
|
| 159 |
nameValuePairs.add(new BasicNameValuePair("execution",ex));
|
- |
|
| 160 |
nameValuePairs.add(new BasicNameValuePair("lt",lt));
|
- |
|
| 161 |
nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
|
- |
|
| 162 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
- |
|
| 163 |
//response = null;
|
- |
|
| 164 |
try {
|
- |
|
| 165 |
response = client.execute(post);
|
- |
|
| 166 |
} catch (Exception e) {
|
- |
|
| 167 |
logger.error("Unable to get Http Response for snapdeal seller portal login", e);
|
- |
|
| 168 |
}
|
- |
|
| 169 |
|
- |
|
| 170 |
try {
|
- |
|
| 171 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 172 |
} catch (Exception e1) {
|
- |
|
| 173 |
logger.error("Unable to read Http Response for snapdeal seller portal login", e1);
|
- |
|
| 174 |
}
|
- |
|
| 175 |
|
- |
|
| 176 |
try {
|
- |
|
| 177 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 178 |
System.out.println(line);
|
- |
|
| 179 |
}
|
- |
|
| 180 |
} catch (Exception e) {
|
- |
|
| 181 |
logger.error("Unable to extract Http Response for snapdeal seller portal login", e);
|
- |
|
| 182 |
}
|
- |
|
| 183 |
}*/
|
- |
|
| 184 |
|
- |
|
| 185 |
@SuppressWarnings("unchecked")
|
86 |
@SuppressWarnings("unchecked")
|
| 186 |
public static void fetchOrders() throws IllegalStateException, IOException, JSONException{
|
87 |
public static void fetchOrders() throws Exception{
|
| 187 |
List<SnapdealOrderUnit> snapdealOrderUnitsList = new ArrayList<SnapdealOrderUnit>();
|
88 |
List<SnapdealOrderUnit> snapdealOrderUnitsList = new ArrayList<SnapdealOrderUnit>();
|
| 188 |
Map<String, SnapdealOrderUnit> snapdealOrderUnitListMap = new HashMap<String, SnapdealOrderUnit>();
|
89 |
Map<String, SnapdealOrderUnit> snapdealOrderUnitListMap = new HashMap<String, SnapdealOrderUnit>();
|
| 189 |
Map<String, Long> pendingSkuMap = new HashMap<String, Long>();
|
90 |
Map<String, Long> pendingSkuMap = new HashMap<String, Long>();
|
| - |
|
91 |
SnapdealSessionCookie sdSessionCookie = new SnapdealSessionCookie();
|
| - |
|
92 |
String cookies = sdSessionCookie.getCookies();
|
| - |
|
93 |
JSONObject cookieObject = new JSONObject(cookies);
|
| 190 |
String pendingOrderSummaryUrl = "http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/pendingOrders/40?fulfillmentModelCode=ONESHIP";
|
94 |
String pendingOrderSummaryUrl = "http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/pendingOrders/40?fulfillmentModelCode=ONESHIP";
|
| 191 |
String cookie = "";
|
- |
|
| 192 |
HttpGet get = new HttpGet(pendingOrderSummaryUrl);
|
95 |
HttpGet get = new HttpGet(pendingOrderSummaryUrl);
|
| 193 |
for(String key:headers.keySet())
|
96 |
for(String key:headers.keySet())
|
| 194 |
get.addHeader(key, headers.get(key));
|
97 |
get.addHeader(key, headers.get(key));
|
| 195 |
get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
|
98 |
get.addHeader("Cookie","AWSELB="+cookieObject.get("AWSELB")+";JSESSIONID="+cookieObject.get("JSESSIONID")+";");
|
| - |
|
99 |
System.out.println(get.getAllHeaders().length);
|
| 196 |
HttpResponse response = null;
|
100 |
HttpResponse response = null;
|
| 197 |
Gson gson = new Gson();
|
101 |
Gson gson = new Gson();
|
| 198 |
BufferedReader rd= null;
|
102 |
BufferedReader rd= null;
|
| 199 |
String line = "";
|
103 |
String line = "";
|
| 200 |
try {
|
104 |
try {
|
| Line 206... |
Line 110... |
| 206 |
}
|
110 |
}
|
| 207 |
|
111 |
|
| 208 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
112 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 209 |
|
113 |
|
| 210 |
while((line=rd.readLine())!=null){
|
114 |
while((line=rd.readLine())!=null){
|
| 211 |
|
115 |
System.out.println(line);
|
| 212 |
}
|
116 |
}
|
| 213 |
|
117 |
|
| 214 |
get = new HttpGet("http://shipping.snapdeal.com/json/vendor/ONESHIP/product-shipment/pendingOrders/PFF/ALL/pending");
|
118 |
get = new HttpGet("http://shipping.snapdeal.com/json/vendor/ONESHIP/product-shipment/pendingOrders/PFF/ALL/pending");
|
| 215 |
for(String key:headers.keySet())
|
119 |
for(String key:headers.keySet())
|
| 216 |
get.addHeader(key, headers.get(key));
|
120 |
get.addHeader(key, headers.get(key));
|
| - |
|
121 |
cookies = sdSessionCookie.getCookies();
|
| - |
|
122 |
cookieObject = new JSONObject(cookies);
|
| 217 |
get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
|
123 |
get.addHeader("Cookie","AWSELB="+cookieObject.get("AWSELB")+";JSESSIONID="+cookieObject.get("JSESSIONID")+";");
|
| - |
|
124 |
|
| 218 |
|
125 |
|
| 219 |
response = null;
|
126 |
response = null;
|
| 220 |
|
127 |
|
| 221 |
try {
|
128 |
try {
|
| 222 |
response = client.execute(get);
|
129 |
response = client.execute(get);
|
| Line 228... |
Line 135... |
| 228 |
|
135 |
|
| 229 |
|
136 |
|
| 230 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
137 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 231 |
|
138 |
|
| 232 |
line = rd.readLine();
|
139 |
line = rd.readLine();
|
| - |
|
140 |
System.out.println(line);
|
| 233 |
|
141 |
|
| 234 |
|
142 |
|
| 235 |
JSONArray jsonArray = new JSONArray(line);
|
143 |
JSONArray jsonArray = new JSONArray(line);
|
| 236 |
for(int i=0; i<jsonArray.length(); i++){
|
144 |
for(int i=0; i<jsonArray.length(); i++){
|
| 237 |
VendorPendingOrderSkuDetail vendorPendingSku = (VendorPendingOrderSkuDetail)gson.fromJson(jsonArray.get(i).toString(),VendorPendingOrderSkuDetail.class);
|
145 |
VendorPendingOrderSkuDetail vendorPendingSku = (VendorPendingOrderSkuDetail)gson.fromJson(jsonArray.get(i).toString(),VendorPendingOrderSkuDetail.class);
|
| Line 256... |
Line 164... |
| 256 |
pendingQuantityToParse = URLEncoder.encode(pendingQuantityToParse.toString(),"UTF-8");
|
164 |
pendingQuantityToParse = URLEncoder.encode(pendingQuantityToParse.toString(),"UTF-8");
|
| 257 |
|
165 |
|
| 258 |
get = new HttpGet("http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/pendingOrders/PFF/fetch?statusCode=PFF&packCategory=ALL&productCode="+productCodeToParse+"&maxPackagesToFetch="+pendingQuantityToParse+"&oneshipCenter=");
|
166 |
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())
|
167 |
for(String key:headers.keySet())
|
| 260 |
get.addHeader(key, headers.get(key));
|
168 |
get.addHeader(key, headers.get(key));
|
| - |
|
169 |
cookies = sdSessionCookie.getCookies();
|
| - |
|
170 |
cookieObject = new JSONObject(cookies);
|
| 261 |
get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
|
171 |
get.addHeader("Cookie","AWSELB="+cookieObject.get("AWSELB")+";JSESSIONID="+cookieObject.get("JSESSIONID")+";");
|
| 262 |
|
172 |
|
| 263 |
response = null;
|
173 |
response = null;
|
| 264 |
|
174 |
|
| 265 |
try {
|
175 |
try {
|
| 266 |
response = client.execute(get);
|
176 |
response = client.execute(get);
|
| 267 |
} catch (ClientProtocolException e) {
|
177 |
} catch (ClientProtocolException e) {
|
| Line 287... |
Line 197... |
| 287 |
}
|
197 |
}
|
| 288 |
|
198 |
|
| 289 |
get = new HttpGet("http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/invoicedetails/VENDOR_READY?selectedShipments="+shipmentIdsToParse);
|
199 |
get = new HttpGet("http://shipping.snapdeal.com/vendor/ONESHIP/product-shipment/invoicedetails/VENDOR_READY?selectedShipments="+shipmentIdsToParse);
|
| 290 |
for(String key:headers.keySet())
|
200 |
for(String key:headers.keySet())
|
| 291 |
get.addHeader(key, headers.get(key));
|
201 |
get.addHeader(key, headers.get(key));
|
| - |
|
202 |
cookies = sdSessionCookie.getCookies();
|
| - |
|
203 |
cookieObject = new JSONObject(cookies);
|
| 292 |
get.addHeader("Cookie","SERVERID=s1;sfJSESSIONID=2A00C6B6C929B16511E35202A4DC10EB;");
|
204 |
get.addHeader("Cookie","AWSELB="+cookieObject.get("AWSELB")+";JSESSIONID="+cookieObject.get("JSESSIONID")+";");
|
| 293 |
|
205 |
|
| 294 |
response = null;
|
206 |
response = null;
|
| 295 |
|
207 |
|
| 296 |
try {
|
208 |
try {
|
| 297 |
response = client.execute(get);
|
209 |
response = client.execute(get);
|
| Line 355... |
Line 267... |
| 355 |
e2.printStackTrace();
|
267 |
e2.printStackTrace();
|
| 356 |
} catch (IllegalStateException e) {
|
268 |
} catch (IllegalStateException e) {
|
| 357 |
e.printStackTrace();
|
269 |
e.printStackTrace();
|
| 358 |
} catch (JSONException e) {
|
270 |
} catch (JSONException e) {
|
| 359 |
e.printStackTrace();
|
271 |
e.printStackTrace();
|
| - |
|
272 |
} catch (Exception e) {
|
| - |
|
273 |
e.printStackTrace();
|
| 360 |
}
|
274 |
}
|
| 361 |
}
|
275 |
}
|
| 362 |
|
276 |
|
| 363 |
public static void processSnapdealOrders(List<SnapdealOrderUnit> snapdealOrderUnitsList){
|
277 |
public static void processSnapdealOrders(List<SnapdealOrderUnit> snapdealOrderUnitsList){
|
| 364 |
SourceDetail sourceDetail = null;
|
278 |
SourceDetail sourceDetail = null;
|