| Line 22... |
Line 22... |
| 22 |
import javax.servlet.http.HttpSession;
|
22 |
import javax.servlet.http.HttpSession;
|
| 23 |
|
23 |
|
| 24 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
24 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
| 25 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
25 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
| 26 |
import org.apache.struts2.util.ServletContextAware;
|
26 |
import org.apache.struts2.util.ServletContextAware;
|
| - |
|
27 |
import org.slf4j.Logger;
|
| - |
|
28 |
import org.slf4j.LoggerFactory;
|
| 27 |
|
29 |
|
| 28 |
/**
|
30 |
/**
|
| 29 |
* Allows executives of courier companies to login and download courier details
|
31 |
* Allows executives of courier companies to login and download courier details
|
| 30 |
* report which they then use to upload into their database.
|
32 |
* report which they then use to upload into their database.
|
| 31 |
*
|
33 |
*
|
| 32 |
* @author Chandranshu
|
34 |
* @author Chandranshu
|
| 33 |
*
|
35 |
*
|
| 34 |
*/
|
36 |
*/
|
| 35 |
public class CourierDetailsController implements ServletResponseAware,
|
37 |
public class CourierDetailsController implements ServletResponseAware,
|
| 36 |
ServletRequestAware, ServletContextAware {
|
38 |
ServletRequestAware, ServletContextAware {
|
| - |
|
39 |
|
| - |
|
40 |
private static Logger logger = LoggerFactory.getLogger(CourierDetailsController.class);
|
| - |
|
41 |
|
| 37 |
private String id;
|
42 |
private String id;
|
| 38 |
private int daysToSubtract;
|
43 |
private int daysToSubtract;
|
| 39 |
|
44 |
|
| 40 |
//FIXME: Read this configuration from the config client
|
45 |
//FIXME: Read this configuration from the config client
|
| 41 |
private String courierDetailsPath = "/CourierDetailReports";
|
46 |
private String courierDetailsPath = "/CourierDetailReports";
|
| Line 72... |
Line 77... |
| 72 |
// Handler for GET /courier-details/<warehouseId>
|
77 |
// Handler for GET /courier-details/<warehouseId>
|
| 73 |
public String show(){
|
78 |
public String show(){
|
| 74 |
try {
|
79 |
try {
|
| 75 |
long warehouseId = Long.parseLong(getId());
|
80 |
long warehouseId = Long.parseLong(getId());
|
| 76 |
long providerId = ((Long)session.getAttribute("providerId")).longValue();
|
81 |
long providerId = ((Long)session.getAttribute("providerId")).longValue();
|
| - |
|
82 |
boolean isCod;
|
| 77 |
|
83 |
try {
|
| - |
|
84 |
isCod = Boolean.parseBoolean(request.getParameter("isCod"));
|
| - |
|
85 |
} catch (Exception e) {
|
| - |
|
86 |
isCod = false;
|
| - |
|
87 |
}
|
| 78 |
System.out.println("Warehouse Id is: " + warehouseId);
|
88 |
System.out.println("Warehouse Id is: " + warehouseId);
|
| 79 |
System.out.println("Provider Id is: " + providerId);
|
89 |
System.out.println("Provider Id is: " + providerId);
|
| 80 |
|
90 |
|
| - |
|
91 |
String deliveryType = "prepaid";
|
| - |
|
92 |
if(isCod)
|
| - |
|
93 |
deliveryType = "cod";
|
| - |
|
94 |
|
| 81 |
response.setContentType("application/vnd.ms-excel");
|
95 |
response.setContentType("application/vnd.ms-excel");
|
| 82 |
|
96 |
|
| 83 |
Calendar date = new GregorianCalendar();
|
97 |
Calendar date = new GregorianCalendar();
|
| 84 |
date.add(Calendar.DAY_OF_MONTH, daysToSubtract);
|
98 |
date.add(Calendar.DAY_OF_MONTH, daysToSubtract);
|
| 85 |
int year = date.get(Calendar.YEAR);
|
99 |
int year = date.get(Calendar.YEAR);
|
| 86 |
int month = date.get(Calendar.MONTH) +1;
|
100 |
int month = date.get(Calendar.MONTH) +1;
|
| 87 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
101 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
| 88 |
String fileName = courierDetailsPath + "/courier-details-"+warehouseId+"-"+ providerId + "-"+year+"-"+ month+"-" + day +".xls";
|
102 |
String fileName = courierDetailsPath + "/courier-details-" + deliveryType + "-" + warehouseId + "-" + providerId + "-" + year + "-" + month + "-" + day +".xls";
|
| 89 |
response.setHeader("Content-disposition", "inline; filename=courier-details-"+warehouseId+"-"+ providerId + "-"+year+"-"+ month+"-" + day +".xls" );
|
103 |
response.setHeader("Content-disposition", "inline; filename=courier-details-" + deliveryType + "-" + warehouseId + "-" + providerId + "-" + year + "-"+ month + "-" + day +".xls" );
|
| 90 |
|
104 |
|
| 91 |
ServletOutputStream sos;
|
105 |
ServletOutputStream sos;
|
| 92 |
try {
|
106 |
try {
|
| 93 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
107 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
| 94 |
baos.write(getBytesFromFile(new File(fileName)));
|
108 |
baos.write(getBytesFromFile(new File(fileName)));
|
| 95 |
sos = response.getOutputStream();
|
109 |
sos = response.getOutputStream();
|
| 96 |
baos.writeTo(sos);
|
110 |
baos.writeTo(sos);
|
| 97 |
sos.flush();
|
111 |
sos.flush();
|
| 98 |
} catch (IOException e) {
|
112 |
} catch (IOException e) {
|
| 99 |
e.printStackTrace();
|
113 |
logger.error("Unable to stream the courier details report", e);
|
| 100 |
}
|
114 |
}
|
| 101 |
return "authsuccess";
|
115 |
return "authsuccess";
|
| 102 |
}catch(NumberFormatException nfe){
|
116 |
}catch(NumberFormatException nfe){
|
| 103 |
nfe.printStackTrace();
|
117 |
logger.error("Unable to parse the warehouse id", nfe);
|
| 104 |
}
|
118 |
}
|
| 105 |
return "authfail";
|
119 |
return "authfail";
|
| 106 |
}
|
120 |
}
|
| 107 |
|
121 |
|
| 108 |
public String dayBefore(){
|
122 |
public String dayBefore(){
|