| 2674 |
vikas |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 3390 |
mandeep.dh |
3 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
| 4689 |
anupam.sin |
4 |
import in.shop2020.util.CRMConstants;
|
|
|
5 |
import in.shop2020.util.CRMConstants.CODCancelMatrix;
|
| 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 |
|
| 2674 |
vikas |
56 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
57 |
this.response = response;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
61 |
this.request = request;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public void setSession(Map<String, Object> sessionMap) {
|
|
|
65 |
this.session = request.getSession();
|
|
|
66 |
this.sessionMap = sessionMap;
|
|
|
67 |
}
|
| 3090 |
mandeep.dh |
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Utility method to convert a date to a readable format
|
|
|
71 |
*/
|
| 3106 |
mandeep.dh |
72 |
public String convertDate(Long date) {
|
|
|
73 |
if (date == null || date == 0) {
|
| 3090 |
mandeep.dh |
74 |
return "N/A";
|
|
|
75 |
}
|
|
|
76 |
|
| 4144 |
mandeep.dh |
77 |
return SDF.format(new Date(date));
|
| 3090 |
mandeep.dh |
78 |
}
|
| 3106 |
mandeep.dh |
79 |
|
|
|
80 |
public String getCurrentAgentEmailId() {
|
|
|
81 |
return currentAgentEmailId;
|
|
|
82 |
}
|
|
|
83 |
|
| 3090 |
mandeep.dh |
84 |
public String getAgentName() throws TException
|
|
|
85 |
{
|
| 3390 |
mandeep.dh |
86 |
return CRMAuthorizingRealm.getAgent(currentAgentEmailId).getName();
|
| 3090 |
mandeep.dh |
87 |
}
|
|
|
88 |
|
| 3578 |
mandeep.dh |
89 |
public boolean canVerifyCOD() {
|
|
|
90 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public boolean canViewFailedPayments() {
|
|
|
94 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
|
|
95 |
}
|
|
|
96 |
|
| 4008 |
mandeep.dh |
97 |
public boolean canViewDelayedDeliveries() {
|
|
|
98 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
|
|
99 |
}
|
| 4267 |
anupam.sin |
100 |
|
|
|
101 |
public boolean canViewFlaggedPayments() {
|
|
|
102 |
return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
|
|
|
103 |
}
|
| 4490 |
anupam.sin |
104 |
|
|
|
105 |
public boolean canViewDoaRequests() {
|
|
|
106 |
return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public boolean canViewReturnRequests() {
|
|
|
110 |
return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
|
|
|
111 |
}
|
| 4751 |
anupam.sin |
112 |
|
|
|
113 |
public boolean canViewOrderCancellation() {
|
|
|
114 |
return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
|
|
|
115 |
}
|
| 4008 |
mandeep.dh |
116 |
|
| 3106 |
mandeep.dh |
117 |
public String editNew() {
|
|
|
118 |
return EDIT_NEW;
|
| 3090 |
mandeep.dh |
119 |
}
|
|
|
120 |
|
| 3106 |
mandeep.dh |
121 |
public String edit() {
|
|
|
122 |
return EDIT;
|
| 3090 |
mandeep.dh |
123 |
}
|
| 4689 |
anupam.sin |
124 |
|
|
|
125 |
public CODCancelMatrix[] getCODCancelMatrix () {
|
|
|
126 |
return CRMConstants.CODCancelMatrix.values();
|
|
|
127 |
}
|
| 3090 |
mandeep.dh |
128 |
}
|