| 21234 |
kshitij.so |
1 |
package in.shop2020.hotspot.dashbaord.server;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
| 21247 |
kshitij.so |
5 |
import in.shop2020.hotspot.dashbaord.shared.actions.BillingType;
|
| 21234 |
kshitij.so |
6 |
import in.shop2020.model.v1.order.ShipmentDelayDetail;
|
|
|
7 |
|
|
|
8 |
import java.io.File;
|
|
|
9 |
import java.io.IOException;
|
|
|
10 |
import java.util.Calendar;
|
|
|
11 |
import java.util.GregorianCalendar;
|
|
|
12 |
import java.util.Iterator;
|
|
|
13 |
import java.util.List;
|
|
|
14 |
|
|
|
15 |
import javax.servlet.ServletException;
|
|
|
16 |
import javax.servlet.http.HttpServlet;
|
|
|
17 |
import javax.servlet.http.HttpServletRequest;
|
|
|
18 |
import javax.servlet.http.HttpServletResponse;
|
|
|
19 |
|
|
|
20 |
import org.apache.commons.fileupload.FileItem;
|
|
|
21 |
import org.apache.commons.fileupload.FileItemFactory;
|
|
|
22 |
import org.apache.commons.fileupload.FileUploadException;
|
|
|
23 |
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
24 |
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|
|
25 |
|
|
|
26 |
import com.google.gwt.core.client.impl.AsyncFragmentLoader.Logger;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Servlet to read xls and process it.
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
@SuppressWarnings("serial")
|
|
|
33 |
public class BulkBillingServlet extends HttpServlet {
|
|
|
34 |
protected void doPost(HttpServletRequest request, HttpServletResponse
|
|
|
35 |
response) throws ServletException, IOException {
|
|
|
36 |
|
| 21238 |
kshitij.so |
37 |
|
| 21241 |
kshitij.so |
38 |
System.out.println("LogisticsTransactionId"+request.getParameter("logisticsTransactionId"));
|
|
|
39 |
System.out.println("PackageDimensions"+request.getParameter("packageDimensions"));
|
| 21234 |
kshitij.so |
40 |
|
|
|
41 |
FileItem uploadItem = getFileItem(request);
|
|
|
42 |
if (uploadItem == null) {
|
|
|
43 |
response.getWriter().write("NO-SCRIPT-DATA");
|
|
|
44 |
return;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
String fileName = "/tmp/"+getTimeInMilliseconds()+".xls";
|
|
|
48 |
File file;
|
|
|
49 |
try {
|
|
|
50 |
file = new File(fileName);
|
|
|
51 |
if(file.exists()){
|
|
|
52 |
response.getWriter().write("File already exists.");
|
|
|
53 |
return;
|
|
|
54 |
}
|
|
|
55 |
uploadItem.write(file);
|
|
|
56 |
} catch (Exception e) {
|
|
|
57 |
// TODO Auto-generated catch block
|
|
|
58 |
e.printStackTrace();
|
|
|
59 |
}
|
| 21250 |
kshitij.so |
60 |
ProcessBulkBilling processBulkBilling = new ProcessBulkBilling(fileName,request.getParameter("logisticsTransactionId")+"",request.getParameter("packageDimensions")+"",in.shop2020.model.v1.inventory.BillingType.valueOf(request.getParameter("billingType")),request.getParameter("username"));
|
| 21238 |
kshitij.so |
61 |
String result = "";
|
|
|
62 |
if (processBulkBilling.processReport()){
|
|
|
63 |
result = processBulkBilling.checkBillingDetails();
|
| 21234 |
kshitij.so |
64 |
}
|
|
|
65 |
else{
|
| 21243 |
kshitij.so |
66 |
result = "Unable to validate uploaded sheet or duplicate serial numbers in sheet.";
|
| 21234 |
kshitij.so |
67 |
}
|
| 21238 |
kshitij.so |
68 |
response.setContentType("text/html");
|
|
|
69 |
response.getWriter().write(result);
|
| 21234 |
kshitij.so |
70 |
}
|
|
|
71 |
|
|
|
72 |
private long getTimeInMilliseconds(){
|
|
|
73 |
Calendar cal=GregorianCalendar.getInstance();
|
|
|
74 |
return cal.getTimeInMillis();
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
private FileItem getFileItem(HttpServletRequest request){
|
|
|
78 |
FileItemFactory factory = new DiskFileItemFactory();
|
|
|
79 |
ServletFileUpload upload = new ServletFileUpload(factory);
|
|
|
80 |
try {
|
|
|
81 |
List items = upload.parseRequest(request);
|
|
|
82 |
Iterator it = items.iterator();
|
|
|
83 |
while (it.hasNext()) {
|
|
|
84 |
FileItem item = (FileItem) it.next();
|
|
|
85 |
if (!item.isFormField() && "file".equals(item.getFieldName())){
|
|
|
86 |
return item;
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
} catch (FileUploadException e){
|
|
|
90 |
return null;
|
|
|
91 |
}
|
|
|
92 |
return null;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
}
|