| 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;
|
|
|
7 |
import java.util.Calendar;
|
|
|
8 |
import java.util.GregorianCalendar;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.ServletOutputStream;
|
|
|
11 |
import javax.servlet.http.HttpServletRequest;
|
|
|
12 |
import javax.servlet.http.HttpServletResponse;
|
|
|
13 |
|
|
|
14 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
15 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
16 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
17 |
import org.apache.struts2.rest.HttpHeaders;
|
| 3062 |
chandransh |
18 |
import org.slf4j.Logger;
|
|
|
19 |
import org.slf4j.LoggerFactory;
|
| 676 |
chandransh |
20 |
|
|
|
21 |
public class ManifestController implements ServletResponseAware, ServletRequestAware {
|
| 756 |
chandransh |
22 |
|
| 3062 |
chandransh |
23 |
private static Logger logger = LoggerFactory.getLogger(ManifestController.class);
|
|
|
24 |
|
| 676 |
chandransh |
25 |
private long warehouseId;
|
|
|
26 |
private long providerId;
|
| 3062 |
chandransh |
27 |
private boolean isCod;
|
|
|
28 |
|
| 676 |
chandransh |
29 |
private HttpServletRequest request;
|
|
|
30 |
private HttpServletResponse response;
|
|
|
31 |
|
|
|
32 |
public HttpHeaders index(){
|
|
|
33 |
this.warehouseId = Long.parseLong(request.getParameter("warehouseID"));
|
|
|
34 |
this.providerId = Long.parseLong(request.getParameter("providerID"));
|
| 3062 |
chandransh |
35 |
try {
|
|
|
36 |
this.isCod = Boolean.parseBoolean(request.getParameter("isCod"));
|
|
|
37 |
} catch (Exception e) {
|
|
|
38 |
this.isCod = false;
|
|
|
39 |
}
|
| 676 |
chandransh |
40 |
|
| 3062 |
chandransh |
41 |
logger.debug("Warehouse Id is: " + warehouseId);
|
|
|
42 |
logger.debug("Provider Id is: " + providerId);
|
|
|
43 |
logger.debug("Cod is: " + isCod);
|
| 676 |
chandransh |
44 |
|
|
|
45 |
Calendar date = new GregorianCalendar();
|
|
|
46 |
int year = date.get(Calendar.YEAR);
|
|
|
47 |
int month = date.get(Calendar.MONTH) +1;
|
|
|
48 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
|
|
49 |
|
| 3062 |
chandransh |
50 |
String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
|
|
51 |
|
| 756 |
chandransh |
52 |
ManifestGenerator manifestGenerator = new ManifestGenerator();
|
| 3062 |
chandransh |
53 |
ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(warehouseId, providerId, isCod);
|
| 756 |
chandransh |
54 |
response.setContentType("application/pdf");
|
|
|
55 |
|
| 3062 |
chandransh |
56 |
response.setHeader("Content-disposition", "inline; filename=manifest-" + fileNameSuffix + ".pdf" );
|
| 676 |
chandransh |
57 |
|
|
|
58 |
ServletOutputStream sos;
|
|
|
59 |
try {
|
|
|
60 |
sos = response.getOutputStream();
|
|
|
61 |
baos.writeTo(sos);
|
|
|
62 |
sos.flush();
|
|
|
63 |
} catch (IOException e) {
|
| 3062 |
chandransh |
64 |
logger.error("Unable to stream the manifest file", e);
|
| 676 |
chandransh |
65 |
}
|
|
|
66 |
return new DefaultHttpHeaders("lsuccess");
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
@Override
|
|
|
70 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
71 |
this.response = response;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
@Override
|
|
|
75 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
76 |
this.request = request;
|
|
|
77 |
}
|
|
|
78 |
}
|