| 8182 |
amar.kumar |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
4 |
import in.shop2020.model.v1.catalog.EbayItem;
|
|
|
5 |
import in.shop2020.model.v1.order.EbayOrder;
|
|
|
6 |
import in.shop2020.model.v1.order.Order;
|
|
|
7 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
8 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
9 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
10 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
11 |
|
|
|
12 |
import java.io.File;
|
|
|
13 |
import java.io.FileInputStream;
|
|
|
14 |
import java.io.IOException;
|
|
|
15 |
import java.text.SimpleDateFormat;
|
|
|
16 |
import java.util.Collection;
|
|
|
17 |
import java.util.Date;
|
|
|
18 |
|
|
|
19 |
import javax.servlet.http.HttpServletRequest;
|
|
|
20 |
import javax.servlet.http.HttpSession;
|
|
|
21 |
|
|
|
22 |
import org.apache.commons.io.FileUtils;
|
|
|
23 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
24 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
25 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
26 |
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
27 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
28 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
29 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
30 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
31 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
32 |
import org.slf4j.Logger;
|
|
|
33 |
import org.slf4j.LoggerFactory;
|
|
|
34 |
|
|
|
35 |
import com.opensymphony.xwork2.ActionSupport;
|
|
|
36 |
|
|
|
37 |
@SuppressWarnings("serial")
|
|
|
38 |
@InterceptorRefs({
|
|
|
39 |
@InterceptorRef("defaultStack"),
|
|
|
40 |
@InterceptorRef("login")
|
|
|
41 |
})
|
|
|
42 |
@Results({
|
|
|
43 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
44 |
})
|
|
|
45 |
public class EbayColorChangeController extends ActionSupport implements ServletRequestAware {
|
|
|
46 |
|
|
|
47 |
private static Logger logger = LoggerFactory.getLogger(EbayColorChangeController.class);
|
|
|
48 |
|
|
|
49 |
private static final int PAISAPAYID_INDEX = 0;
|
|
|
50 |
private static final int SALES_REC_NUM_INDEX = 1;
|
|
|
51 |
private static final int NEW_ITEM_ID_INDEX = 2;
|
|
|
52 |
|
|
|
53 |
private HttpServletRequest request;
|
|
|
54 |
private HttpSession session;
|
|
|
55 |
|
|
|
56 |
private String errorMsg = "";
|
|
|
57 |
|
|
|
58 |
private File listingFile;
|
|
|
59 |
|
|
|
60 |
public String create() throws IOException {
|
|
|
61 |
Workbook wb = new HSSFWorkbook(new FileInputStream(listingFile));
|
|
|
62 |
|
|
|
63 |
int totalNumRows = 0;
|
|
|
64 |
int successfullyProcessedNumRows = 0;
|
|
|
65 |
for (Row row : wb.getSheetAt(0)) {
|
|
|
66 |
String key = "";
|
|
|
67 |
try {
|
|
|
68 |
totalNumRows++;
|
|
|
69 |
if(totalNumRows==1) {
|
|
|
70 |
continue;
|
|
|
71 |
}
|
|
|
72 |
row.getCell(PAISAPAYID_INDEX).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
73 |
String paisaPayId = row.getCell(PAISAPAYID_INDEX).getStringCellValue();
|
|
|
74 |
Long itemId = new Double(row.getCell(NEW_ITEM_ID_INDEX).getNumericCellValue()).longValue();
|
|
|
75 |
Long salesRecordNumber = new Double(row.getCell(SALES_REC_NUM_INDEX).getNumericCellValue()).longValue();
|
|
|
76 |
TransactionService.Client transactionClient = new TransactionClient().getClient();
|
|
|
77 |
EbayOrder ebayOrder = transactionClient.getEbayOrderBySalesRecNumber(salesRecordNumber);
|
|
|
78 |
if(ebayOrder.getPaisaPayId().equals(paisaPayId)) {
|
|
|
79 |
Order order = transactionClient.getOrder(ebayOrder.getOrderId());
|
|
|
80 |
transactionClient.changeItem(order.getId(), itemId);
|
|
|
81 |
} else {
|
|
|
82 |
logger.error("Mismatch for paisaPayId : " + paisaPayId + " and salesRecordNumber : " + salesRecordNumber);
|
|
|
83 |
setErrorMsg(getErrorMsg() + "<br/>Mismatch for paisaPayId : " + paisaPayId + " and salesRecordNumber : " + salesRecordNumber);
|
|
|
84 |
addActionError("Mismatch for paisaPayId : " + paisaPayId + " and salesRecordNumber : " + salesRecordNumber);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
successfullyProcessedNumRows++;
|
|
|
88 |
} catch (Exception e) {
|
|
|
89 |
logger.error(e + "\n" + e.getMessage() + e.getCause());
|
|
|
90 |
setErrorMsg(getErrorMsg() + "<br/>Error in row number " + totalNumRows);
|
|
|
91 |
addActionError("Error in row number " + totalNumRows);
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
if(errorMsg.isEmpty()) {
|
|
|
95 |
setErrorMsg("Sucessfully uploaded listings");
|
|
|
96 |
}
|
|
|
97 |
return "authsuccess";
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public String index() {
|
|
|
101 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/ebay-dashboard"))
|
|
|
102 |
return "authfail";
|
|
|
103 |
return "authsuccess";
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
@Override
|
|
|
107 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
108 |
this.request = request;
|
|
|
109 |
this.session = request.getSession();
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public String getErrorMsg() {
|
|
|
113 |
return errorMsg;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
public void setErrorMsg(String errorMsg) {
|
|
|
117 |
this.errorMsg = errorMsg;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public File getListingFile() {
|
|
|
121 |
return listingFile;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public void setListingFile(File listingFile) {
|
|
|
125 |
this.listingFile = listingFile;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
}
|