Subversion Repositories SmartDukaan

Rev

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

Rev 3125 Rev 3213
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.InventoryServiceException;
3
import in.shop2020.model.v1.catalog.Warehouse;
4
import in.shop2020.model.v1.catalog.Warehouse;
4
import in.shop2020.model.v1.order.LineItem;
5
import in.shop2020.model.v1.order.LineItem;
5
import in.shop2020.model.v1.order.Order;
6
import in.shop2020.model.v1.order.Order;
6
import in.shop2020.model.v1.order.TransactionServiceException;
7
import in.shop2020.model.v1.order.TransactionServiceException;
7
import in.shop2020.support.utils.ReportsUtils;
8
import in.shop2020.support.utils.ReportsUtils;
Line 37... Line 38...
37
import org.apache.struts2.interceptor.ServletRequestAware;
38
import org.apache.struts2.interceptor.ServletRequestAware;
38
import org.apache.struts2.interceptor.ServletResponseAware;
39
import org.apache.struts2.interceptor.ServletResponseAware;
39
import org.apache.struts2.rest.DefaultHttpHeaders;
40
import org.apache.struts2.rest.DefaultHttpHeaders;
40
import org.apache.struts2.rest.HttpHeaders;
41
import org.apache.struts2.rest.HttpHeaders;
41
import org.apache.struts2.util.ServletContextAware;
42
import org.apache.struts2.util.ServletContextAware;
-
 
43
import org.apache.thrift.TException;
-
 
44
import org.slf4j.Logger;
-
 
45
import org.slf4j.LoggerFactory;
42
 
46
 
43
/**
47
/**
44
 * 
48
 * 
45
 * @author Varun Gupta
49
 * @author Varun Gupta
46
 * @version 1.0
50
 * @version 1.0
Line 53... Line 57...
53
    @InterceptorRef("defaultStack"),
57
    @InterceptorRef("defaultStack"),
54
    @InterceptorRef("login")
58
    @InterceptorRef("login")
55
})
59
})
56
public class HotspotReconciliationController implements ServletResponseAware, ServletRequestAware, ServletContextAware {
60
public class HotspotReconciliationController implements ServletResponseAware, ServletRequestAware, ServletContextAware {
57
 
61
 
-
 
62
    private static Logger logger = LoggerFactory.getLogger(HotspotReconciliationController.class);
-
 
63
    
58
	private enum ReportColumn{
64
	private enum ReportColumn{
59
	    ORDER_ID(0),
65
	    ORDER_ID(0),
60
		BILLING_NUMBER(1),
66
		BILLING_NUMBER(1),
61
		BILLING_DATE(2),
67
		BILLING_DATE(2),
62
		CUSTOMER_NAME(3),
68
		CUSTOMER_NAME(3),
Line 98... Line 104...
98
	}
104
	}
99
	
105
	
100
	// Handles the POST request (Form Submission)
106
	// Handles the POST request (Form Submission)
101
	public HttpHeaders create(){
107
	public HttpHeaders create(){
102
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
108
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
103
		Date startDate = null;
-
 
104
		Date endDate = null;
-
 
105
 
109
		
106
		try	{
110
		try	{
107
			//Formatting Form input parameters
111
			//Formatting Form input parameters
108
			startDate = dateFormat.parse(request.getParameter("start"));
112
		    Date startDate = dateFormat.parse(request.getParameter("start"));
109
			endDate = dateFormat.parse(request.getParameter("end"));
113
		    Date endDate = dateFormat.parse(request.getParameter("end"));
110
			
114
			
111
			CatalogClient csc = new CatalogClient();
115
			CatalogClient csc = new CatalogClient();
112
			in.shop2020.model.v1.catalog.InventoryService.Client catalogClient= csc.getClient();
116
			in.shop2020.model.v1.catalog.InventoryService.Client catalogClient= csc.getClient();
113
			List<Warehouse> warehouses = catalogClient.getAllWarehouses(true);
117
			List<Warehouse> warehouses = catalogClient.getAllWarehouses(true);
114
 
118
 
Line 119... Line 123...
119
 
123
 
120
			//Retrieving all the orders across all the warehouses
124
			//Retrieving all the orders across all the warehouses
121
			for(Warehouse warehouse : warehouses)	{
125
			for(Warehouse warehouse : warehouses)	{
122
				orders.addAll(client.getOrdersByBillingDate(null, startDate.getTime(), endDate.getTime(), warehouse.getId()));
126
				orders.addAll(client.getOrdersByBillingDate(null, startDate.getTime(), endDate.getTime(), warehouse.getId()));
123
			}
127
			}
124
			System.out.println("Total number of Orders: " + orders.size());
128
			logger.debug("Total number of Orders: " + orders.size());
125
			
129
			
126
			// Preparing XLS file for output
130
			// Preparing XLS file for output
127
			response.setContentType("application/vnd.ms-excel");
131
			response.setContentType("application/vnd.ms-excel");
128
			
132
			
129
			
133
			
Line 135... Line 139...
135
				ByteArrayOutputStream baos = getSpreadSheetData(orders, startDate, endDate);
139
				ByteArrayOutputStream baos = getSpreadSheetData(orders, startDate, endDate);
136
				sos = response.getOutputStream();
140
				sos = response.getOutputStream();
137
				baos.writeTo(sos);
141
				baos.writeTo(sos);
138
				sos.flush();
142
				sos.flush();
139
			} catch (IOException e) {
143
			} catch (IOException e) {
140
				e.printStackTrace();
144
				logger.error("Error while streaming the hotspot reconciliation report", e);
141
			}
145
			}
142
 
146
 
143
		} catch (ParseException e)	{
147
		} catch (ParseException e)	{
144
			e.printStackTrace();
148
			logger.error("Unable to parse the start or end date", e);
145
		} catch (TransactionServiceException e)	{
149
		} catch (TransactionServiceException e)	{
-
 
150
			logger.error("Error while getting order information from the transaction service", e);
146
			e.printStackTrace();
151
		} catch (InventoryServiceException e) {
-
 
152
		    logger.error("Error while getting the list of warehouses from the catalog service", e);
147
		} catch (Exception e)	{
153
        } catch (TException e) {
148
			e.printStackTrace();
154
            logger.error("Unable to get the orders or the warehouses", e);
149
		} finally	{
155
        } catch (Exception e)   {
150
			System.out.println(startDate.getTime() + "  |  " + endDate.getTime());
156
            logger.error("Unexpected exception", e);
151
		}
157
        }
152
		return new DefaultHttpHeaders("report");
158
		return new DefaultHttpHeaders("report");
153
	}
159
	}
154
	
160
	
155
	// Prepares the XLS worksheet object and fills in the data with proper formatting
161
	// Prepares the XLS worksheet object and fills in the data with proper formatting
156
	private ByteArrayOutputStream getSpreadSheetData(List <Order> orders, Date startDate, Date endDate)	{
162
	private ByteArrayOutputStream getSpreadSheetData(List <Order> orders, Date startDate, Date endDate)	{
Line 226... Line 232...
226
		// Write the workbook to the output stream
232
		// Write the workbook to the output stream
227
		try {
233
		try {
228
			wb.write(baosXLS);
234
			wb.write(baosXLS);
229
			baosXLS.close();
235
			baosXLS.close();
230
		} catch (IOException e) {
236
		} catch (IOException e) {
231
			e.printStackTrace();
237
			logger.error("Unable to write the hotspot reconciliation report to the byte array", e);
232
		}		
238
		}		
233
		return baosXLS;
239
		return baosXLS;
234
	}
240
	}
235
	
241
	
236
	public String getId(){
242
	public String getId(){