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