Subversion Repositories SmartDukaan

Rev

Rev 1023 | Rev 2904 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1023 Rev 1075
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.model.v1.catalog.Warehouse;
3
import in.shop2020.model.v1.catalog.Warehouse;
4
import in.shop2020.support.services.CourierDetailsGenerator;
-
 
5
import in.shop2020.thrift.clients.CatalogServiceClient;
4
import in.shop2020.thrift.clients.CatalogServiceClient;
6
import in.shop2020.thrift.clients.HelperServiceClient;
5
import in.shop2020.thrift.clients.HelperServiceClient;
7
import in.shop2020.utils.HelperService;
-
 
8
import in.shop2020.utils.LogisticsUser;
6
import in.shop2020.utils.LogisticsUser;
9
 
7
 
10
import java.io.ByteArrayOutputStream;
8
import java.io.ByteArrayOutputStream;
11
import java.io.File;
9
import java.io.File;
12
import java.io.FileInputStream;
10
import java.io.FileInputStream;
Line 15... Line 13...
15
import java.util.GregorianCalendar;
13
import java.util.GregorianCalendar;
16
import java.util.HashMap;
14
import java.util.HashMap;
17
import java.util.List;
15
import java.util.List;
18
import java.util.Map;
16
import java.util.Map;
19
 
17
 
-
 
18
import javax.servlet.ServletContext;
20
import javax.servlet.ServletOutputStream;
19
import javax.servlet.ServletOutputStream;
21
import javax.servlet.http.HttpServletRequest;
20
import javax.servlet.http.HttpServletRequest;
22
import javax.servlet.http.HttpServletResponse;
21
import javax.servlet.http.HttpServletResponse;
23
import javax.servlet.http.HttpSession;
22
import javax.servlet.http.HttpSession;
24
 
23
 
25
import org.apache.struts2.interceptor.ServletRequestAware;
24
import org.apache.struts2.interceptor.ServletRequestAware;
26
import org.apache.struts2.interceptor.ServletResponseAware;
25
import org.apache.struts2.interceptor.ServletResponseAware;
27
import org.apache.struts2.rest.DefaultHttpHeaders;
26
import org.apache.struts2.util.ServletContextAware;
28
import org.apache.struts2.rest.HttpHeaders;
-
 
29
 
27
 
-
 
28
//@Results({
-
 
29
//	@Result(name="authsuccess", type="httpheader", params = {})
-
 
30
//})
30
public class CourierDetailsController implements ServletResponseAware,
31
public class CourierDetailsController implements ServletResponseAware,
31
		ServletRequestAware {
32
		ServletRequestAware, ServletContextAware {
32
	private String id;
33
	private String id;
-
 
34
	private int daysToSubtract;
33
	
35
	
34
	//FIXME: Read this configuration from the config client
36
	//FIXME: Read this configuration from the config client
35
	private String courierDetailsPath = "/CourierDetailReports";
37
	private String courierDetailsPath = "/CourierDetailReports";
36
	
38
	
-
 
39
	private ServletContext context;
37
	private HttpServletRequest request;
40
	private HttpServletRequest request;
38
	private HttpServletResponse response;
41
	private HttpServletResponse response;
39
	private HttpSession session;
42
	private HttpSession session;
40
 
43
 
41
	public String index(){
44
	public String index(){
Line 72... Line 75...
72
			System.out.println("Provider Id is: " + providerId);
75
			System.out.println("Provider Id is: " + providerId);
73
			
76
			
74
			response.setContentType("application/vnd.ms-excel");
77
			response.setContentType("application/vnd.ms-excel");
75
			
78
			
76
			Calendar date = new GregorianCalendar();
79
			Calendar date = new GregorianCalendar();
-
 
80
			date.add(Calendar.DAY_OF_MONTH, daysToSubtract);
77
			int year = date.get(Calendar.YEAR);
81
			int year = date.get(Calendar.YEAR);
78
			int month = date.get(Calendar.MONTH) +1;
82
			int month = date.get(Calendar.MONTH) +1;
79
			int day = date.get(Calendar.DAY_OF_MONTH);
83
			int day = date.get(Calendar.DAY_OF_MONTH);
80
			String fileName = courierDetailsPath + "/courier-details-"+warehouseId+"-"+ providerId + "-"+year+"-"+ month+"-" + day +".xls";
84
			String fileName = courierDetailsPath + "/courier-details-"+warehouseId+"-"+ providerId + "-"+year+"-"+ month+"-" + day +".xls";
81
			response.setHeader("Content-disposition", "inline; filename=courier-details-"+warehouseId+"-"+ providerId + "-"+year+"-"+ month+"-" + day +".xls" );
85
			response.setHeader("Content-disposition", "inline; filename=courier-details-"+warehouseId+"-"+ providerId + "-"+year+"-"+ month+"-" + day +".xls" );
Line 95... Line 99...
95
			nfe.printStackTrace();
99
			nfe.printStackTrace();
96
		}
100
		}
97
		return "authfail";
101
		return "authfail";
98
	}
102
	}
99
	
103
	
-
 
104
	public String dayBefore(){
-
 
105
		daysToSubtract = -2;
-
 
106
		return show();
-
 
107
	}
-
 
108
	
-
 
109
	public String yesterday(){
-
 
110
		daysToSubtract = -1;
-
 
111
		return show();
-
 
112
	}
-
 
113
	
-
 
114
	public String today(){
-
 
115
		daysToSubtract = 0;
-
 
116
		return show();
-
 
117
	}
-
 
118
	
100
	// Returns the contents of the file in a byte array.
119
	// Returns the contents of the file in a byte array.
101
	public static byte[] getBytesFromFile(File file) throws IOException {
120
	public static byte[] getBytesFromFile(File file) throws IOException {
102
	    FileInputStream is = new FileInputStream(file);
121
	    FileInputStream is = new FileInputStream(file);
103
	    
122
	    
104
	    // Get the size of the file
123
	    // Get the size of the file
Line 132... Line 151...
132
	    is.close();
151
	    is.close();
133
	    return bytes;
152
	    return bytes;
134
	}
153
	}
135
	
154
	
136
	@Override
155
	@Override
-
 
156
	public void setServletContext(ServletContext context) {
-
 
157
		this.context = context;
-
 
158
	}
-
 
159
	
-
 
160
	@Override
137
	public void setServletResponse(HttpServletResponse response) {
161
	public void setServletResponse(HttpServletResponse response) {
138
		this.response  = response;
162
		this.response  = response;
139
	}
163
	}
140
 
164
 
141
	@Override
165
	@Override
Line 169... Line 193...
169
			e.printStackTrace();
193
			e.printStackTrace();
170
		}
194
		}
171
		return warehouseMap;
195
		return warehouseMap;
172
	}
196
	}
173
 
197
 
-
 
198
	public String getServletContextPath(){
-
 
199
		return context.getContextPath();
-
 
200
	}
174
}
201
}