Subversion Repositories SmartDukaan

Rev

Rev 9136 | Rev 9147 | 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";
113
	private static final String WAREOLOG = "DTDC";
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";
118
	private static final String BLUEDART_APEX = "BLUEDART_APEX";
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";
124
	private static final String RED_EXP = "RED_EXP";
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;
136
 
137
    public String create() throws TException {
138
        File fileToCreate = null;
139
        orderDataFileName = "OrderSheet_Snapdeal_"+(new Date().toString());
140
        try {
141
            fileToCreate = new File("/tmp/", this.orderDataFileName);
142
            FileUtils.copyFile(this.orderDataFile, fileToCreate);
143
        } catch (Exception e) {
144
           logger.error("Error while writing order data file to the local file system for Snapdeal", e);
145
           addActionError("Error while writing order data file to the local file system");
146
        }
147
 
148
 
149
        if(checkForErrors())
150
            return "authsuccess";
151
 
152
        //Parse the file and submit the data for update to the transaction service
153
        Workbook wb = null;
154
        try {
155
            wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
156
        } catch (Exception e) {
157
            logger.error("Unable to open the File for Order Creation for Snapdeal ", e);
158
            setErrorMsg(getErrorMsg() + "Error in opening File for Order creation");
159
            addActionError("Unable to open the File for Order creation");
160
        }
161
        if(checkForErrors())
162
            return "authsuccess";
163
 
164
        SourceDetail sourceDetail = null;
165
        User user = null;
166
        TransactionClient tsc = null;
167
        try {
168
            tsc = new TransactionClient();
169
			sourceDetail = tsc.getClient().getSourceDetail(SNAPDEAL_SOURCE_ID);
170
        } catch (Exception e) {
171
            logger.error("Unable to establish connection to the transaction service while getting Snapdeal Source Detail", e);
172
            setErrorMsg(getErrorMsg() + "Error in Order Service while getting Snapdeal Source Detail");
173
            addActionError("Error in connecting to Order Service");
174
		}
175
 
176
        if(checkForErrors())
177
            return "authsuccess";
178
 
179
	    try {   
180
	        in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
181
	        user = userClient.getUserByEmail(sourceDetail.getEmail());
182
	    } catch (Exception e) {
183
	        logger.error("Unable to establish connection to the User service", e);
184
	        setErrorMsg(getErrorMsg() + "Unable to get Default Email for Snapdeal ");
185
	        addActionError("Unable to get Default Email for Snapdeal ");
186
		}
187
 
188
        if(checkForErrors())
189
            return "authsuccess";
190
 
191
        Sheet sheet = wb.getSheetAt(0);
192
        Row firstRow = sheet.getRow(0);
193
        for (Row row : sheet) {
194
        	long orderCountForRow = 0;
195
        	rowId++;
196
            if(row.equals(firstRow))
197
                continue;
198
        	try {
199
	            Transaction txn = new Transaction();
200
	            txn.setShoppingCartid(user.getActiveCartId());
201
	            txn.setCustomer_id(user.getUserId());
202
	            txn.setCreatedOn(new Date().getTime());
203
	            txn.setTransactionStatus(TransactionStatus.INIT);
204
	            txn.setStatusDescription("Order for Snapdeal ");
205
 
206
	            List<Order> orders = new ArrayList<Order>();
207
 
208
	            row.getCell(ITEMID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
209
	            Long itemId = Long.parseLong(row.getCell(ITEMID_INDEX).getStringCellValue());
210
	    		double listingPrice = 0;
211
	    		double overriddenPrice = 0;
212
	    		double totalPrice = 0;
213
	    		Cell overriddenPriceCell = row.getCell(OVERRIDE_BILLING_PRICE_INDEX);
214
	        	if(overriddenPriceCell  != null && overriddenPriceCell .getCellType() != Cell.CELL_TYPE_BLANK) {
215
	        		overriddenPrice = row.getCell(OVERRIDE_BILLING_PRICE_INDEX).getNumericCellValue();
216
	        	}
217
 
218
	    		totalPrice = row.getCell(AMOUNT_INDEX).getNumericCellValue();
219
	    		listingPrice = totalPrice;
220
	    		if(overriddenPrice>=1) {
221
	    			totalPrice = overriddenPrice;
222
	    		}
223
	        	LineItem lineItem = null;
224
	        	try {
225
	        		lineItem = createLineItem(itemId, totalPrice);
8569 amar.kumar 226
	        		Double subOrderId = row.getCell(SUBORDER_ID_INDEX).getNumericCellValue();
227
	            	String refCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
228
	        		lineItem.setExtra_info("SubOrderId = " + subOrderId + " ReferenceCode = " + refCode);
8488 amar.kumar 229
	        	} catch (Exception tex) {
230
	        		logger.error("Unable to create order for RowId " + rowId, tex);
231
	        		setErrorMsg(getErrorMsg() + "<br>Unable to create lineitem using catalog info for RowId " + rowId);
232
	    	        continue;
233
	        	}
234
	            Order t_order = new Order();
235
	            t_order.setCustomer_id(user.getUserId());
236
	            t_order.setCustomer_email(sourceDetail.getEmail());
237
	            row.getCell(BUYER_NAME_INDEX).setCellType(Cell.CELL_TYPE_STRING);
238
	        	t_order.setCustomer_name(row.getCell(BUYER_NAME_INDEX).getStringCellValue());
239
	        	t_order.setCustomer_address1("");
240
	        	t_order.setCustomer_address2("");
241
	        	t_order.setCustomer_city(row.getCell(CITY_INDEX).getStringCellValue());
242
	        	t_order.setCustomer_state(row.getCell(STATE_INDEX).getStringCellValue());
243
	        	row.getCell(PINCODE_INDEX).setCellType(Cell.CELL_TYPE_STRING);
244
	        	t_order.setCustomer_pincode(row.getCell(PINCODE_INDEX).getStringCellValue());
245
	            t_order.setTotal_amount(lineItem.getTotal_price());            
246
	            t_order.setTotal_weight(lineItem.getTotal_weight());
247
	            t_order.setLineitems(Collections.singletonList(lineItem));            
8761 vikram.rag 248
	            t_order.setStatus(OrderStatus.PAYMENT_PENDING);
8488 amar.kumar 249
	            t_order.setStatusDescription("In Process");
250
	            t_order.setCreated_timestamp(new Date().getTime());
251
	            t_order.setOrderType(OrderType.B2C);
252
	            t_order.setCod(false);
253
	            try {
254
	            	Calendar time = Calendar.getInstance();
255
	            	time.add(Calendar.DAY_OF_MONTH, 1);
256
	            	t_order.setPromised_shipping_time(time.getTimeInMillis());
257
	            	t_order.setExpected_shipping_time(time.getTimeInMillis());
258
	            	time.add(Calendar.DAY_OF_MONTH, 3);
259
	            	t_order.setPromised_delivery_time(time.getTimeInMillis());
260
	            	t_order.setExpected_delivery_time(time.getTimeInMillis());
261
	            } catch(Exception e) {
262
	            	addActionError("Error in updating Shipping or Delivery Time for row number " + rowId);
263
	            	logger.error("Error in updating Shipping or Delivery Time for row number " + rowId,e);
264
	            	continue;
265
	            }
266
 
267
	            InventoryService.Client inventoryClient = null;
268
	            Warehouse fulfillmentWarehouse= null; 
269
	            try {
270
	            	inventoryClient = new InventoryClient().getClient();
271
	            	Cell warehouseCell = row.getCell(WAREHOUSE_ID_INDEX);
272
	            	if(warehouseCell != null && warehouseCell.getCellType() != Cell.CELL_TYPE_BLANK) {
273
	            		fulfillmentWarehouse = inventoryClient.getWarehouse(new Double(row.getCell(WAREHOUSE_ID_INDEX).getNumericCellValue()).longValue());
274
	            	} else {
275
	            		List<Long> itemAvailability = inventoryClient.getItemAvailabilityAtLocation(itemId, 1);
276
	            		fulfillmentWarehouse = inventoryClient.getWarehouse(itemAvailability.get(0));
277
	            	}
278
	            	t_order.setFulfilmentWarehouseId(fulfillmentWarehouse.getId());
8892 amar.kumar 279
 
280
					long billingWarehouseId = 0;
281
					if(fulfillmentWarehouse.getBillingWarehouseId()== 0) {
282
						inventoryClient = new InventoryClient().getClient();
283
						List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, fulfillmentWarehouse.getVendor().getId(), 0, 0);
284
						for(Warehouse warehouse : warehouses) {
285
							if(warehouse.getBillingWarehouseId()!=0) {
286
								billingWarehouseId = warehouse.getBillingWarehouseId();
287
				                break;
288
							}
289
						}
290
					} else {
291
						billingWarehouseId = fulfillmentWarehouse.getBillingWarehouseId();
292
					}
293
 
294
					t_order.setWarehouse_id(billingWarehouseId);
295
					//t_order.setWarehouse_id(fulfillmentWarehouse.getBillingWarehouseId());
8488 amar.kumar 296
	        		VendorItemPricing vendorItemPricing = inventoryClient.getItemPricing(lineItem.getItem_id(), fulfillmentWarehouse.getVendor().getId());
297
	        		t_order.getLineitems().get(0).setTransfer_price(vendorItemPricing.getTransferPrice());
298
	        		t_order.getLineitems().get(0).setNlc(vendorItemPricing.getNlc());
299
				} catch (InventoryServiceException e) {
300
					addActionError("Error in updating WarehouseId for row number " + rowId);
301
					setErrorMsg(getErrorMsg() + "<br>Error in updating WarehouseId for row number  " + rowId);
302
	            	logger.error("Error in updating WarehouseId for row number " + rowId,e);
303
	            	continue;
304
				}
305
 
306
				String provider = row.getCell(COURIER_INDEX).getStringCellValue();
9110 vikram.rag 307
				if(provider.equalsIgnoreCase(FIRSTFLIGHT)) {
8488 amar.kumar 308
					t_order.setLogistics_provider_id(12);
9110 vikram.rag 309
				} else if(provider.equalsIgnoreCase(DELHIVERY)) {
8488 amar.kumar 310
					t_order.setLogistics_provider_id(13);
9110 vikram.rag 311
				} else if(provider.equalsIgnoreCase(BLUEDART)) {
8508 amar.kumar 312
					t_order.setLogistics_provider_id(14);
9110 vikram.rag 313
				} else if(provider.equalsIgnoreCase(ECOM)) {
8796 anupam.sin 314
                    t_order.setLogistics_provider_id(18);
9110 vikram.rag 315
                }else if(provider.equalsIgnoreCase(EWINGS)){
316
    				t_order.setLogistics_provider_id(19);
317
    			}
318
    			else if(provider.equalsIgnoreCase(DTDC)){
319
    				t_order.setLogistics_provider_id(20);
320
    			}
321
    			else if(provider.equalsIgnoreCase(WAREOLOG)){
322
    				t_order.setLogistics_provider_id(21);
323
    			}
324
    			else if(provider.equalsIgnoreCase(MIRAKLE)){
325
    				t_order.setLogistics_provider_id(22);
326
    			}
327
    			else if(provider.equalsIgnoreCase(RAJIV_TRANSPORT)){
328
    				t_order.setLogistics_provider_id(23);
329
    			}
330
    			else if(provider.equalsIgnoreCase(BLUEDART_HIGH_VALUE)){
331
    				t_order.setLogistics_provider_id(24);
332
    			}
333
    			else if(provider.equalsIgnoreCase(BLUEDART_SURFACE)){
334
    				t_order.setLogistics_provider_id(25);
335
    			}
336
    			else if(provider.equalsIgnoreCase(BLUEDART_APEX)){
337
    				t_order.setLogistics_provider_id(26);
338
    			}
339
    			else if(provider.equalsIgnoreCase(ARAMEX)){
340
    				t_order.setLogistics_provider_id(27);
341
    			}
342
    			else if(provider.equalsIgnoreCase(GATI)){
343
    				t_order.setLogistics_provider_id(28);
344
    			}
345
    			else if(provider.equalsIgnoreCase(INDIA_POST)){
346
    				t_order.setLogistics_provider_id(29);
347
    			}
348
    			else if(provider.equalsIgnoreCase(FEDEX)){
349
    				t_order.setLogistics_provider_id(30);
350
    			}
351
    			else if(provider.equalsIgnoreCase(IOT)){
352
    				t_order.setLogistics_provider_id(31);
353
    			}
354
    			else if(provider.equalsIgnoreCase(RED_EXP)){
355
    				t_order.setLogistics_provider_id(32);
356
    			}
357
    			else if(provider.equalsIgnoreCase(VDELIVER)){
358
    				t_order.setLogistics_provider_id(33);
359
    			}
360
    			else if(provider.equalsIgnoreCase(GHARPAY)){
361
    				t_order.setLogistics_provider_id(34);
362
    			}
363
    			else if(provider.equalsIgnoreCase(QUANTIUM)){
364
    				t_order.setLogistics_provider_id(35);
365
    			}
366
    			else if(provider.equalsIgnoreCase(GATI_AIR)){
367
    				t_order.setLogistics_provider_id(36);
9136 vikram.rag 368
    			}
9138 vikram.rag 369
    			else if(provider.equalsIgnoreCase(OVERNITE_EXP)){
9136 vikram.rag 370
    				t_order.setLogistics_provider_id(37);
371
    			}
372
    			else {
8488 amar.kumar 373
					addActionError("Unknown logistics provider found for row number " + rowId);
374
					setErrorMsg(getErrorMsg() + "<br>Unknown logistics provider found for row number " + rowId);
375
	            	logger.error("Unknown logistics provider found for row number " + rowId);
376
	            	continue;
377
				}
378
 
379
				row.getCell(AWB_INDEX).setCellType(Cell.CELL_TYPE_STRING);
380
				t_order.setAirwaybill_no(row.getCell(AWB_INDEX).getStringCellValue());
381
				t_order.setTracking_id(row.getCell(AWB_INDEX).getStringCellValue());
382
	            t_order.setTotal_amount(totalPrice);
383
	            t_order.setOrderType(OrderType.B2C);
384
	            t_order.setSource(SNAPDEAL_SOURCE_ID);
385
	            t_order.setOrderType(OrderType.B2C);
386
	            orders.add(t_order);
387
	            orderCountForRow++;
388
 
389
	            txn.setOrders(orders);
390
	            Client transaction_client = new TransactionClient().getClient();
391
	            try {
392
	            	long subOrderId = new Double(row.getCell(SUBORDER_ID_INDEX).getNumericCellValue()).longValue();
393
	            	String referenceCode = row.getCell(REFERENCE_CODE_INDEX).getStringCellValue();
394
	            	String productName = row.getCell(PRODUCT_NAME_INDEX).getStringCellValue();
395
	            	Date snapdealTxnDate = row.getCell(TRANSACTION_DATE_INDEX).getDateCellValue();
396
 
8802 amar.kumar 397
	            	if(transaction_client.snapdealOrderExists(subOrderId, referenceCode)) {
8488 amar.kumar 398
	            		setErrorMsg(getErrorMsg() + "<br>Duplicate order for subOrderId " + subOrderId + " for row number  " + rowId);
399
	            		logger.error("Duplicate order for subOrderId " + subOrderId + " for row number  " + rowId);
400
	            		continue;
401
	            	}
402
 
403
	            	transactionId =  String.valueOf(transaction_client.createTransaction(txn));
404
	            	createPayment(user, (new Long(subOrderId)).toString(), totalPrice);
405
 
406
	                logger.info("Successfully created transaction: " + transactionId + " for amount: " + totalPrice);
407
 
408
	                Transaction transaction = transaction_client.getTransaction(Long.parseLong(transactionId));
409
	                Order order = transaction.getOrders().get(0);
410
 
411
	                inventoryClient.reserveItemInWarehouse(itemId, fulfillmentWarehouse.getId(), 1, 
412
	                		order.getId(), order.getCreated_timestamp(), order.getPromised_shipping_time(), order.getLineitems().get(0).getQuantity());
413
 
414
 
415
	                SnapdealOrder snapdealOrder = new SnapdealOrder();
416
	                snapdealOrder.setOrderId(order.getId());
417
	                snapdealOrder.setSubOrderId(subOrderId);
418
	                snapdealOrder.setReferenceCode(referenceCode);
419
	                snapdealOrder.setProductName(productName);
420
	                snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
421
	                snapdealOrder.setListingPrice(listingPrice);
422
	                transaction_client.createSnapdealOrder(snapdealOrder);
423
 
424
 
425
	            } catch (Exception e) {
426
	                logger.error("Error while creating order for rowId " + rowId, e);
427
	                addActionError("Error while creating order for rowId " + rowId);
428
	                setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
429
	                continue;
430
	    		}
431
        	} catch (Exception e) {
8748 amar.kumar 432
        		logger.error("Error while creating order for row number " + rowId, e);
8488 amar.kumar 433
        		setErrorMsg(getErrorMsg() + "<br>Error while creating order for row number " + rowId);
434
        		continue;
435
        	}
436
        }
437
 
438
        checkForErrors();
439
        return "authsuccess";
440
    }
441
 
442
    private Date interchangeDateAndMonth(Date date) {
443
		Date updatedDate = new Date(date.getTime());
444
		updatedDate.setDate(date.getMonth() + 1);
445
		updatedDate.setMonth(date.getDate() - 1);
446
		return updatedDate;
447
	}
448
 
449
	private LineItem createLineItem(long itemId, double amount) throws CatalogServiceException, TException {
450
    	LineItem lineItem = new LineItem();
451
    	CatalogService.Client catalogClient = new CatalogClient().getClient();
452
    	Item item = catalogClient.getItem(itemId);
453
 
454
    	lineItem.setProductGroup(item.getProductGroup());
455
        lineItem.setBrand(item.getBrand());
456
        lineItem.setModel_number(item.getModelNumber());
457
        lineItem.setModel_name(item.getModelName());
458
        lineItem.setExtra_info(item.getFeatureDescription());
459
        lineItem.setQuantity(1);
460
        lineItem.setItem_id(item.getId());
461
        lineItem.setUnit_weight(item.getWeight());
462
        lineItem.setTotal_weight(item.getWeight());
463
        lineItem.setUnit_price(amount);
464
        lineItem.setTotal_price(amount);
465
 
466
        if (item.getColor() == null || "NA".equals(item.getColor())) {
467
            lineItem.setColor("");
468
        } else {
469
            lineItem.setColor(item.getColor());
470
        }
471
    	return lineItem;
472
	}
473
 
474
    private void createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {
475
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
476
        long paymentId = client.createPayment(user.getUserId(), amount, SNAPDEAL_GATEWAY_ID, Long.valueOf(transactionId), false);
477
        client.updatePaymentDetails(paymentId, null, null, null, null, null, null, subOrderId, null, PaymentStatus.AUTHORIZED, null, null);
478
    }   
479
 
480
	public String index() {
481
        if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
482
            return "authfail";
483
        checkForErrors();
484
        return "authsuccess";
485
    }
486
 
487
	private boolean checkForErrors(){
488
        Collection<String> actionErrors = getActionErrors();
489
        if(actionErrors != null && !actionErrors.isEmpty()){
490
            for (String str : actionErrors) {
491
                errorMsg += "<BR/>" + str;
492
            }
493
            return true;
494
        }
495
        return false;
496
    }
497
 
498
	@Override
499
	public void setServletRequest(HttpServletRequest request) {
500
		this.request = request;
501
        this.session = request.getSession();
502
	}
503
 
504
	public String getErrorMsg() {
505
		return errorMsg;
506
	}
507
 
508
	public void setErrorMsg(String errorMsg) {
509
		this.errorMsg = errorMsg;
510
	}
511
 
512
	public Long getRowId() {
513
		return rowId;
514
	}
515
 
516
	public void setRowId(Long rowId) {
517
		this.rowId = rowId;
518
	}
519
 
520
	public File getOrderDataFile() {
521
		return orderDataFile;
522
	}
523
 
524
	public void setOrderDataFile(File orderDataFile) {
525
		this.orderDataFile = orderDataFile;
526
	}
527
 
528
}