Subversion Repositories SmartDukaan

Rev

Rev 9215 | Rev 9456 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8488 amar.kumar 1
package in.shop2020.support.controllers;
2
 
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.text.SimpleDateFormat;
6
import java.util.ArrayList;
7
import java.util.Calendar;
8
import java.util.Collection;
9
import java.util.Collections;
10
import java.util.Date;
11
import java.util.List;
12
 
13
import in.shop2020.logistics.DeliveryType;
14
import in.shop2020.logistics.LogisticsInfo;
15
import in.shop2020.logistics.LogisticsService;
16
import in.shop2020.logistics.PickUpType;
17
import in.shop2020.model.v1.catalog.CatalogService;
18
import in.shop2020.model.v1.catalog.CatalogServiceException;
19
import in.shop2020.model.v1.catalog.EbayItem;
20
import in.shop2020.model.v1.catalog.Item;
21
import in.shop2020.model.v1.inventory.InventoryService;
22
import in.shop2020.model.v1.inventory.InventoryServiceException;
8892 amar.kumar 23
import in.shop2020.model.v1.inventory.InventoryType;
8488 amar.kumar 24
import in.shop2020.model.v1.inventory.VendorItemPricing;
25
import in.shop2020.model.v1.inventory.Warehouse;
8892 amar.kumar 26
import in.shop2020.model.v1.inventory.WarehouseType;
8488 amar.kumar 27
import in.shop2020.model.v1.order.LineItem;
28
import in.shop2020.model.v1.order.Order;
29
import in.shop2020.model.v1.order.OrderSource;
30
import in.shop2020.model.v1.order.OrderStatus;
31
import in.shop2020.model.v1.order.OrderType;
32
import in.shop2020.model.v1.order.SnapdealOrder;
33
import in.shop2020.model.v1.order.SourceDetail;
34
import in.shop2020.model.v1.order.Transaction;
35
import in.shop2020.model.v1.order.TransactionStatus;
36
import in.shop2020.model.v1.order.TransactionService.Client;
37
import in.shop2020.model.v1.user.Address;
38
import in.shop2020.model.v1.user.User;
39
import in.shop2020.payments.Attribute;
40
import in.shop2020.payments.PaymentException;
41
import in.shop2020.payments.PaymentStatus;
42
import in.shop2020.thrift.clients.CatalogClient;
43
import in.shop2020.thrift.clients.InventoryClient;
44
import in.shop2020.thrift.clients.LogisticsClient;
45
import in.shop2020.thrift.clients.PaymentClient;
46
import in.shop2020.thrift.clients.TransactionClient;
47
import in.shop2020.thrift.clients.UserClient;
48
import in.shop2020.support.utils.ReportsUtils;
49
 
50
import javax.servlet.http.HttpServletRequest;
51
import javax.servlet.http.HttpSession;
52
 
53
import org.apache.commons.io.FileUtils;
54
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
55
import org.apache.poi.ss.usermodel.Cell;
56
import org.apache.poi.ss.usermodel.Row;
57
import org.apache.poi.ss.usermodel.Sheet;
58
import org.apache.poi.ss.usermodel.Workbook;
59
import org.apache.struts2.convention.annotation.InterceptorRef;
60
import org.apache.struts2.convention.annotation.InterceptorRefs;
61
import org.apache.struts2.convention.annotation.Result;
62
import org.apache.struts2.convention.annotation.Results;
63
import org.apache.struts2.interceptor.ServletRequestAware;
64
import org.apache.thrift.TException;
65
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
67
 
68
import com.opensymphony.xwork2.ActionSupport;
69
 
70
@SuppressWarnings("serial")
71
@InterceptorRefs({
72
    @InterceptorRef("defaultStack"),
73
    @InterceptorRef("login")
74
})
75
@Results({
76
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
77
})
78
public class SnapdealOrderCreatorController extends ActionSupport implements ServletRequestAware {
79
 
80
	private static Logger logger = LoggerFactory.getLogger(SnapdealOrderCreatorController.class);
81
 
82
	private HttpServletRequest request;
83
    private HttpSession session;
84
 
85
    private static final int SNAPDEAL_SOURCE_ID = 7;
86
 
87
    private static final int COURIER_INDEX = 0;
88
    private static final int PRODUCT_NAME_INDEX = 1;
89
    private static final int REFERENCE_CODE_INDEX = 2;
90
    private static final int SUBORDER_ID_INDEX = 3;
91
    private static final int ITEMID_INDEX = 4;
92
    private static final int AWB_INDEX = 5;
93
    private static final int TRANSACTION_DATE_INDEX = 6;
94
    private static final int BUYER_NAME_INDEX = 8;
95
    private static final int CITY_INDEX = 9;
96
    private static final int STATE_INDEX = 10;
97
    private static final int PINCODE_INDEX = 11;
98
    private static final int AMOUNT_INDEX = 12;
99
    private static final int WAREHOUSE_ID_INDEX = 14;
100
    private static final int OVERRIDE_BILLING_PRICE_INDEX = 15;
101
 
102
 
103
    private static final int SNAPDEAL_GATEWAY_ID = 18;
104
 
105
    private static final String FIRSTFLIGHT = "First Flight";
9110 vikram.rag 106
	private static final String DELHIVERY = "DELHIVERY";
107
	private static final String BLUEDART = "Bluedart";
108
	private static final String CHHOTU = "CHHOTU";	
109
	private static final String LAST_MILE = "LAST_MILE";
110
	private static final String  ECOM = "Ecom Express";
111
	private static final String  EWINGS = "EWINGS";
112
	private static final String DTDC = "DTDC";
9188 vikram.rag 113
	private static final String WAREOLOG = "Wareolog";
9110 vikram.rag 114
	private static final String  MIRAKLE = "MIRAKLE";
115
	private static final String RAJIV_TRANSPORT = "RAJIV_TRANSPORT";
116
	private static final String BLUEDART_HIGH_VALUE = "BLUEDART_HIGH_VALUE";
117
	private static final String BLUEDART_SURFACE = "BLUEDART_SURFACE";
9188 vikram.rag 118
	private static final String BLUEDART_APEX = "BLUEDART APEX";
9110 vikram.rag 119
	private static final String ARAMEX = "ARAMEX";
120
	private static final String GATI = "GATI";
121
	private static final String INDIA_POST = "INDIA_POST";
122
	private static final String FEDEX = "FEDEX";
123
	private static final String IOT = "IOT";
9147 vikram.rag 124
	private static final String RED_EXP = "Red Express";
9110 vikram.rag 125
	private static final String GHARPAY = "GHARPAY";
9127 vikram.rag 126
	private static final String QUANTIUM = "Quantium Solutions";
9119 vikram.rag 127
	private static final String GATI_AIR = "GATI AIR";
9110 vikram.rag 128
	private static final String VDELIVER = "VDELIVER";
9136 vikram.rag 129
	private static final String OVERNITE_EXP = "Overnite Express";
9110 vikram.rag 130
 
8488 amar.kumar 131
    private File orderDataFile;
132
    private String orderDataFileName;
133
    private String transactionId;
134
    private String errorMsg = "";
135
    private Long rowId = 0L;
9150 vikram.rag 136
 
137
	private long paymentId;
8488 amar.kumar 138
 
139
    public String create() throws TException {
140
        File fileToCreate = null;
141
        orderDataFileName = "OrderSheet_Snapdeal_"+(new Date().toString());
142
        try {
143
            fileToCreate = new File("/tmp/", this.orderDataFileName);
144
            FileUtils.copyFile(this.orderDataFile, fileToCreate);
145
        } catch (Exception e) {
146
           logger.error("Error while writing order data file to the local file system for Snapdeal", e);
147
           addActionError("Error while writing order data file to the local file system");
148
        }
149
 
150
 
151
        if(checkForErrors())
152
            return "authsuccess";
153
 
154
        //Parse the file and submit the data for update to the transaction service
155
        Workbook wb = null;
156
        try {
157
            wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
158
        } catch (Exception e) {
159
            logger.error("Unable to open the File for Order Creation for Snapdeal ", e);
160
            setErrorMsg(getErrorMsg() + "Error in opening File for Order creation");
161
            addActionError("Unable to open the File for Order creation");
162
        }
163
        if(checkForErrors())
164
            return "authsuccess";
165
 
166
        SourceDetail sourceDetail = null;
167
        User user = null;
168
        TransactionClient tsc = null;
169
        try {
170
            tsc = new TransactionClient();
171
			sourceDetail = tsc.getClient().getSourceDetail(SNAPDEAL_SOURCE_ID);
172
        } catch (Exception e) {
173
            logger.error("Unable to establish connection to the transaction service while getting Snapdeal Source Detail", e);
174
            setErrorMsg(getErrorMsg() + "Error in Order Service while getting Snapdeal Source Detail");
175
            addActionError("Error in connecting to Order Service");
176
		}
177
 
178
        if(checkForErrors())
179
            return "authsuccess";
180
 
181
	    try {   
182
	        in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
183
	        user = userClient.getUserByEmail(sourceDetail.getEmail());
184
	    } catch (Exception e) {
185
	        logger.error("Unable to establish connection to the User service", e);
186
	        setErrorMsg(getErrorMsg() + "Unable to get Default Email for Snapdeal ");
187
	        addActionError("Unable to get Default Email for Snapdeal ");
188
		}
189
 
190
        if(checkForErrors())
191
            return "authsuccess";
192
 
193
        Sheet sheet = wb.getSheetAt(0);
194
        Row firstRow = sheet.getRow(0);
195
        for (Row row : sheet) {
196
        	long orderCountForRow = 0;
197
        	rowId++;
198
            if(row.equals(firstRow))
199
                continue;
200
        	try {
201
	            Transaction txn = new Transaction();
202
	            txn.setShoppingCartid(user.getActiveCartId());
203
	            txn.setCustomer_id(user.getUserId());
204
	            txn.setCreatedOn(new Date().getTime());
205
	            txn.setTransactionStatus(TransactionStatus.INIT);
206
	            txn.setStatusDescription("Order for Snapdeal ");
207
 
208
	            List<Order> orders = new ArrayList<Order>();
209
 
210
	            row.getCell(ITEMID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
211
	            Long itemId = Long.parseLong(row.getCell(ITEMID_INDEX).getStringCellValue());
212
	    		double listingPrice = 0;
213
	    		double overriddenPrice = 0;
214
	    		double totalPrice = 0;
215
	    		Cell overriddenPriceCell = row.getCell(OVERRIDE_BILLING_PRICE_INDEX);
216
	        	if(overriddenPriceCell  != null && overriddenPriceCell .getCellType() != Cell.CELL_TYPE_BLANK) {
217
	        		overriddenPrice = row.getCell(OVERRIDE_BILLING_PRICE_INDEX).getNumericCellValue();
218
	        	}
219
 
220
	    		totalPrice = row.getCell(AMOUNT_INDEX).getNumericCellValue();
221
	    		listingPrice = totalPrice;
222
	    		if(overriddenPrice>=1) {
223
	    			totalPrice = overriddenPrice;
224
	    		}
225
	        	LineItem lineItem = null;
226
	        	try {
227
	        		lineItem = createLineItem(itemId, totalPrice);
8569 amar.kumar 228
	        		Double subOrderId = row.getCell(SUBORDER_ID_INDEX).getNumericCellValue();
229
	            	String refCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
230
	        		lineItem.setExtra_info("SubOrderId = " + subOrderId + " ReferenceCode = " + refCode);
8488 amar.kumar 231
	        	} catch (Exception tex) {
232
	        		logger.error("Unable to create order for RowId " + rowId, tex);
233
	        		setErrorMsg(getErrorMsg() + "<br>Unable to create lineitem using catalog info for RowId " + rowId);
234
	    	        continue;
235
	        	}
236
	            Order t_order = new Order();
237
	            t_order.setCustomer_id(user.getUserId());
238
	            t_order.setCustomer_email(sourceDetail.getEmail());
239
	            row.getCell(BUYER_NAME_INDEX).setCellType(Cell.CELL_TYPE_STRING);
240
	        	t_order.setCustomer_name(row.getCell(BUYER_NAME_INDEX).getStringCellValue());
9215 vikram.rag 241
	        	t_order.setCustomer_mobilenumber("+91-9999999999");
8488 amar.kumar 242
	        	t_order.setCustomer_address1("");
243
	        	t_order.setCustomer_address2("");
244
	        	t_order.setCustomer_city(row.getCell(CITY_INDEX).getStringCellValue());
245
	        	t_order.setCustomer_state(row.getCell(STATE_INDEX).getStringCellValue());
246
	        	row.getCell(PINCODE_INDEX).setCellType(Cell.CELL_TYPE_STRING);
247
	        	t_order.setCustomer_pincode(row.getCell(PINCODE_INDEX).getStringCellValue());
248
	            t_order.setTotal_amount(lineItem.getTotal_price());            
249
	            t_order.setTotal_weight(lineItem.getTotal_weight());
250
	            t_order.setLineitems(Collections.singletonList(lineItem));            
8761 vikram.rag 251
	            t_order.setStatus(OrderStatus.PAYMENT_PENDING);
8488 amar.kumar 252
	            t_order.setStatusDescription("In Process");
253
	            t_order.setCreated_timestamp(new Date().getTime());
254
	            t_order.setOrderType(OrderType.B2C);
255
	            t_order.setCod(false);
256
	            try {
257
	            	Calendar time = Calendar.getInstance();
258
	            	time.add(Calendar.DAY_OF_MONTH, 1);
9288 vikram.rag 259
	            	if(time.get(Calendar.DAY_OF_WEEK)!=1){
260
	            		t_order.setPromised_shipping_time(time.getTimeInMillis());
261
	            		t_order.setExpected_shipping_time(time.getTimeInMillis());
262
	            	}
263
	            	else{
264
	            		t_order.setPromised_shipping_time(time.getTimeInMillis()+24*60*60*1000);
265
	            		t_order.setExpected_shipping_time(time.getTimeInMillis()+24*60*60*1000);
266
	            	}
8488 amar.kumar 267
	            	time.add(Calendar.DAY_OF_MONTH, 3);
268
	            	t_order.setPromised_delivery_time(time.getTimeInMillis());
269
	            	t_order.setExpected_delivery_time(time.getTimeInMillis());
270
	            } catch(Exception e) {
271
	            	addActionError("Error in updating Shipping or Delivery Time for row number " + rowId);
272
	            	logger.error("Error in updating Shipping or Delivery Time for row number " + rowId,e);
273
	            	continue;
274
	            }
275
 
276
	            InventoryService.Client inventoryClient = null;
277
	            Warehouse fulfillmentWarehouse= null; 
278
	            try {
279
	            	inventoryClient = new InventoryClient().getClient();
280
	            	Cell warehouseCell = row.getCell(WAREHOUSE_ID_INDEX);
281
	            	if(warehouseCell != null && warehouseCell.getCellType() != Cell.CELL_TYPE_BLANK) {
282
	            		fulfillmentWarehouse = inventoryClient.getWarehouse(new Double(row.getCell(WAREHOUSE_ID_INDEX).getNumericCellValue()).longValue());
283
	            	} else {
284
	            		List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(itemId, 1);
285
	            		fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
286
	            	}
287
	            	t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
8892 amar.kumar 288
 
289
					long billingWarehouseId = 0;
290
					if(fulfillmentWarehouse.getBillingWarehouseId()== 0) {
291
						inventoryClient = new InventoryClient().getClient();
292
						List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, fulfillmentWarehouse.getVendor().getId(), 0, 0);
293
						for(Warehouse warehouse : warehouses) {
294
							if(warehouse.getBillingWarehouseId()!=0) {
295
								billingWarehouseId = warehouse.getBillingWarehouseId();
296
				                break;
297
							}
298
						}
299
					} else {
300
						billingWarehouseId = fulfillmentWarehouse.getBillingWarehouseId();
301
					}
302
 
303
					t_order.setWarehouse_id(billingWarehouseId);
304
					//t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
8488 amar.kumar 305
	        		VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
306
	        		t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
307
	        		t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
308
				} catch (InventoryServiceException e) {
309
					addActionError("Error in updating WarehouseId for row number " + rowId);
310
					setErrorMsg(getErrorMsg() + "<br>Error in updating WarehouseId for row number  " + rowId);
311
	            	logger.error("Error in updating WarehouseId for row number " + rowId,e);
312
	            	continue;
313
				}
314
 
315
				String provider = row.getCell(COURIER_INDEX).getStringCellValue();
9110 vikram.rag 316
				if(provider.equalsIgnoreCase(FIRSTFLIGHT)) {
8488 amar.kumar 317
					t_order.setLogistics_provider_id(12);
9110 vikram.rag 318
				} else if(provider.equalsIgnoreCase(DELHIVERY)) {
8488 amar.kumar 319
					t_order.setLogistics_provider_id(13);
9110 vikram.rag 320
				} else if(provider.equalsIgnoreCase(BLUEDART)) {
8508 amar.kumar 321
					t_order.setLogistics_provider_id(14);
9110 vikram.rag 322
				} else if(provider.equalsIgnoreCase(ECOM)) {
8796 anupam.sin 323
                    t_order.setLogistics_provider_id(18);
9110 vikram.rag 324
                }else if(provider.equalsIgnoreCase(EWINGS)){
325
    				t_order.setLogistics_provider_id(19);
326
    			}
327
    			else if(provider.equalsIgnoreCase(DTDC)){
328
    				t_order.setLogistics_provider_id(20);
329
    			}
330
    			else if(provider.equalsIgnoreCase(WAREOLOG)){
331
    				t_order.setLogistics_provider_id(21);
332
    			}
333
    			else if(provider.equalsIgnoreCase(MIRAKLE)){
334
    				t_order.setLogistics_provider_id(22);
335
    			}
336
    			else if(provider.equalsIgnoreCase(RAJIV_TRANSPORT)){
337
    				t_order.setLogistics_provider_id(23);
338
    			}
339
    			else if(provider.equalsIgnoreCase(BLUEDART_HIGH_VALUE)){
340
    				t_order.setLogistics_provider_id(24);
341
    			}
342
    			else if(provider.equalsIgnoreCase(BLUEDART_SURFACE)){
343
    				t_order.setLogistics_provider_id(25);
344
    			}
345
    			else if(provider.equalsIgnoreCase(BLUEDART_APEX)){
346
    				t_order.setLogistics_provider_id(26);
347
    			}
348
    			else if(provider.equalsIgnoreCase(ARAMEX)){
349
    				t_order.setLogistics_provider_id(27);
350
    			}
351
    			else if(provider.equalsIgnoreCase(GATI)){
352
    				t_order.setLogistics_provider_id(28);
353
    			}
354
    			else if(provider.equalsIgnoreCase(INDIA_POST)){
355
    				t_order.setLogistics_provider_id(29);
356
    			}
357
    			else if(provider.equalsIgnoreCase(FEDEX)){
358
    				t_order.setLogistics_provider_id(30);
359
    			}
360
    			else if(provider.equalsIgnoreCase(IOT)){
361
    				t_order.setLogistics_provider_id(31);
362
    			}
363
    			else if(provider.equalsIgnoreCase(RED_EXP)){
364
    				t_order.setLogistics_provider_id(32);
365
    			}
366
    			else if(provider.equalsIgnoreCase(VDELIVER)){
367
    				t_order.setLogistics_provider_id(33);
368
    			}
369
    			else if(provider.equalsIgnoreCase(GHARPAY)){
370
    				t_order.setLogistics_provider_id(34);
371
    			}
372
    			else if(provider.equalsIgnoreCase(QUANTIUM)){
373
    				t_order.setLogistics_provider_id(35);
374
    			}
375
    			else if(provider.equalsIgnoreCase(GATI_AIR)){
376
    				t_order.setLogistics_provider_id(36);
9136 vikram.rag 377
    			}
9138 vikram.rag 378
    			else if(provider.equalsIgnoreCase(OVERNITE_EXP)){
9136 vikram.rag 379
    				t_order.setLogistics_provider_id(37);
380
    			}
381
    			else {
8488 amar.kumar 382
					addActionError("Unknown logistics provider found for row number " + rowId);
383
					setErrorMsg(getErrorMsg() + "<br>Unknown logistics provider found for row number " + rowId);
384
	            	logger.error("Unknown logistics provider found for row number " + rowId);
385
	            	continue;
386
				}
387
 
388
				row.getCell(AWB_INDEX).setCellType(Cell.CELL_TYPE_STRING);
389
				t_order.setAirwaybill_no(row.getCell(AWB_INDEX).getStringCellValue());
390
				t_order.setTracking_id(row.getCell(AWB_INDEX).getStringCellValue());
391
	            t_order.setTotal_amount(totalPrice);
392
	            t_order.setOrderType(OrderType.B2C);
393
	            t_order.setSource(SNAPDEAL_SOURCE_ID);
394
	            t_order.setOrderType(OrderType.B2C);
395
	            orders.add(t_order);
396
	            orderCountForRow++;
397
 
398
	            txn.setOrders(orders);
399
	            Client transaction_client = new TransactionClient().getClient();
400
	            try {
401
	            	long subOrderId = new Double(row.getCell(SUBORDER_ID_INDEX).getNumericCellValue()).longValue();
402
	            	String referenceCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
403
	            	String productName = row.getCell(PRODUCT_NAME_INDEX).getStringCellValue();
404
	            	Date snapdealTxnDate = row.getCell(TRANSACTION_DATE_INDEX).getDateCellValue();
405
 
8802 amar.kumar 406
	            	if(transaction_client.snapdealOrderExists(subOrderId, referenceCode)) {
8488 amar.kumar 407
	            		setErrorMsg(getErrorMsg() + "<br>Duplicate order for subOrderId " + subOrderId + " for row number  " + rowId);
408
	            		logger.error("Duplicate order for subOrderId " + subOrderId + " for row number  " + rowId);
409
	            		continue;
410
	            	}
411
 
412
	            	transactionId =  String.valueOf(transaction_client.createTransaction(txn));
9150 vikram.rag 413
	            	paymentId = createPayment(user, (new Long(subOrderId)).toString(), totalPrice);
8488 amar.kumar 414
 
415
	                logger.info("Successfully created transaction: " + transactionId + " for amount: " + totalPrice);
416
 
417
	                Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
418
	                Order order = transaction.getOrders().get(0);
419
 
420
	                inventoryClient.reserveItemInWarehouse(itemId, fulfillmentWarehouse.getId(), 1, 
421
	                		order.getId(), order.getCreated_timestamp(), order.getPromised_shipping_time(), order.getLineitems().get(0).getQuantity());
422
 
423
 
424
	                SnapdealOrder snapdealOrder = new SnapdealOrder();
425
	                snapdealOrder.setOrderId(order.getId());
426
	                snapdealOrder.setSubOrderId(subOrderId);
427
	                snapdealOrder.setReferenceCode(referenceCode);
428
	                snapdealOrder.setProductName(productName);
429
	                snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
430
	                snapdealOrder.setListingPrice(listingPrice);
431
	                transaction_client.createSnapdealOrder(snapdealOrder);
9150 vikram.rag 432
					new PaymentClient().getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, Long.toString(subOrderId), null, PaymentStatus.SUCCESS, null, null);
8488 amar.kumar 433
 
434
	            } catch (Exception e) {
435
	                logger.error("Error while creating order for rowId " + rowId, e);
436
	                addActionError("Error while creating order for rowId " + rowId);
437
	                setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
438
	                continue;
439
	    		}
440
        	} catch (Exception e) {
8748 amar.kumar 441
        		logger.error("Error while creating order for row number " + rowId, e);
8488 amar.kumar 442
        		setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
443
        		continue;
444
        	}
445
        }
446
 
447
        checkForErrors();
448
        return "authsuccess";
449
    }
450
 
451
    private Date interchangeDateAndMonth(Date date) {
452
		Date updatedDate = new Date(date.getTime());
453
		updatedDate.setDate(date.getMonth() + 1);
454
		updatedDate.setMonth(date.getDate() - 1);
455
		return updatedDate;
456
	}
457
 
458
	private LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
459
    	LineItem lineItem = new LineItem();
460
    	CatalogService.Client catalogClient = new CatalogClient().getClient();
461
    	Item item = catalogClient.getItem(itemId);
462
 
463
    	lineItem.setProductGroup(item.getProductGroup());
464
        lineItem.setBrand(item.getBrand());
465
        lineItem.setModel_number(item.getModelNumber());
466
        lineItem.setModel_name(item.getModelName());
467
        lineItem.setExtra_info(item.getFeatureDescription());
468
        lineItem.setQuantity(1);
469
        lineItem.setItem_id(item.getId());
470
        lineItem.setUnit_weight(item.getWeight());
471
        lineItem.setTotal_weight(item.getWeight());
472
        lineItem.setUnit_price(amount);
473
        lineItem.setTotal_price(amount);
474
 
475
        if (item.getColor() == null || "NA".equals(item.getColor())) {
476
            lineItem.setColor("");
477
        } else {
478
            lineItem.setColor(item.getColor());
479
        }
480
    	return lineItem;
481
	}
482
 
9150 vikram.rag 483
    private long createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {
8488 amar.kumar 484
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
9150 vikram.rag 485
        return client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
8488 amar.kumar 486
    }   
487
 
488
	public String index() {
489
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
490
            return "authfail";
491
        checkForErrors();
492
        return "authsuccess";
493
    }
494
 
495
	private boolean checkForErrors(){
496
        Collection<String> actionErrors = getActionErrors();
497
        if(actionErrors != null && !actionErrors.isEmpty()){
498
            for (String str : actionErrors) {
499
                errorMsg += "<BR/>" + str;
500
            }
501
            return true;
502
        }
503
        return false;
504
    }
505
 
506
	@Override
507
	public void setServletRequest(HttpServletRequest request) {
508
		this.request = request;
509
        this.session = request.getSession();
510
	}
511
 
512
	public String getErrorMsg() {
513
		return errorMsg;
514
	}
515
 
516
	public void setErrorMsg(String errorMsg) {
517
		this.errorMsg = errorMsg;
518
	}
519
 
520
	public Long getRowId() {
521
		return rowId;
522
	}
523
 
524
	public void setRowId(Long rowId) {
525
		this.rowId = rowId;
526
	}
527
 
528
	public File getOrderDataFile() {
529
		return orderDataFile;
530
	}
531
 
532
	public void setOrderDataFile(File orderDataFile) {
533
		this.orderDataFile = orderDataFile;
534
	}
535
 
536
}