| 8961 |
vikram.rag |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.Amazonlisted;
|
|
|
4 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
5 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
6 |
import in.shop2020.model.v1.catalog.Item;
|
| 8994 |
vikram.rag |
7 |
import in.shop2020.model.v1.catalog.SnapdealItem;
|
| 8961 |
vikram.rag |
8 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
9 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
|
|
10 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
11 |
import in.shop2020.model.v1.inventory.VendorItemPricing;
|
|
|
12 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
13 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
|
|
14 |
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
|
|
|
15 |
import in.shop2020.model.v1.order.FlipkartOrder;
|
|
|
16 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
17 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
18 |
import in.shop2020.model.v1.order.OrderType;
|
|
|
19 |
import in.shop2020.model.v1.order.SourceDetail;
|
|
|
20 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
21 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
22 |
import in.shop2020.model.v1.order.TransactionStatus;
|
|
|
23 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
24 |
import in.shop2020.model.v1.user.User;
|
|
|
25 |
import in.shop2020.payments.PaymentException;
|
|
|
26 |
import in.shop2020.payments.PaymentStatus;
|
|
|
27 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
28 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
29 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
30 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
31 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
32 |
import in.shop2020.thrift.clients.UserClient;
|
| 8995 |
vikram.rag |
33 |
import in.shop2020.utils.GmailUtils;
|
| 8961 |
vikram.rag |
34 |
|
|
|
35 |
import java.io.BufferedInputStream;
|
|
|
36 |
import java.io.BufferedReader;
|
|
|
37 |
import java.io.File;
|
|
|
38 |
import java.io.FileInputStream;
|
|
|
39 |
import java.io.FileNotFoundException;
|
|
|
40 |
import java.io.FileOutputStream;
|
|
|
41 |
import java.io.FileReader;
|
|
|
42 |
import java.io.FileWriter;
|
|
|
43 |
import java.io.IOException;
|
|
|
44 |
import java.io.InputStream;
|
|
|
45 |
import java.io.Writer;
|
|
|
46 |
import java.text.ParseException;
|
|
|
47 |
import java.text.SimpleDateFormat;
|
|
|
48 |
import java.util.ArrayList;
|
|
|
49 |
import java.util.Arrays;
|
|
|
50 |
import java.util.Calendar;
|
|
|
51 |
import java.util.Collections;
|
|
|
52 |
import java.util.Date;
|
| 8995 |
vikram.rag |
53 |
import java.util.GregorianCalendar;
|
| 8961 |
vikram.rag |
54 |
import java.util.HashMap;
|
|
|
55 |
import java.util.List;
|
|
|
56 |
import java.util.Map;
|
|
|
57 |
|
|
|
58 |
import javax.servlet.ServletContext;
|
|
|
59 |
import javax.servlet.ServletOutputStream;
|
|
|
60 |
import javax.servlet.http.HttpServletRequest;
|
|
|
61 |
import javax.servlet.http.HttpServletResponse;
|
|
|
62 |
import javax.servlet.http.HttpSession;
|
|
|
63 |
|
|
|
64 |
import org.apache.commons.io.FileUtils;
|
|
|
65 |
import org.apache.commons.lang.xwork.StringUtils;
|
|
|
66 |
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
67 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
68 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
69 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
70 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
71 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
72 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
73 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
74 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
75 |
import org.apache.thrift.TException;
|
|
|
76 |
import org.apache.thrift.transport.TTransportException;
|
|
|
77 |
import org.slf4j.Logger;
|
|
|
78 |
import org.slf4j.LoggerFactory;
|
|
|
79 |
|
|
|
80 |
import au.com.bytecode.opencsv.CSVReader;
|
|
|
81 |
|
|
|
82 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
83 |
|
|
|
84 |
public class FlipkartDashboardController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
|
|
|
85 |
private static Logger logger = LoggerFactory.getLogger(FlipkartDashboardController.class);
|
|
|
86 |
private static final int FLIPKART_SOURCE_ID = 8;
|
| 8963 |
vikram.rag |
87 |
private static final int FLIPKART_GATEWAY_ID = 17;
|
| 8962 |
vikram.rag |
88 |
private static final int FLIPKART_LOGISTICS_ID = 19;
|
| 8961 |
vikram.rag |
89 |
private HttpServletRequest request;
|
|
|
90 |
private HttpServletResponse response;
|
|
|
91 |
private HttpSession session;
|
|
|
92 |
private ServletContext context;
|
|
|
93 |
private String url;
|
|
|
94 |
private File file;
|
|
|
95 |
private String errMsg;
|
|
|
96 |
private String id;
|
| 9199 |
vikram.rag |
97 |
private long paymentId;
|
| 8961 |
vikram.rag |
98 |
private static String transactionId;
|
|
|
99 |
public String uploadorders(){
|
|
|
100 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
|
|
|
101 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
|
|
|
102 |
return "authfail";
|
|
|
103 |
}
|
|
|
104 |
return "flipkart-upload-orders";
|
|
|
105 |
}
|
|
|
106 |
public String show() {
|
|
|
107 |
logger.info("Before fetching role");
|
|
|
108 |
logger.info(request.getSession().toString());
|
|
|
109 |
logger.info(ReportsUtils.ROLE);
|
|
|
110 |
logger.info(session.getAttribute(ReportsUtils.ROLE).toString());
|
|
|
111 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
|
|
|
112 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
|
|
|
113 |
logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
|
|
|
114 |
return "authfail";
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
if (StringUtils.equals(id, "flipkart-options")){
|
|
|
118 |
return "flipkart-options";
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
return "id";
|
|
|
122 |
}
|
|
|
123 |
public void uploadOrdersFile() throws IOException, CatalogServiceException, TException{
|
|
|
124 |
File fileToCreate = new File("/tmp/", "Flipkart-Orders.csv");
|
|
|
125 |
FileUtils.copyFile(this.file, fileToCreate);
|
|
|
126 |
FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
|
|
|
127 |
CSVReader orderfilereader = null;
|
|
|
128 |
replacecommas(fileToCreate);
|
|
|
129 |
try {
|
|
|
130 |
orderfilereader = new CSVReader(new FileReader("/tmp/formatted.csv"),'$');
|
|
|
131 |
} catch (FileNotFoundException e) {
|
|
|
132 |
// TODO Auto-generated catch block
|
|
|
133 |
e.printStackTrace();
|
|
|
134 |
}
|
|
|
135 |
logger.info("Before Processing orders ");
|
|
|
136 |
String [] nextLine;
|
| 8971 |
vikram.rag |
137 |
StringBuffer sb = new StringBuffer();
|
| 8974 |
vikram.rag |
138 |
int orders_processed = 0;
|
| 9034 |
vikram.rag |
139 |
String order_string = "";
|
| 8961 |
vikram.rag |
140 |
try {
|
|
|
141 |
User user = null;
|
|
|
142 |
TransactionClient tsc = null;
|
|
|
143 |
SourceDetail sourceDetail = null;
|
|
|
144 |
logger.info("Before Fetching sourcedetail");
|
|
|
145 |
try {
|
|
|
146 |
tsc = new TransactionClient();
|
|
|
147 |
sourceDetail = tsc.getClient().getSourceDetail(FLIPKART_SOURCE_ID);
|
|
|
148 |
logger.info("Flipkart sourcedetail " + sourceDetail.getEmail() + " " + sourceDetail.getName());
|
|
|
149 |
} catch (Exception e) {
|
|
|
150 |
logger.error("Unable to establish connection to the transaction service while getting Flipkart Source Detail ", e);
|
|
|
151 |
}
|
|
|
152 |
try {
|
|
|
153 |
in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
|
|
|
154 |
logger.info("Before Fetching User by Email");
|
|
|
155 |
user = userClient.getUserByEmail(sourceDetail.getEmail());
|
|
|
156 |
logger.info("User is " + user.getEmail());
|
|
|
157 |
} catch (Exception e) {
|
|
|
158 |
logger.error("Unable to establish connection to the User service ", e);
|
|
|
159 |
}
|
|
|
160 |
logger.info("Before iterating orders in file");
|
| 8970 |
vikram.rag |
161 |
while ((nextLine = orderfilereader.readNext()) != null && nextLine.length!=0) {
|
| 8973 |
vikram.rag |
162 |
logger.info("Order file entry " + nextLine + " Length " + nextLine.length);
|
| 8961 |
vikram.rag |
163 |
String orderId,subOrderId,create_date;
|
|
|
164 |
long sku;
|
|
|
165 |
logger.info("Processing order " + nextLine[3]+ " " + nextLine[4]);
|
|
|
166 |
if(nextLine[3].length()==0 || nextLine[4].length()==0 ){
|
|
|
167 |
sb.append(" Could not parse order id " + nextLine[3]+ " " + nextLine[4] + "\n");
|
|
|
168 |
logger.info("Processing order " + nextLine[3]+ " " + nextLine[4]);
|
|
|
169 |
continue;
|
|
|
170 |
}
|
|
|
171 |
else{
|
|
|
172 |
orderId = nextLine[3];
|
|
|
173 |
subOrderId = nextLine[4];
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
if(nextLine[0].length()!=0){
|
|
|
177 |
create_date = nextLine[0];
|
|
|
178 |
}
|
|
|
179 |
else{
|
|
|
180 |
sb.append(orderId+" "+subOrderId + " Could not parse order date" +"\n");
|
|
|
181 |
logger.info(orderId+" "+subOrderId + " Could not parse order date");
|
|
|
182 |
continue;
|
| 8970 |
vikram.rag |
183 |
}
|
| 8961 |
vikram.rag |
184 |
if(nextLine[5].length()==0){
|
|
|
185 |
sb.append(orderId+" "+subOrderId + " Could not parse sku" +"\n");
|
|
|
186 |
logger.info(orderId+" "+subOrderId + " Could not parse sku");
|
|
|
187 |
continue;
|
|
|
188 |
}
|
|
|
189 |
else{
|
|
|
190 |
sku = Long.parseLong(nextLine[5]);
|
|
|
191 |
logger.info(orderId+" "+subOrderId + " Processing sku " + sku);
|
|
|
192 |
}
|
|
|
193 |
if(nextLine[6].length()!=0 && nextLine[6].equalsIgnoreCase("Approved")){
|
|
|
194 |
String status = nextLine[6];
|
|
|
195 |
}
|
|
|
196 |
else{
|
|
|
197 |
if(nextLine[6].length()==0){
|
| 9007 |
vikram.rag |
198 |
sb.append(orderId+" "+subOrderId + " Could not parse status" +"\n");
|
|
|
199 |
logger.info(orderId+" "+subOrderId + " Could not parse status" +"\n");
|
| 8961 |
vikram.rag |
200 |
}
|
| 9007 |
vikram.rag |
201 |
else{
|
| 9030 |
vikram.rag |
202 |
sb.append(orderId+" "+subOrderId + " Order not Approved" +"\n");
|
|
|
203 |
logger.info(orderId+" "+subOrderId + " Order not Approved" +"\n");
|
| 9007 |
vikram.rag |
204 |
}
|
| 8961 |
vikram.rag |
205 |
continue;
|
|
|
206 |
}
|
|
|
207 |
double unitSellingPrice,shippingPrice,octroiFee,emiFee;
|
|
|
208 |
if(nextLine[7].length()!=0 ){
|
|
|
209 |
if(Double.parseDouble(nextLine[7]) > 0){
|
|
|
210 |
unitSellingPrice = Double.parseDouble(nextLine[7]);
|
|
|
211 |
}
|
|
|
212 |
else{
|
|
|
213 |
sb.append(orderId+" "+subOrderId + " Unit Price set to 0 " +"\n");
|
|
|
214 |
logger.info(orderId+" "+subOrderId + " Unit Price set to 0 " +"\n");
|
|
|
215 |
continue;
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
else{
|
|
|
219 |
sb.append(orderId+" "+subOrderId + " Unit Price not set " +"\n");
|
|
|
220 |
logger.info(orderId+" "+subOrderId + " Unit Price not set " +"\n");
|
|
|
221 |
continue;
|
|
|
222 |
}
|
|
|
223 |
if(nextLine[8].length()!=0){
|
|
|
224 |
shippingPrice = Double.parseDouble(nextLine[8]);
|
| 9086 |
vikram.rag |
225 |
if(shippingPrice!=0){
|
|
|
226 |
sb.append(orderId+" "+subOrderId + " Shipping Fee :"+ shippingPrice +"\n");
|
|
|
227 |
logger.info(orderId+" "+subOrderId + " Shipping Fee :"+ shippingPrice +"\n");
|
|
|
228 |
}
|
| 8961 |
vikram.rag |
229 |
}
|
|
|
230 |
else{
|
|
|
231 |
shippingPrice=0;
|
|
|
232 |
}
|
|
|
233 |
if(nextLine[9].length()!=0){
|
|
|
234 |
octroiFee = Double.parseDouble(nextLine[9]);
|
|
|
235 |
if(octroiFee >0){
|
|
|
236 |
sb.append(orderId+" "+subOrderId + " OctroiFee :"+ octroiFee +"\n");
|
|
|
237 |
logger.info(orderId+" "+subOrderId + " OctroiFee :"+ octroiFee +"\n");
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
else{
|
|
|
241 |
octroiFee=0;
|
|
|
242 |
}
|
|
|
243 |
if(nextLine[10].length()!=0){
|
|
|
244 |
emiFee = Double.parseDouble(nextLine[10]);
|
|
|
245 |
if(emiFee >0){
|
|
|
246 |
sb.append(orderId+" "+subOrderId + " EMI :"+ emiFee +"\n");
|
|
|
247 |
logger.info(orderId+" "+subOrderId + " EMI :"+ emiFee +"\n");
|
|
|
248 |
}
|
|
|
249 |
}
|
|
|
250 |
else{
|
|
|
251 |
emiFee = 0;
|
|
|
252 |
}
|
|
|
253 |
int quantity;
|
|
|
254 |
if(nextLine[11].length()!=0){
|
|
|
255 |
quantity = Integer.parseInt(nextLine[11]);
|
|
|
256 |
if(quantity > 1){
|
| 9072 |
vikram.rag |
257 |
sb.append(orderId+" "+subOrderId + " Quantity > 1 " + quantity +"\n");
|
|
|
258 |
logger.info(orderId+" "+subOrderId + " Quantity > 1 " + quantity +"\n");
|
| 8961 |
vikram.rag |
259 |
}
|
|
|
260 |
else{
|
|
|
261 |
if(quantity==0){
|
| 9072 |
vikram.rag |
262 |
sb.append(orderId+" "+subOrderId + " Quantity not set " + quantity +"\n");
|
|
|
263 |
logger.info(orderId+" "+subOrderId + " Quantity not set " + quantity +"\n");
|
| 8961 |
vikram.rag |
264 |
continue;
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
}
|
|
|
268 |
else{
|
| 9072 |
vikram.rag |
269 |
sb.append(orderId+" "+subOrderId + " Quantity not set " + "\n");
|
|
|
270 |
logger.info(orderId+" "+subOrderId + " Quantity not set " + "\n");
|
| 8961 |
vikram.rag |
271 |
continue;
|
|
|
272 |
}
|
|
|
273 |
double totalsellingPrice;
|
|
|
274 |
if(nextLine[12].length()!=0){
|
|
|
275 |
totalsellingPrice= Double.parseDouble(nextLine[12]);
|
|
|
276 |
if(totalsellingPrice==0){
|
|
|
277 |
sb.append(orderId+" "+subOrderId + " Total Selling Price set to 0 " +"\n");
|
|
|
278 |
logger.info(orderId+" "+subOrderId + " Total Selling Price set to 0 " +"\n");
|
|
|
279 |
continue;
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
else{
|
|
|
283 |
sb.append(orderId+" "+subOrderId + " Total Selling Price not set " +"\n");
|
|
|
284 |
logger.info(orderId+" "+subOrderId + " Total Selling Price not set " +"\n");
|
|
|
285 |
continue;
|
|
|
286 |
}
|
| 9056 |
vikram.rag |
287 |
|
| 8973 |
vikram.rag |
288 |
String shipToName,addressLine1,addressLine2,city,state,pincode,buyerName="unknown";
|
|
|
289 |
if(nextLine[17].length()>0){
|
|
|
290 |
buyerName = nextLine[17];
|
|
|
291 |
}
|
|
|
292 |
else{
|
|
|
293 |
sb.append(orderId+" "+subOrderId + " Buyer Name not set " +"\n");
|
|
|
294 |
logger.info(orderId+" "+subOrderId + " Buyer Name not set " +"\n");
|
|
|
295 |
}
|
| 8961 |
vikram.rag |
296 |
if(nextLine[18].length()>0){
|
|
|
297 |
shipToName = nextLine[18];
|
|
|
298 |
}
|
|
|
299 |
else{
|
|
|
300 |
sb.append(orderId+" "+subOrderId + " Ship to Name not set " +"\n");
|
|
|
301 |
logger.info(orderId+" "+subOrderId + " Ship to Name not set " +"\n");
|
|
|
302 |
continue;
|
|
|
303 |
}
|
| 8973 |
vikram.rag |
304 |
if(buyerName.contains("unknown")){
|
| 9056 |
vikram.rag |
305 |
buyerName = shipToName;
|
|
|
306 |
}
|
| 8961 |
vikram.rag |
307 |
if(nextLine[19].length()>0){
|
|
|
308 |
addressLine1 = nextLine[19];
|
|
|
309 |
}
|
|
|
310 |
else{
|
|
|
311 |
addressLine1 ="";
|
|
|
312 |
}
|
|
|
313 |
if(nextLine[20].length()>0){
|
|
|
314 |
addressLine2 = nextLine[20];
|
|
|
315 |
}
|
|
|
316 |
else{
|
|
|
317 |
addressLine2 ="";
|
|
|
318 |
}
|
|
|
319 |
if(nextLine[21].length()>0){
|
|
|
320 |
city = nextLine[21];
|
|
|
321 |
}
|
|
|
322 |
else{
|
|
|
323 |
sb.append(orderId+" "+subOrderId + " City not set " +"\n");
|
|
|
324 |
logger.info(orderId+" "+subOrderId + " City not set " +"\n");
|
|
|
325 |
continue;
|
|
|
326 |
}
|
|
|
327 |
if(nextLine[22].length()>0){
|
|
|
328 |
state = nextLine[22];
|
|
|
329 |
}
|
|
|
330 |
else{
|
|
|
331 |
sb.append(orderId+" "+subOrderId + " State not set " +"\n");
|
|
|
332 |
logger.info(orderId+" "+subOrderId + " State not set " +"\n");
|
|
|
333 |
continue;
|
|
|
334 |
}
|
|
|
335 |
if(nextLine[23].length()>0){
|
|
|
336 |
pincode = nextLine[23];
|
|
|
337 |
}
|
|
|
338 |
else{
|
|
|
339 |
sb.append(orderId+" "+subOrderId + " Pincode not set " +"\n");
|
|
|
340 |
logger.info(orderId+" "+subOrderId + " Pincode not set " +"\n");
|
|
|
341 |
continue;
|
|
|
342 |
}
|
|
|
343 |
int sla;
|
|
|
344 |
if(nextLine[23].length()>0){
|
|
|
345 |
sla = Integer.parseInt(nextLine[24]);
|
|
|
346 |
}
|
|
|
347 |
else{
|
|
|
348 |
sb.append(orderId+" "+subOrderId + " Ship to date not available " +"\n");
|
|
|
349 |
logger.info(orderId+" "+subOrderId + " Ship to date not available " +"\n");
|
|
|
350 |
continue;
|
|
|
351 |
}
|
|
|
352 |
//String shipByDate = nextLine[26];
|
|
|
353 |
Client transaction_client = null;
|
|
|
354 |
try {
|
|
|
355 |
transaction_client = new TransactionClient().getClient();
|
|
|
356 |
if(transaction_client.flipkartOrderExists(orderId,subOrderId)) {
|
| 9016 |
vikram.rag |
357 |
logger.error("Flipkart order exists " + "id : " + orderId + " suborder id : " + subOrderId);
|
| 9031 |
vikram.rag |
358 |
sb.append("Flipkart order exists " + orderId+" "+subOrderId+"\n");
|
| 8961 |
vikram.rag |
359 |
continue;
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
} catch (TTransportException e1) {
|
|
|
363 |
logger.error("Problem with Transaction service " , e1);
|
|
|
364 |
e1.printStackTrace();
|
|
|
365 |
} catch (TException e) {
|
|
|
366 |
logger.error("Problem.. thrift exception with Transaction service " , e);
|
|
|
367 |
e.printStackTrace();
|
|
|
368 |
}
|
|
|
369 |
SimpleDateFormat istFormatter = new SimpleDateFormat("MMM dd, yyyy");
|
|
|
370 |
Date flipkartTxnDate = null;
|
|
|
371 |
try {
|
|
|
372 |
create_date = create_date.replaceAll("\"","");
|
|
|
373 |
flipkartTxnDate = istFormatter.parse(create_date);
|
|
|
374 |
} catch (ParseException e) {
|
|
|
375 |
logger.error(orderId+" "+subOrderId + " Could not parse flipkart order date from file " , e);
|
|
|
376 |
sb.append(orderId+" "+subOrderId + " Could not parse order date" +"\n");
|
|
|
377 |
continue;
|
|
|
378 |
}
|
|
|
379 |
Transaction txn = new Transaction();
|
|
|
380 |
txn.setShoppingCartid(user.getActiveCartId());
|
|
|
381 |
txn.setCustomer_id(user.getUserId());
|
|
|
382 |
System.out.println("User Id is " + user.getUserId());
|
|
|
383 |
txn.setCreatedOn(new Date().getTime());
|
|
|
384 |
txn.setTransactionStatus(TransactionStatus.INIT);
|
|
|
385 |
txn.setStatusDescription("Order for flipkart ");
|
|
|
386 |
List<in.shop2020.model.v1.order.Order> orderlist = new ArrayList<in.shop2020.model.v1.order.Order>();
|
|
|
387 |
double total_price=0;
|
|
|
388 |
InventoryService.Client inventoryClient = null;
|
|
|
389 |
Warehouse fulfillmentWarehouse= null;
|
| 9032 |
vikram.rag |
390 |
boolean exit = false;
|
| 9271 |
vikram.rag |
391 |
LineItem lineItem = null;
|
|
|
392 |
lineItem = createLineItem(sku,unitSellingPrice,quantity);
|
|
|
393 |
logger.info(orderId+" "+subOrderId + "sku and Price " + sku + " " + unitSellingPrice);
|
|
|
394 |
lineItem.setExtra_info("flipkartOrderId = " + orderId + " flipkartsubOrderId = " + subOrderId);
|
|
|
395 |
in.shop2020.model.v1.order.Order t_order = new in.shop2020.model.v1.order.Order();
|
|
|
396 |
t_order.setCustomer_id(user.getUserId());
|
|
|
397 |
t_order.setCustomer_email(sourceDetail.getEmail());
|
|
|
398 |
t_order.setCustomer_name(shipToName);
|
|
|
399 |
addressLine1 = addressLine1.replaceAll("\"","");
|
|
|
400 |
t_order.setCustomer_address1(addressLine1);
|
|
|
401 |
addressLine2 = addressLine2.replaceAll("\"","");
|
|
|
402 |
t_order.setCustomer_address2(addressLine2);
|
|
|
403 |
t_order.setCustomer_mobilenumber("+91-9999999999");
|
|
|
404 |
t_order.setCustomer_city(city);
|
|
|
405 |
t_order.setCustomer_state(state);
|
|
|
406 |
t_order.setCustomer_pincode(pincode);
|
| 9276 |
vikram.rag |
407 |
t_order.setTotal_amount(unitSellingPrice*quantity);
|
| 9271 |
vikram.rag |
408 |
t_order.setTotal_weight(lineItem.getTotal_weight());
|
|
|
409 |
t_order.setLineitems(Collections.singletonList(lineItem));
|
|
|
410 |
t_order.setStatus(OrderStatus.PAYMENT_PENDING);
|
|
|
411 |
t_order.setStatusDescription("In Process");
|
|
|
412 |
t_order.setCreated_timestamp(new Date().getTime());
|
|
|
413 |
t_order.setOrderType(OrderType.B2C);
|
|
|
414 |
t_order.setCod(false);
|
|
|
415 |
try {
|
|
|
416 |
Date shipDate = new Date();
|
|
|
417 |
shipDate.setTime( flipkartTxnDate.getTime() + sla*24*60*60*1000);
|
|
|
418 |
Calendar time = Calendar.getInstance();
|
|
|
419 |
t_order.setPromised_shipping_time(shipDate.getTime());
|
|
|
420 |
t_order.setExpected_shipping_time(shipDate.getTime());
|
|
|
421 |
time.add(Calendar.DAY_OF_MONTH, 4);
|
|
|
422 |
t_order.setPromised_delivery_time(time.getTimeInMillis());
|
|
|
423 |
t_order.setExpected_delivery_time(time.getTimeInMillis());
|
|
|
424 |
} catch(Exception e) {
|
|
|
425 |
logger.error("Error in updating Shipping or Delivery Time for suborderid " + subOrderId);
|
|
|
426 |
sb.append(orderId + " "+ subOrderId + " Could not update delivery time" + " " + "\n");
|
|
|
427 |
exit = true;
|
|
|
428 |
continue;
|
|
|
429 |
}
|
| 9273 |
vikram.rag |
430 |
//SnapdealItem snapdealItem = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().getSnapdealItem(sku);
|
|
|
431 |
SnapdealItem snapdealItem = new CatalogClient().getClient().getSnapdealItem(sku);
|
| 9271 |
vikram.rag |
432 |
inventoryClient = new InventoryClient().getClient();
|
|
|
433 |
try {
|
|
|
434 |
logger.info("Snapdeal Item id is " + snapdealItem.getItem_id());
|
|
|
435 |
if(snapdealItem.getItem_id()!=0 && snapdealItem.getWarehouseId()!=0) {
|
|
|
436 |
logger.info("SnapdealItem Warehouse Id " + snapdealItem.getWarehouseId());
|
|
|
437 |
fulfillmentWarehouse = inventoryClient.getWarehouse(snapdealItem.getWarehouseId());
|
|
|
438 |
logger.info("fulfillmentWarehouse is " + fulfillmentWarehouse.getId() + " " + fulfillmentWarehouse.getDisplayName() );
|
| 9056 |
vikram.rag |
439 |
|
| 9271 |
vikram.rag |
440 |
} else {
|
|
|
441 |
List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(sku, 1);
|
|
|
442 |
fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
|
|
|
443 |
if(fulfillmentWarehouse.getStateId()!=0){
|
|
|
444 |
fulfillmentWarehouse = inventoryClient.getWarehouse(7);
|
| 8961 |
vikram.rag |
445 |
}
|
| 9271 |
vikram.rag |
446 |
}
|
|
|
447 |
t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
|
|
|
448 |
long billingWarehouseId = 0;
|
|
|
449 |
if(fulfillmentWarehouse.getBillingWarehouseId()== 0) {
|
|
|
450 |
inventoryClient = new InventoryClient().getClient();
|
|
|
451 |
List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, fulfillmentWarehouse.getVendor().getId(), 0, 0);
|
|
|
452 |
for(Warehouse warehouse : warehouses) {
|
|
|
453 |
if(warehouse.getBillingWarehouseId()!=0) {
|
|
|
454 |
billingWarehouseId = warehouse.getBillingWarehouseId();
|
|
|
455 |
break;
|
| 8961 |
vikram.rag |
456 |
}
|
|
|
457 |
}
|
| 9271 |
vikram.rag |
458 |
}else {
|
|
|
459 |
billingWarehouseId = fulfillmentWarehouse.getBillingWarehouseId();
|
|
|
460 |
}
|
| 9056 |
vikram.rag |
461 |
|
| 9271 |
vikram.rag |
462 |
//logger.info("Billing warehouse id for suborderid " + order.getSuborderId() + " is " + fulfillmentWarehouse.getBillingWarehouseId());
|
|
|
463 |
t_order.setWarehouse_id(billingWarehouseId);
|
|
|
464 |
VendorItemPricing vendorItemPricing = new VendorItemPricing();
|
|
|
465 |
if(fulfillmentWarehouse.getId()==7) {
|
|
|
466 |
Item item = new CatalogClient().getClient().getItem(lineItem.getItem_id());
|
|
|
467 |
vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), item.getPreferredVendor());
|
|
|
468 |
} else {
|
|
|
469 |
vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
|
|
|
470 |
}
|
| 9056 |
vikram.rag |
471 |
|
| 9271 |
vikram.rag |
472 |
t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
|
|
|
473 |
t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
|
|
|
474 |
} catch (InventoryServiceException e) {
|
|
|
475 |
logger.error("Error connecting inventory service for suborderid " + orderId + " " + subOrderId , e);
|
|
|
476 |
sb.append(orderId + " " + subOrderId+ " Inventory Service Exception" + " " + "\n");
|
|
|
477 |
exit = true;
|
|
|
478 |
continue;
|
|
|
479 |
} catch (TTransportException e) {
|
|
|
480 |
logger.error("Transport Exception with Inventory Service for suborderid " + orderId + " " + subOrderId , e);
|
|
|
481 |
sb.append(orderId + " " + subOrderId + " Transport Exception with Inventory Service" + " " + "\n");
|
|
|
482 |
exit = true;
|
|
|
483 |
continue;
|
|
|
484 |
} catch (TException e) {
|
|
|
485 |
logger.error("Exception with Inventory Service for suborderid " + orderId + " " + subOrderId , e);
|
|
|
486 |
sb.append(orderId + " " + subOrderId + " Exception in Inventory Service" + " " + "\n");
|
|
|
487 |
exit = true;
|
|
|
488 |
continue;
|
|
|
489 |
} catch (CatalogServiceException e) {
|
|
|
490 |
logger.error("Exception with Catalog Service for " + orderId + " " + subOrderId + " while getting item " + lineItem.getItem_id(), e);
|
|
|
491 |
sb.append(orderId + " " + subOrderId + " Exception in Catalog Service" + " " + "\n");
|
|
|
492 |
exit = true;
|
|
|
493 |
continue;
|
| 8961 |
vikram.rag |
494 |
}
|
| 9271 |
vikram.rag |
495 |
t_order.setLogistics_provider_id(FLIPKART_LOGISTICS_ID);
|
|
|
496 |
t_order.setAirwaybill_no("");
|
|
|
497 |
t_order.setTracking_id("");
|
|
|
498 |
t_order.setOrderType(OrderType.B2C);
|
|
|
499 |
t_order.setSource(FLIPKART_SOURCE_ID);
|
|
|
500 |
t_order.setOrderType(OrderType.B2C);
|
|
|
501 |
total_price = unitSellingPrice*quantity;
|
|
|
502 |
orderlist.add(t_order);
|
| 9032 |
vikram.rag |
503 |
if(exit){
|
|
|
504 |
continue;
|
|
|
505 |
}
|
| 8961 |
vikram.rag |
506 |
txn.setOrders(orderlist);
|
|
|
507 |
try {
|
|
|
508 |
transactionId = String.valueOf(transaction_client.createTransaction(txn));
|
| 8965 |
vikram.rag |
509 |
logger.info("Transaction id is : " + transactionId);
|
| 8961 |
vikram.rag |
510 |
} catch (TransactionServiceException e) {
|
|
|
511 |
logger.error(orderId+" "+subOrderId + " Could not create transaction " , e);
|
|
|
512 |
sb.append(orderId+" "+subOrderId + " Could not create transaction" +"\n");
|
|
|
513 |
continue;
|
|
|
514 |
} catch (TException e) {
|
|
|
515 |
sb.append(orderId+" "+subOrderId + " Transaction Service Exception could not create transaction" +"\n");
|
|
|
516 |
logger.info(orderId+" "+subOrderId + " Transaction Service Exception could not create transaction" +"\n");
|
|
|
517 |
continue;
|
|
|
518 |
}
|
|
|
519 |
try{
|
| 8965 |
vikram.rag |
520 |
logger.info("Creating payment for suborder id " + subOrderId);
|
| 9199 |
vikram.rag |
521 |
paymentId = createPayment(user,subOrderId,total_price);
|
| 8961 |
vikram.rag |
522 |
}
|
|
|
523 |
catch (NumberFormatException e) {
|
|
|
524 |
logger.error("Could not create payment",e);
|
|
|
525 |
sb.append(orderId+" "+subOrderId + " Could not create payment");
|
|
|
526 |
e.printStackTrace();
|
|
|
527 |
continue;
|
|
|
528 |
} catch (PaymentException e) {
|
|
|
529 |
logger.error("Could not create payment payment exception",e);
|
|
|
530 |
sb.append(orderId+" "+subOrderId + " Could not create payment Payment exception");
|
|
|
531 |
e.printStackTrace();
|
|
|
532 |
continue;
|
|
|
533 |
} catch (TException e) {
|
|
|
534 |
logger.error("Could not create payment thrift exception",e);
|
|
|
535 |
sb.append(orderId+" "+subOrderId + " Could not create payment Thrift exception");
|
|
|
536 |
e.printStackTrace();
|
|
|
537 |
continue;
|
|
|
538 |
}
|
|
|
539 |
Transaction transaction = null;
|
|
|
540 |
try {
|
|
|
541 |
transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
|
|
|
542 |
} catch (NumberFormatException e) {
|
|
|
543 |
logger.error("Problem parsing transaction id " + transactionId);
|
|
|
544 |
sb.append(orderId+" "+subOrderId + " Problem parsing transaction id "+ transactionId +"\n");
|
|
|
545 |
e.printStackTrace();
|
|
|
546 |
continue;
|
|
|
547 |
} catch (TransactionServiceException e) {
|
|
|
548 |
logger.error("Problem getting transaction from service transaction id " + transactionId);
|
|
|
549 |
sb.append(orderId+" "+subOrderId + " Problem getting transaction id "+ transactionId +"\n");
|
|
|
550 |
e.printStackTrace();
|
|
|
551 |
continue;
|
|
|
552 |
} catch (TException e) {
|
|
|
553 |
logger.error("Problem with transaction service while getting transaction id " + transactionId);
|
|
|
554 |
sb.append(orderId+" "+subOrderId + " Problem with transaction service while getting transaction id "+ transactionId +"\n");
|
|
|
555 |
e.printStackTrace();
|
|
|
556 |
continue;
|
|
|
557 |
}
|
|
|
558 |
List<in.shop2020.model.v1.order.Order> flipkartorders = transaction.getOrders();
|
|
|
559 |
for(in.shop2020.model.v1.order.Order flipkartorder:flipkartorders){
|
|
|
560 |
try {
|
| 8973 |
vikram.rag |
561 |
List<in.shop2020.model.v1.order.Attribute> attributeList = new ArrayList<in.shop2020.model.v1.order.Attribute>();
|
| 8961 |
vikram.rag |
562 |
inventoryClient.reserveItemInWarehouse(flipkartorder.getLineitems().get(0).getItem_id(), fulfillmentWarehouse.getId(), 1,
|
|
|
563 |
flipkartorder.getId(), flipkartorder.getCreated_timestamp(), flipkartorder.getPromised_shipping_time(), flipkartorder.getLineitems().get(0).getQuantity());
|
|
|
564 |
FlipkartOrder flipkartOrder = new FlipkartOrder();
|
|
|
565 |
flipkartOrder.setOrderId(flipkartorder.getId());
|
|
|
566 |
flipkartOrder.setFlipkartOrderId(orderId);
|
|
|
567 |
flipkartOrder.setFlipkartSubOrderId(subOrderId);
|
|
|
568 |
flipkartOrder.setFlipkartTxnDate(flipkartTxnDate.getTime());
|
|
|
569 |
flipkartOrder.setEmiFee(emiFee);
|
|
|
570 |
flipkartOrder.setOctroiFee(octroiFee);
|
|
|
571 |
flipkartOrder.setShippingPrice(shippingPrice);
|
| 8973 |
vikram.rag |
572 |
in.shop2020.model.v1.order.Attribute attribute = new in.shop2020.model.v1.order.Attribute();
|
|
|
573 |
attribute.setName("Buyer Name");
|
|
|
574 |
attribute.setValue(buyerName);
|
|
|
575 |
attributeList.add(attribute);
|
| 8961 |
vikram.rag |
576 |
try {
|
|
|
577 |
transaction_client.createFlipkartOrder(flipkartOrder);
|
| 8973 |
vikram.rag |
578 |
transaction_client.setOrderAttributes(flipkartOrder.getOrderId(),attributeList);
|
| 9199 |
vikram.rag |
579 |
logger.info("transaction id : " + Long.valueOf(transactionId) + " Payment id : " + paymentId);
|
|
|
580 |
new PaymentClient().getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, subOrderId, null, PaymentStatus.SUCCESS, null, null);
|
| 8974 |
vikram.rag |
581 |
orders_processed++;
|
| 8961 |
vikram.rag |
582 |
} catch (TException e) {
|
|
|
583 |
logger.error("Could not create flipkart order");
|
|
|
584 |
sb.append(orderId+" "+subOrderId + " Could not create flipkart order"+"\n");
|
|
|
585 |
continue;
|
| 9199 |
vikram.rag |
586 |
}catch (PaymentException e) {
|
|
|
587 |
logger.error("Could not update flipkart order payment ",e);
|
|
|
588 |
sb.append(orderId+" "+subOrderId + " Could not update flipkart order payment"+"\n");
|
|
|
589 |
continue;
|
| 8961 |
vikram.rag |
590 |
}
|
|
|
591 |
|
|
|
592 |
} catch (InventoryServiceException e1) {
|
|
|
593 |
logger.error("Problem while reserving item in inventory service" + flipkartorder.getId());
|
|
|
594 |
sb.append(orderId+" "+subOrderId + " Could not reserve inventory for sku "+ sku +"\n");
|
|
|
595 |
continue;
|
|
|
596 |
} catch (TException e1) {
|
|
|
597 |
logger.error("Problem with inventory service" + flipkartorder.getId());
|
|
|
598 |
sb.append(orderId+" "+subOrderId + " Problem with inventory service while reserving inventory for sku "+ sku +"\n");
|
|
|
599 |
continue;
|
|
|
600 |
}
|
|
|
601 |
}
|
|
|
602 |
}
|
|
|
603 |
response.setHeader("Content-Type", "text/javascript");
|
| 9056 |
vikram.rag |
604 |
|
| 9034 |
vikram.rag |
605 |
if(orders_processed==1){
|
|
|
606 |
order_string = "Order";
|
|
|
607 |
}
|
|
|
608 |
else{
|
|
|
609 |
order_string = "Orders";
|
|
|
610 |
}
|
| 8961 |
vikram.rag |
611 |
|
|
|
612 |
ServletOutputStream sos;
|
|
|
613 |
try {
|
|
|
614 |
sos = response.getOutputStream();
|
| 9015 |
vikram.rag |
615 |
if(sb.toString().equalsIgnoreCase("")){
|
| 9034 |
vikram.rag |
616 |
sos.write((orders_processed + " " + order_string + " Created").toString().getBytes());
|
| 8968 |
vikram.rag |
617 |
}
|
|
|
618 |
else{
|
| 9056 |
vikram.rag |
619 |
sos.write((orders_processed +" " + order_string + " Created \n"+ sb.toString()).getBytes());
|
| 8968 |
vikram.rag |
620 |
}
|
| 8961 |
vikram.rag |
621 |
sos.flush();
|
|
|
622 |
} catch (IOException e) {
|
|
|
623 |
System.out.println("Unable to stream the manifest file");
|
|
|
624 |
}
|
|
|
625 |
|
|
|
626 |
}
|
|
|
627 |
catch (FileNotFoundException e) {
|
|
|
628 |
// TODO Auto-generated catch block
|
|
|
629 |
e.printStackTrace();
|
|
|
630 |
}
|
| 8995 |
vikram.rag |
631 |
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
|
|
632 |
Calendar cal=GregorianCalendar.getInstance();
|
| 9007 |
vikram.rag |
633 |
String emailFromAddress = "build@shop2020.in";
|
| 8995 |
vikram.rag |
634 |
String password = "cafe@nes";
|
|
|
635 |
GmailUtils mailer = new GmailUtils();
|
| 9274 |
vikram.rag |
636 |
String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
|
|
|
637 |
//String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
|
|
638 |
// "khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
|
|
639 |
// "yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
|
| 8995 |
vikram.rag |
640 |
try {
|
| 9006 |
vikram.rag |
641 |
logger.info("Before Sending Emails");
|
| 9056 |
vikram.rag |
642 |
|
| 9015 |
vikram.rag |
643 |
if(sb.toString().equalsIgnoreCase("")){
|
| 9056 |
vikram.rag |
644 |
if(orders_processed!=0){
|
| 9094 |
vikram.rag |
645 |
String emailSubjectTxt = orders_processed + " Flipkart " + order_string + " created manually "+sdf.format(cal.getTime());
|
| 9056 |
vikram.rag |
646 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt,"Orders Created Successfully (No Alerts)", emailFromAddress, password, new ArrayList<File>());
|
|
|
647 |
logger.info("Sending Email Flipkart Orders Created Successfully (No Alerts)");
|
|
|
648 |
}
|
| 9090 |
vikram.rag |
649 |
else{
|
| 9094 |
vikram.rag |
650 |
String emailSubjectTxt = "No new orders created manually "+sdf.format(cal.getTime());
|
|
|
651 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt,"No new orders created manually", emailFromAddress, password, new ArrayList<File>());
|
| 9090 |
vikram.rag |
652 |
logger.info("Sending Email Flipkart Orders Created Successfully (No Alerts)");
|
|
|
653 |
}
|
| 8995 |
vikram.rag |
654 |
}
|
|
|
655 |
else{
|
|
|
656 |
if(orders_processed!=0){
|
| 9094 |
vikram.rag |
657 |
String emailSubjectTxt = orders_processed + " Flipkart " + order_string + " created manually (Check Alerts) "+sdf.format(cal.getTime());
|
| 9017 |
vikram.rag |
658 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt,sb.toString(), emailFromAddress, password, new ArrayList<File>());
|
| 9032 |
vikram.rag |
659 |
logger.info("Sending Email Flipkart Orders Created Successfully (Check Alerts)");
|
| 8995 |
vikram.rag |
660 |
}
|
|
|
661 |
else{
|
| 9095 |
vikram.rag |
662 |
String emailSubjectTxt = "No new Flipkart orders created manually "+sdf.format(cal.getTime());
|
| 9017 |
vikram.rag |
663 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt,sb.toString(), emailFromAddress, password, new ArrayList<File>());
|
| 9032 |
vikram.rag |
664 |
logger.info("Sending Email Flipkart Orders Created Successfully (Check Alerts)");
|
| 8995 |
vikram.rag |
665 |
}
|
|
|
666 |
}
|
| 9056 |
vikram.rag |
667 |
}
|
|
|
668 |
catch (Exception e) {
|
|
|
669 |
e.printStackTrace();
|
|
|
670 |
logger.error("Exception ",e);
|
|
|
671 |
}
|
| 8961 |
vikram.rag |
672 |
}
|
|
|
673 |
|
|
|
674 |
public static Logger getLogger() {
|
|
|
675 |
return logger;
|
|
|
676 |
}
|
|
|
677 |
public static void setLogger(Logger logger) {
|
|
|
678 |
FlipkartDashboardController.logger = logger;
|
|
|
679 |
}
|
|
|
680 |
public HttpServletRequest getRequest() {
|
|
|
681 |
return request;
|
|
|
682 |
}
|
|
|
683 |
public void setRequest(HttpServletRequest request) {
|
|
|
684 |
this.request = request;
|
|
|
685 |
}
|
|
|
686 |
public HttpServletResponse getResponse() {
|
|
|
687 |
return response;
|
|
|
688 |
}
|
|
|
689 |
public void setResponse(HttpServletResponse response) {
|
|
|
690 |
this.response = response;
|
|
|
691 |
}
|
|
|
692 |
public HttpSession getSession() {
|
|
|
693 |
return session;
|
|
|
694 |
}
|
|
|
695 |
public void setSession(HttpSession session) {
|
|
|
696 |
this.session = session;
|
|
|
697 |
}
|
|
|
698 |
public ServletContext getContext() {
|
|
|
699 |
return context;
|
|
|
700 |
}
|
|
|
701 |
public void setContext(ServletContext context) {
|
|
|
702 |
this.context = context;
|
|
|
703 |
}
|
|
|
704 |
public String getUrl() {
|
|
|
705 |
return url;
|
|
|
706 |
}
|
|
|
707 |
public void setUrl(String url) {
|
|
|
708 |
this.url = url;
|
|
|
709 |
}
|
|
|
710 |
public File getFile() {
|
|
|
711 |
return file;
|
|
|
712 |
}
|
|
|
713 |
public void setFile(File file) {
|
|
|
714 |
this.file = file;
|
|
|
715 |
}
|
|
|
716 |
public String getErrMsg() {
|
|
|
717 |
return errMsg;
|
|
|
718 |
}
|
|
|
719 |
public void setErrMsg(String errMsg) {
|
|
|
720 |
this.errMsg = errMsg;
|
|
|
721 |
}
|
|
|
722 |
public String getId() {
|
|
|
723 |
return id;
|
|
|
724 |
}
|
|
|
725 |
public void setId(String id) {
|
|
|
726 |
this.id = id;
|
|
|
727 |
}
|
|
|
728 |
@Override
|
|
|
729 |
public void setServletContext(ServletContext arg0) {
|
|
|
730 |
// TODO Auto-generated method stub
|
|
|
731 |
|
|
|
732 |
}
|
|
|
733 |
@Override
|
|
|
734 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
735 |
this.response = response;
|
|
|
736 |
}
|
|
|
737 |
@Override
|
|
|
738 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
739 |
this.request = request;
|
|
|
740 |
this.session = request.getSession();
|
|
|
741 |
|
|
|
742 |
}
|
| 9271 |
vikram.rag |
743 |
public static LineItem createLineItem(long itemId, double amount,int qty) throws CatalogServiceException, TException {
|
| 8961 |
vikram.rag |
744 |
LineItem lineItem = new LineItem();
|
|
|
745 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
746 |
Item item = catalogClient.getItem(itemId);
|
|
|
747 |
if(item.getId()==0){
|
|
|
748 |
//in case item id is incorrect..
|
|
|
749 |
return null;
|
|
|
750 |
}
|
|
|
751 |
|
|
|
752 |
lineItem.setProductGroup(item.getProductGroup());
|
|
|
753 |
lineItem.setBrand(item.getBrand());
|
|
|
754 |
lineItem.setModel_number(item.getModelNumber());
|
|
|
755 |
lineItem.setModel_name(item.getModelName());
|
|
|
756 |
lineItem.setExtra_info(item.getFeatureDescription());
|
| 9271 |
vikram.rag |
757 |
lineItem.setQuantity(qty);
|
| 8961 |
vikram.rag |
758 |
lineItem.setItem_id(item.getId());
|
|
|
759 |
lineItem.setUnit_weight(item.getWeight());
|
|
|
760 |
lineItem.setTotal_weight(item.getWeight());
|
|
|
761 |
lineItem.setUnit_price(amount);
|
| 9271 |
vikram.rag |
762 |
lineItem.setTotal_price(amount*qty);
|
| 8961 |
vikram.rag |
763 |
if (item.getColor() == null || "NA".equals(item.getColor())) {
|
|
|
764 |
lineItem.setColor("");
|
|
|
765 |
} else {
|
|
|
766 |
lineItem.setColor(item.getColor());
|
|
|
767 |
}
|
|
|
768 |
return lineItem;
|
|
|
769 |
}
|
|
|
770 |
|
|
|
771 |
public static void replacecommas (File file) throws IOException {
|
|
|
772 |
BufferedReader br = null;
|
|
|
773 |
File tempFile = new File("/tmp/formatted.csv");
|
|
|
774 |
FileWriter fw = new FileWriter(tempFile);
|
|
|
775 |
String line;
|
|
|
776 |
br = new BufferedReader(new FileReader(file));
|
|
|
777 |
boolean replace = false;
|
|
|
778 |
char [] lineChars;
|
| 8991 |
vikram.rag |
779 |
int counter=1;
|
| 9006 |
vikram.rag |
780 |
String completeorder = "";
|
| 8961 |
vikram.rag |
781 |
while ((line = br.readLine()) != null) {
|
| 8991 |
vikram.rag |
782 |
if(counter!=1){
|
| 9046 |
vikram.rag |
783 |
if(line.endsWith(",,,,,,")){
|
| 8991 |
vikram.rag |
784 |
completeorder = completeorder.concat(line);
|
|
|
785 |
if(line.contains("Ordered On")){
|
|
|
786 |
continue;
|
| 8961 |
vikram.rag |
787 |
}
|
| 8991 |
vikram.rag |
788 |
else{
|
|
|
789 |
lineChars = completeorder.toCharArray();
|
|
|
790 |
int count = 0;
|
|
|
791 |
for(int i=0;i<lineChars.length;i++)
|
|
|
792 |
{
|
|
|
793 |
if(lineChars[i]=='"'){
|
|
|
794 |
count++;
|
|
|
795 |
}
|
|
|
796 |
if(count%2==1){
|
|
|
797 |
replace=false;
|
|
|
798 |
}
|
|
|
799 |
if(count%2==0){
|
|
|
800 |
replace=true;
|
|
|
801 |
}
|
|
|
802 |
if(replace && lineChars[i] == ','){
|
|
|
803 |
lineChars[i]='$';
|
|
|
804 |
}
|
|
|
805 |
}
|
| 8961 |
vikram.rag |
806 |
}
|
| 8991 |
vikram.rag |
807 |
line = String.valueOf(lineChars);
|
|
|
808 |
System.out.println(" Line and Length " + line + " " + line.length());
|
|
|
809 |
fw.write(line+"\n");
|
|
|
810 |
completeorder="";
|
|
|
811 |
}
|
|
|
812 |
else{
|
|
|
813 |
line = line.replace("\n","");
|
| 9006 |
vikram.rag |
814 |
if(completeorder.equalsIgnoreCase("")){
|
| 8991 |
vikram.rag |
815 |
completeorder = line;
|
| 8961 |
vikram.rag |
816 |
}
|
| 8991 |
vikram.rag |
817 |
else{
|
|
|
818 |
completeorder = completeorder.concat(line);;
|
| 8961 |
vikram.rag |
819 |
}
|
|
|
820 |
}
|
|
|
821 |
}
|
| 8991 |
vikram.rag |
822 |
counter++;
|
|
|
823 |
} if (br != null)br.close();
|
| 8961 |
vikram.rag |
824 |
if (fw != null)fw.close();
|
|
|
825 |
}
|
|
|
826 |
|
| 9199 |
vikram.rag |
827 |
public static long createPayment(User user, String subOrderId, double amount) throws PaymentException, TException {
|
| 8961 |
vikram.rag |
828 |
in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
|
| 8967 |
vikram.rag |
829 |
logger.info("Creating payment for user id " + user.getUserId() + " Gateway id " + FLIPKART_GATEWAY_ID);
|
| 8966 |
vikram.rag |
830 |
logger.info("Long value of transaction id : " + Long.valueOf(transactionId));
|
| 9199 |
vikram.rag |
831 |
return client.createPayment(user.getUserId(), amount, FLIPKART_GATEWAY_ID, Long.valueOf(transactionId), false);
|
| 8961 |
vikram.rag |
832 |
}
|
|
|
833 |
|
|
|
834 |
|
|
|
835 |
}
|