| 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;
|
| 3062 |
chandransh |
31 |
|
| 676 |
chandransh |
32 |
private HttpServletRequest request;
|
|
|
33 |
private HttpServletResponse response;
|
|
|
34 |
|
|
|
35 |
public HttpHeaders index(){
|
|
|
36 |
this.warehouseId = Long.parseLong(request.getParameter("warehouseID"));
|
|
|
37 |
this.providerId = Long.parseLong(request.getParameter("providerID"));
|
| 4788 |
rajveer |
38 |
this.orderIdsString = request.getParameter("orderIds");
|
| 3062 |
chandransh |
39 |
try {
|
|
|
40 |
this.isCod = Boolean.parseBoolean(request.getParameter("isCod"));
|
|
|
41 |
} catch (Exception e) {
|
|
|
42 |
this.isCod = false;
|
|
|
43 |
}
|
| 676 |
chandransh |
44 |
|
| 3062 |
chandransh |
45 |
logger.debug("Warehouse Id is: " + warehouseId);
|
|
|
46 |
logger.debug("Provider Id is: " + providerId);
|
|
|
47 |
logger.debug("Cod is: " + isCod);
|
| 4788 |
rajveer |
48 |
logger.debug("Order Ids are: " + orderIdsString);
|
| 676 |
chandransh |
49 |
|
| 4788 |
rajveer |
50 |
List<Long> orderIds = new ArrayList<Long>();
|
|
|
51 |
for(String orderIdString: orderIdsString.split(":")){
|
|
|
52 |
orderIds.add(Long.parseLong(orderIdString));
|
|
|
53 |
}
|
| 676 |
chandransh |
54 |
Calendar date = new GregorianCalendar();
|
|
|
55 |
int year = date.get(Calendar.YEAR);
|
|
|
56 |
int month = date.get(Calendar.MONTH) +1;
|
|
|
57 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
|
|
58 |
|
| 3062 |
chandransh |
59 |
String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
|
|
60 |
|
| 756 |
chandransh |
61 |
ManifestGenerator manifestGenerator = new ManifestGenerator();
|
| 4788 |
rajveer |
62 |
ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(warehouseId, providerId, isCod, orderIds);
|
| 756 |
chandransh |
63 |
response.setContentType("application/pdf");
|
|
|
64 |
|
| 3062 |
chandransh |
65 |
response.setHeader("Content-disposition", "inline; filename=manifest-" + fileNameSuffix + ".pdf" );
|
| 676 |
chandransh |
66 |
|
|
|
67 |
ServletOutputStream sos;
|
|
|
68 |
try {
|
|
|
69 |
sos = response.getOutputStream();
|
|
|
70 |
baos.writeTo(sos);
|
|
|
71 |
sos.flush();
|
|
|
72 |
} catch (IOException e) {
|
| 3062 |
chandransh |
73 |
logger.error("Unable to stream the manifest file", e);
|
| 676 |
chandransh |
74 |
}
|
|
|
75 |
return new DefaultHttpHeaders("lsuccess");
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
80 |
this.response = response;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
@Override
|
|
|
84 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
85 |
this.request = request;
|
|
|
86 |
}
|
|
|
87 |
}
|