| 676 |
chandransh |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.support.services.ManifestGenerator;
|
|
|
4 |
|
|
|
5 |
import java.io.ByteArrayOutputStream;
|
|
|
6 |
import java.io.IOException;
|
| 4788 |
rajveer |
7 |
import java.util.ArrayList;
|
| 676 |
chandransh |
8 |
import java.util.Calendar;
|
|
|
9 |
import java.util.GregorianCalendar;
|
| 4788 |
rajveer |
10 |
import java.util.List;
|
| 676 |
chandransh |
11 |
|
|
|
12 |
import javax.servlet.ServletOutputStream;
|
|
|
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
import javax.servlet.http.HttpServletResponse;
|
|
|
15 |
|
|
|
16 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
17 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
18 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
19 |
import org.apache.struts2.rest.HttpHeaders;
|
| 3062 |
chandransh |
20 |
import org.slf4j.Logger;
|
|
|
21 |
import org.slf4j.LoggerFactory;
|
| 676 |
chandransh |
22 |
|
|
|
23 |
public class ManifestController implements ServletResponseAware, ServletRequestAware {
|
| 756 |
chandransh |
24 |
|
| 3062 |
chandransh |
25 |
private static Logger logger = LoggerFactory.getLogger(ManifestController.class);
|
|
|
26 |
|
| 676 |
chandransh |
27 |
private long warehouseId;
|
|
|
28 |
private long providerId;
|
| 3062 |
chandransh |
29 |
private boolean isCod;
|
| 4788 |
rajveer |
30 |
private String orderIdsString;
|
| 5678 |
rajveer |
31 |
private long storeId;
|
| 5743 |
rajveer |
32 |
private String runner;
|
| 3062 |
chandransh |
33 |
|
| 676 |
chandransh |
34 |
private HttpServletRequest request;
|
|
|
35 |
private HttpServletResponse response;
|
|
|
36 |
|
| 5678 |
rajveer |
37 |
|
| 676 |
chandransh |
38 |
public HttpHeaders index(){
|
| 5678 |
rajveer |
39 |
if(request.getParameter("storeId") !=null){
|
|
|
40 |
this.storeId = Long.parseLong(request.getParameter("storeId"));
|
|
|
41 |
}
|
|
|
42 |
if(this.storeId == 0){
|
|
|
43 |
this.warehouseId = Long.parseLong(request.getParameter("warehouseID"));
|
|
|
44 |
try {
|
|
|
45 |
this.isCod = Boolean.parseBoolean(request.getParameter("isCod"));
|
|
|
46 |
} catch (Exception e) {
|
|
|
47 |
this.isCod = false;
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
| 676 |
chandransh |
51 |
this.providerId = Long.parseLong(request.getParameter("providerID"));
|
| 4788 |
rajveer |
52 |
this.orderIdsString = request.getParameter("orderIds");
|
| 5743 |
rajveer |
53 |
this.runner = request.getParameter("runner");
|
| 676 |
chandransh |
54 |
|
| 5678 |
rajveer |
55 |
|
| 3062 |
chandransh |
56 |
logger.debug("Warehouse Id is: " + warehouseId);
|
|
|
57 |
logger.debug("Provider Id is: " + providerId);
|
|
|
58 |
logger.debug("Cod is: " + isCod);
|
| 4788 |
rajveer |
59 |
logger.debug("Order Ids are: " + orderIdsString);
|
| 676 |
chandransh |
60 |
|
| 4788 |
rajveer |
61 |
List<Long> orderIds = new ArrayList<Long>();
|
|
|
62 |
for(String orderIdString: orderIdsString.split(":")){
|
|
|
63 |
orderIds.add(Long.parseLong(orderIdString));
|
|
|
64 |
}
|
| 676 |
chandransh |
65 |
Calendar date = new GregorianCalendar();
|
|
|
66 |
int year = date.get(Calendar.YEAR);
|
|
|
67 |
int month = date.get(Calendar.MONTH) +1;
|
|
|
68 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
|
|
69 |
|
| 3062 |
chandransh |
70 |
String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
|
|
71 |
|
| 756 |
chandransh |
72 |
ManifestGenerator manifestGenerator = new ManifestGenerator();
|
| 5678 |
rajveer |
73 |
ByteArrayOutputStream baos;
|
|
|
74 |
if(storeId == 0){
|
| 5743 |
rajveer |
75 |
baos = manifestGenerator.generateManifestFile(warehouseId, providerId, isCod, orderIds, runner);
|
| 5678 |
rajveer |
76 |
}else{
|
| 5714 |
rajveer |
77 |
List<String> awbs = new ArrayList<String>();
|
|
|
78 |
for(String awb: request.getParameter("awbs").split(":")){
|
|
|
79 |
awbs.add(awb);
|
|
|
80 |
}
|
|
|
81 |
baos = manifestGenerator.generateManifestFile(providerId, storeId, orderIds, awbs);
|
| 5678 |
rajveer |
82 |
}
|
| 756 |
chandransh |
83 |
response.setContentType("application/pdf");
|
|
|
84 |
|
| 3062 |
chandransh |
85 |
response.setHeader("Content-disposition", "inline; filename=manifest-" + fileNameSuffix + ".pdf" );
|
| 676 |
chandransh |
86 |
|
|
|
87 |
ServletOutputStream sos;
|
|
|
88 |
try {
|
|
|
89 |
sos = response.getOutputStream();
|
|
|
90 |
baos.writeTo(sos);
|
|
|
91 |
sos.flush();
|
|
|
92 |
} catch (IOException e) {
|
| 3062 |
chandransh |
93 |
logger.error("Unable to stream the manifest file", e);
|
| 676 |
chandransh |
94 |
}
|
|
|
95 |
return new DefaultHttpHeaders("lsuccess");
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
@Override
|
|
|
99 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
100 |
this.response = response;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
@Override
|
|
|
104 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
105 |
this.request = request;
|
|
|
106 |
}
|
|
|
107 |
}
|