Subversion Repositories SmartDukaan

Rev

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

Rev 4305 Rev 5055
Line 9... Line 9...
9
 
9
 
10
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.catalog.Item;
11
import in.shop2020.model.v1.catalog.ProductNotificationRequest;
11
import in.shop2020.model.v1.catalog.ProductNotificationRequest;
12
import in.shop2020.model.v1.catalog.ProductNotificationRequestCount;
12
import in.shop2020.model.v1.catalog.ProductNotificationRequestCount;
13
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.CatalogClient;
-
 
14
import in.shop2020.thrift.clients.HelperClient;
14
import in.shop2020.utils.ModelUtils;
15
import in.shop2020.utils.ModelUtils;
15
 
16
 
16
import javax.servlet.ServletOutputStream;
17
import javax.servlet.ServletOutputStream;
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19
import javax.servlet.http.HttpServletResponse;
Line 23... Line 24...
23
import org.apache.struts2.convention.annotation.Results;
24
import org.apache.struts2.convention.annotation.Results;
24
import org.apache.struts2.interceptor.ServletRequestAware;
25
import org.apache.struts2.interceptor.ServletRequestAware;
25
import org.apache.struts2.interceptor.ServletResponseAware;
26
import org.apache.struts2.interceptor.ServletResponseAware;
26
import org.apache.struts2.rest.DefaultHttpHeaders;
27
import org.apache.struts2.rest.DefaultHttpHeaders;
27
import org.apache.struts2.rest.HttpHeaders;
28
import org.apache.struts2.rest.HttpHeaders;
-
 
29
import org.apache.thrift.TException;
28
import org.slf4j.Logger;
30
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
31
import org.slf4j.LoggerFactory;
30
 
32
 
31
/**
33
/**
32
 * @author Varun Gupta
34
 * @author Varun Gupta
33
 */
35
 */
34
 
36
//
35
@InterceptorRefs({
37
//@InterceptorRefs({
36
    @InterceptorRef("defaultStack"),
38
//    @InterceptorRef("defaultStack"),
37
    @InterceptorRef("login")
39
//    @InterceptorRef("login")
38
})
40
//})
39
@Results({
41
//@Results({
40
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
42
//    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
41
})
43
//})
42
public class ProductNotificationsController implements ServletRequestAware, ServletResponseAware {
44
public class ProductNotificationsController implements ServletRequestAware, ServletResponseAware {
43
 
45
 
44
	private static Logger logger = LoggerFactory.getLogger(ProductNotificationsController.class);
46
	private static Logger logger = LoggerFactory.getLogger(ProductNotificationsController.class);
45
	private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
47
	private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
46
	private HttpServletRequest request;
48
	private HttpServletRequest request;
Line 58... Line 60...
58
			if (request.getParameter("sp") != null)	{
60
			if (request.getParameter("sp") != null)	{
59
				startDate = getStartDate(request.getParameter("sp"));
61
				startDate = getStartDate(request.getParameter("sp"));
60
			} else	{
62
			} else	{
61
				startDate = getStartDate("d");
63
				startDate = getStartDate("d");
62
			}
64
			}
63
			System.out.println(startDate);
65
			logger.info("", startDate);
64
			notificationRequestCounts = catalogClient.getProductNotificationRequestCount(startDate.getTime());
66
			notificationRequestCounts = catalogClient.getProductNotificationRequestCount(startDate.getTime());
65
			System.out.println(notificationRequestCounts);
67
			logger.info("", notificationRequestCounts);
66
		} catch (Exception e) {
68
		} catch (TException e) {
67
			logger.error(e.toString());
69
			logger.error("", e);
68
		}
70
		}
69
		return "index";
71
		return "index";
70
	}
72
	}
71
	
73
	
72
	public HttpHeaders create() {
74
	public HttpHeaders create() {
73
		try	{
75
		try	{
74
			CatalogClient csc = new CatalogClient();
76
			HelperClient hsc = new HelperClient("helper_service_server_host_prod", "9008");
75
			in.shop2020.model.v1.catalog.InventoryService.Client catalogClient= csc.getClient();
77
			in.shop2020.utils.HelperService.Client helperClient = hsc.getClient();
-
 
78
			
76
			Date startDate = getStartDate(request.getParameter("np"));
79
			Date startDate = dateFormat.parse(request.getParameter("startDate"));
-
 
80
			Date endDate = dateFormat.parse(request.getParameter("endDate"));
-
 
81
			logger.info("" + startDate + "\t" + endDate);
-
 
82
			
77
			notificationRequests = catalogClient.getProductNotifications(startDate.getTime());
83
			List<String> notificationEmails = helperClient.getEmailsForNotificationsSent(startDate.getTime(), endDate.getTime());
78
			
84
			
79
			logger.info(notificationRequests.toString());
85
			logger.info(notificationEmails.toString());
80
			
86
			
81
			response.setContentType("text/tab-separated-values");
87
			response.setContentType("text/tab-separated-values");
82
			response.setHeader("Content-disposition", "inline; filename=product-notifications-since-" + Long.toString(startDate.getTime()) + ".tsv");
88
			response.setHeader("Content-disposition", "inline; filename=product-notifications-since-" + Long.toString(startDate.getTime()) + ".tsv");
83
			
89
			
84
			ServletOutputStream sos;
90
			ServletOutputStream sos;
85
			try {
91
			try {
86
				sos = response.getOutputStream();
92
				sos = response.getOutputStream();
87
				sos.write(getNotificationsTSV().getBytes());
93
				sos.write(getEmailsCSV(notificationEmails).getBytes());
88
				sos.flush();
94
				sos.flush();
89
			} catch (IOException e) {
95
			} catch (IOException e) {
90
				logger.error("Error while streaming the hotspot reconciliation report", e);
96
				logger.error("Error while streaming the hotspot reconciliation report", e);
91
			}
97
			}
92
		} catch (Exception e) {
98
		} catch (Exception e) {
Line 103... Line 109...
103
	@Override
109
	@Override
104
	public void setServletResponse(HttpServletResponse response) {
110
	public void setServletResponse(HttpServletResponse response) {
105
		this.response = response;
111
		this.response = response;
106
	}
112
	}
107
	
113
	
-
 
114
	private String getEmailsCSV(List<String> emails)	{
-
 
115
		StringBuilder builder = new StringBuilder();
-
 
116
		
-
 
117
		for (String email: emails)	{
-
 
118
			builder.append(email);
-
 
119
			builder.append("\n");
-
 
120
		}
-
 
121
		return builder.toString();
-
 
122
	}
-
 
123
	
108
	private String getNotificationsTSV()	{
124
	private String getNotificationsTSV()	{
109
		StringBuilder builder = new StringBuilder();
125
		StringBuilder builder = new StringBuilder();
110
		
126
		
111
		for (ProductNotificationRequest notificationRequest: notificationRequests)	{
127
		for (ProductNotificationRequest notificationRequest: notificationRequests)	{
112
			Item item = notificationRequest.getItem();
128
			Item item = notificationRequest.getItem();