| 2674 |
vikas |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 3128 |
rajveer |
3 |
import in.shop2020.thrift.clients.CRMClient;
|
|
|
4 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
5 |
import in.shop2020.thrift.clients.UserClient;
|
| 3090 |
mandeep.dh |
6 |
|
|
|
7 |
import java.text.SimpleDateFormat;
|
|
|
8 |
import java.util.Date;
|
| 2674 |
vikas |
9 |
import java.util.Map;
|
|
|
10 |
|
|
|
11 |
import javax.servlet.http.HttpServletRequest;
|
|
|
12 |
import javax.servlet.http.HttpServletResponse;
|
|
|
13 |
import javax.servlet.http.HttpSession;
|
|
|
14 |
|
|
|
15 |
import org.apache.log4j.Logger;
|
| 3090 |
mandeep.dh |
16 |
import org.apache.shiro.SecurityUtils;
|
| 2674 |
vikas |
17 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
18 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
19 |
import org.apache.struts2.interceptor.SessionAware;
|
| 3090 |
mandeep.dh |
20 |
import org.apache.thrift.TException;
|
| 2674 |
vikas |
21 |
|
|
|
22 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Base class for all user action handlers i.e. controllers
|
|
|
26 |
*
|
|
|
27 |
* @author Vikas
|
|
|
28 |
*/
|
|
|
29 |
public abstract class BaseController extends ValidationAwareSupport implements
|
|
|
30 |
ServletResponseAware, ServletRequestAware, SessionAware
|
|
|
31 |
{
|
|
|
32 |
private static final long serialVersionUID = 3339523094497219816L;
|
| 3090 |
mandeep.dh |
33 |
protected static Logger log = Logger.getLogger(BaseController.class);
|
|
|
34 |
|
|
|
35 |
protected static final String INPUT = "input";
|
|
|
36 |
protected static final String INDEX = "index";
|
|
|
37 |
protected static final String EDIT_NEW = "editNew";
|
|
|
38 |
protected static final String EDIT = "edit";
|
|
|
39 |
protected static final String SHOW = "show";
|
| 3106 |
mandeep.dh |
40 |
protected static final String EXCEPTION = "exception";
|
| 3090 |
mandeep.dh |
41 |
|
|
|
42 |
protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
|
|
|
43 |
|
| 2674 |
vikas |
44 |
protected HttpServletResponse response;
|
|
|
45 |
protected HttpServletRequest request;
|
|
|
46 |
protected HttpSession session;
|
|
|
47 |
protected Map<String, Object> sessionMap;
|
|
|
48 |
|
| 3090 |
mandeep.dh |
49 |
// Clients used at many places
|
|
|
50 |
protected in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient;
|
|
|
51 |
protected in.shop2020.model.v1.order.TransactionService.Client transactionServiceClient;
|
|
|
52 |
protected in.shop2020.crm.CRMService.Client crmServiceClient;
|
|
|
53 |
|
|
|
54 |
protected String currentAgentEmailId = (String) SecurityUtils.getSubject().getPrincipal();
|
|
|
55 |
|
|
|
56 |
protected void createServiceClients()
|
|
|
57 |
{
|
|
|
58 |
try {
|
| 3128 |
rajveer |
59 |
userContextServiceClient = new UserClient().getClient();
|
|
|
60 |
transactionServiceClient = new TransactionClient().getClient();
|
|
|
61 |
crmServiceClient = new CRMClient().getClient();
|
| 3090 |
mandeep.dh |
62 |
}
|
|
|
63 |
catch (Exception e) {
|
|
|
64 |
log.error("Could not get client!", e);
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
| 2674 |
vikas |
68 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
69 |
this.response = response;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
73 |
this.request = request;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public void setSession(Map<String, Object> sessionMap) {
|
|
|
77 |
this.session = request.getSession();
|
|
|
78 |
this.sessionMap = sessionMap;
|
|
|
79 |
}
|
| 3090 |
mandeep.dh |
80 |
|
|
|
81 |
/**
|
|
|
82 |
* Utility method to convert a date to a readable format
|
|
|
83 |
*/
|
| 3106 |
mandeep.dh |
84 |
public String convertDate(Long date) {
|
|
|
85 |
if (date == null || date == 0) {
|
| 3090 |
mandeep.dh |
86 |
return "N/A";
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
return SDF.format(new Date(date));
|
|
|
90 |
}
|
| 3106 |
mandeep.dh |
91 |
|
|
|
92 |
public String getCurrentAgentEmailId() {
|
|
|
93 |
return currentAgentEmailId;
|
|
|
94 |
}
|
|
|
95 |
|
| 3090 |
mandeep.dh |
96 |
public String getAgentName() throws TException
|
|
|
97 |
{
|
|
|
98 |
createServiceClients();
|
|
|
99 |
return crmServiceClient.getAgentByEmailId(currentAgentEmailId).getName();
|
|
|
100 |
}
|
|
|
101 |
|
| 3106 |
mandeep.dh |
102 |
public String editNew() {
|
|
|
103 |
return EDIT_NEW;
|
| 3090 |
mandeep.dh |
104 |
}
|
|
|
105 |
|
| 3106 |
mandeep.dh |
106 |
public String edit() {
|
|
|
107 |
return EDIT;
|
| 3090 |
mandeep.dh |
108 |
}
|
|
|
109 |
}
|