| 2674 |
vikas |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 6153 |
anupam.sin |
3 |
import in.shop2020.model.v1.order.RechargeType;
|
| 3390 |
mandeep.dh |
4 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
| 6153 |
anupam.sin |
5 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 4689 |
anupam.sin |
6 |
import in.shop2020.util.CRMConstants;
|
|
|
7 |
import in.shop2020.util.CRMConstants.CODCancelMatrix;
|
| 3090 |
mandeep.dh |
8 |
|
|
|
9 |
import java.text.SimpleDateFormat;
|
|
|
10 |
import java.util.Date;
|
| 2674 |
vikas |
11 |
import java.util.Map;
|
|
|
12 |
|
|
|
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
import javax.servlet.http.HttpServletResponse;
|
|
|
15 |
import javax.servlet.http.HttpSession;
|
|
|
16 |
|
|
|
17 |
import org.apache.log4j.Logger;
|
| 3090 |
mandeep.dh |
18 |
import org.apache.shiro.SecurityUtils;
|
| 2674 |
vikas |
19 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
20 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
21 |
import org.apache.struts2.interceptor.SessionAware;
|
| 3090 |
mandeep.dh |
22 |
import org.apache.thrift.TException;
|
| 2674 |
vikas |
23 |
|
|
|
24 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Base class for all user action handlers i.e. controllers
|
|
|
28 |
*
|
|
|
29 |
* @author Vikas
|
|
|
30 |
*/
|
|
|
31 |
public abstract class BaseController extends ValidationAwareSupport implements
|
|
|
32 |
ServletResponseAware, ServletRequestAware, SessionAware
|
|
|
33 |
{
|
|
|
34 |
private static final long serialVersionUID = 3339523094497219816L;
|
| 3090 |
mandeep.dh |
35 |
protected static Logger log = Logger.getLogger(BaseController.class);
|
|
|
36 |
|
|
|
37 |
protected static final String INPUT = "input";
|
|
|
38 |
protected static final String INDEX = "index";
|
|
|
39 |
protected static final String EDIT_NEW = "editNew";
|
|
|
40 |
protected static final String EDIT = "edit";
|
|
|
41 |
protected static final String SHOW = "show";
|
| 5909 |
amar.kumar |
42 |
protected static final String OPEN = "open";
|
| 3106 |
mandeep.dh |
43 |
protected static final String EXCEPTION = "exception";
|
| 6153 |
anupam.sin |
44 |
|
|
|
45 |
static Map<Long, String> providersMap;
|
| 3090 |
mandeep.dh |
46 |
|
|
|
47 |
protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
|
|
|
48 |
|
| 2674 |
vikas |
49 |
protected HttpServletResponse response;
|
|
|
50 |
protected HttpServletRequest request;
|
|
|
51 |
protected HttpSession session;
|
|
|
52 |
protected Map<String, Object> sessionMap;
|
|
|
53 |
|
| 3090 |
mandeep.dh |
54 |
// Clients used at many places
|
|
|
55 |
protected in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient;
|
|
|
56 |
protected in.shop2020.model.v1.order.TransactionService.Client transactionServiceClient;
|
|
|
57 |
protected in.shop2020.crm.CRMService.Client crmServiceClient;
|
|
|
58 |
|
|
|
59 |
protected String currentAgentEmailId = (String) SecurityUtils.getSubject().getPrincipal();
|
|
|
60 |
|
| 2674 |
vikas |
61 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
62 |
this.response = response;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
66 |
this.request = request;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public void setSession(Map<String, Object> sessionMap) {
|
|
|
70 |
this.session = request.getSession();
|
|
|
71 |
this.sessionMap = sessionMap;
|
|
|
72 |
}
|
| 3090 |
mandeep.dh |
73 |
|
| 6153 |
anupam.sin |
74 |
static {
|
|
|
75 |
TransactionClient tcl;
|
|
|
76 |
try {
|
|
|
77 |
tcl = new TransactionClient();
|
| 6206 |
rajveer |
78 |
providersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, false);
|
|
|
79 |
providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH, false));
|
| 6153 |
anupam.sin |
80 |
} catch (Exception e) {
|
|
|
81 |
log.error("Could not get providers", e);
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
| 3090 |
mandeep.dh |
85 |
/**
|
|
|
86 |
* Utility method to convert a date to a readable format
|
|
|
87 |
*/
|
| 3106 |
mandeep.dh |
88 |
public String convertDate(Long date) {
|
|
|
89 |
if (date == null || date == 0) {
|
| 3090 |
mandeep.dh |
90 |
return "N/A";
|
|
|
91 |
}
|
|
|
92 |
|
| 4144 |
mandeep.dh |
93 |
return SDF.format(new Date(date));
|
| 3090 |
mandeep.dh |
94 |
}
|
| 3106 |
mandeep.dh |
95 |
|
|
|
96 |
public String getCurrentAgentEmailId() {
|
|
|
97 |
return currentAgentEmailId;
|
|
|
98 |
}
|
|
|
99 |
|
| 3090 |
mandeep.dh |
100 |
public String getAgentName() throws TException
|
|
|
101 |
{
|
| 3390 |
mandeep.dh |
102 |
return CRMAuthorizingRealm.getAgent(currentAgentEmailId).getName();
|
| 3090 |
mandeep.dh |
103 |
}
|
|
|
104 |
|
| 3578 |
mandeep.dh |
105 |
public boolean canVerifyCOD() {
|
|
|
106 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public boolean canViewFailedPayments() {
|
|
|
110 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
|
|
111 |
}
|
|
|
112 |
|
| 4008 |
mandeep.dh |
113 |
public boolean canViewDelayedDeliveries() {
|
|
|
114 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
|
|
115 |
}
|
| 4267 |
anupam.sin |
116 |
|
|
|
117 |
public boolean canViewFlaggedPayments() {
|
| 6507 |
anupam.sin |
118 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
| 4267 |
anupam.sin |
119 |
}
|
| 4490 |
anupam.sin |
120 |
|
|
|
121 |
public boolean canViewDoaRequests() {
|
|
|
122 |
return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public boolean canViewReturnRequests() {
|
|
|
126 |
return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
|
|
|
127 |
}
|
| 4751 |
anupam.sin |
128 |
|
| 4793 |
amar.kumar |
129 |
public boolean canManageAgents() {
|
|
|
130 |
return (SecurityUtils.getSubject().hasRole("TeamLead"));
|
|
|
131 |
}
|
|
|
132 |
|
| 4751 |
anupam.sin |
133 |
public boolean canViewOrderCancellation() {
|
| 6507 |
anupam.sin |
134 |
return SecurityUtils.getSubject().hasRole("Outbound");
|
| 4751 |
anupam.sin |
135 |
}
|
| 5884 |
amar.kumar |
136 |
|
|
|
137 |
public boolean canViewStorePickupTickets() {
|
|
|
138 |
return (SecurityUtils.getSubject().hasRole("Outbound"));
|
|
|
139 |
}
|
| 4008 |
mandeep.dh |
140 |
|
| 5909 |
amar.kumar |
141 |
public boolean canViewAllOpenTickets() {
|
|
|
142 |
return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
|
|
|
143 |
}
|
|
|
144 |
|
| 7372 |
kshitij.so |
145 |
public boolean canViewLowInventoryCancellation() {
|
|
|
146 |
return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
|
|
|
147 |
}
|
|
|
148 |
|
| 3106 |
mandeep.dh |
149 |
public String editNew() {
|
|
|
150 |
return EDIT_NEW;
|
| 3090 |
mandeep.dh |
151 |
}
|
|
|
152 |
|
| 3106 |
mandeep.dh |
153 |
public String edit() {
|
|
|
154 |
return EDIT;
|
| 3090 |
mandeep.dh |
155 |
}
|
| 4689 |
anupam.sin |
156 |
|
|
|
157 |
public CODCancelMatrix[] getCODCancelMatrix () {
|
|
|
158 |
return CRMConstants.CODCancelMatrix.values();
|
|
|
159 |
}
|
| 3090 |
mandeep.dh |
160 |
}
|