| 7226 |
anupam.sin |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 7272 |
amit.gupta |
3 |
|
| 7343 |
anupam.sin |
4 |
import in.shop2020.model.v1.order.HotspotStore;
|
| 7747 |
anupam.sin |
5 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 7343 |
anupam.sin |
6 |
|
| 7226 |
anupam.sin |
7 |
import java.text.SimpleDateFormat;
|
|
|
8 |
import java.util.Date;
|
| 7272 |
amit.gupta |
9 |
import java.util.HashMap;
|
| 7226 |
anupam.sin |
10 |
import java.util.Map;
|
|
|
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
import javax.servlet.http.HttpServletResponse;
|
|
|
14 |
import javax.servlet.http.HttpSession;
|
|
|
15 |
|
| 19706 |
amit.gupta |
16 |
import org.apache.commons.lang.StringUtils;
|
| 7226 |
anupam.sin |
17 |
import org.apache.log4j.Logger;
|
|
|
18 |
import org.apache.shiro.SecurityUtils;
|
|
|
19 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
20 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
21 |
import org.apache.struts2.interceptor.SessionAware;
|
|
|
22 |
|
|
|
23 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Base class for all user action handlers i.e. controllers
|
|
|
27 |
*
|
|
|
28 |
*/
|
|
|
29 |
public abstract class BaseController extends ValidationAwareSupport implements
|
|
|
30 |
ServletResponseAware, ServletRequestAware, SessionAware
|
|
|
31 |
{
|
|
|
32 |
private static final long serialVersionUID = 3339523094497219816L;
|
|
|
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";
|
|
|
40 |
protected static final String EXCEPTION = "exception";
|
|
|
41 |
|
|
|
42 |
protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
|
| 7343 |
anupam.sin |
43 |
|
|
|
44 |
public static Map<Long, HotspotStore> hotspotStores = new HashMap<Long, HotspotStore>();
|
| 7226 |
anupam.sin |
45 |
|
|
|
46 |
protected HttpServletResponse response;
|
|
|
47 |
protected HttpServletRequest request;
|
|
|
48 |
protected HttpSession session;
|
|
|
49 |
protected Map<String, Object> sessionMap;
|
|
|
50 |
protected long sourceId = -1;
|
| 7272 |
amit.gupta |
51 |
protected Map<String, String> htmlSnippets;
|
| 19706 |
amit.gupta |
52 |
private boolean OCRSession = false;
|
| 7343 |
anupam.sin |
53 |
|
|
|
54 |
protected Long storeId;
|
| 7747 |
anupam.sin |
55 |
protected static boolean showTestMessage = false;
|
|
|
56 |
|
| 7226 |
anupam.sin |
57 |
|
| 7747 |
anupam.sin |
58 |
static {
|
|
|
59 |
try{
|
|
|
60 |
setShowTestMessageField(Boolean.parseBoolean(ConfigClient.getClient().get("showTestMessageOnStoreWebsite")));
|
|
|
61 |
} catch(Exception e){
|
|
|
62 |
log.error("Unable to get value from config service", e);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
| 7272 |
amit.gupta |
66 |
public BaseController() {
|
|
|
67 |
htmlSnippets = new HashMap<String, String>();
|
| 19706 |
amit.gupta |
68 |
OCRSession = StringUtils.isNotEmpty((String)request.getSession().getAttribute("OCR_SESSION"));
|
| 7272 |
amit.gupta |
69 |
}
|
|
|
70 |
|
| 7226 |
anupam.sin |
71 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
72 |
this.response = response;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
76 |
this.request = request;
|
| 7343 |
anupam.sin |
77 |
this.session = request.getSession();
|
| 7226 |
anupam.sin |
78 |
}
|
|
|
79 |
|
|
|
80 |
public void setSession(Map<String, Object> sessionMap) {
|
|
|
81 |
this.sessionMap = sessionMap;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Utility method to convert a date to a readable format
|
|
|
86 |
*/
|
|
|
87 |
public String convertDate(Long date) {
|
|
|
88 |
if (date == null || date == 0) {
|
|
|
89 |
return "N/A";
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
return SDF.format(new Date(date));
|
|
|
93 |
}
|
|
|
94 |
|
| 7386 |
anupam.sin |
95 |
public double getDifference(double num1, double num2) {
|
|
|
96 |
return num1-num2;
|
|
|
97 |
}
|
|
|
98 |
|
| 7226 |
anupam.sin |
99 |
public void setSourceId(long sourceId){
|
|
|
100 |
this.sourceId = sourceId;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
public String index() {
|
|
|
104 |
return INDEX;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public String editNew() {
|
|
|
108 |
return EDIT_NEW;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
public String edit() {
|
|
|
112 |
return EDIT;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public boolean isPermitted(String permission) {
|
|
|
116 |
return SecurityUtils.getSubject().isPermitted(permission);
|
|
|
117 |
}
|
| 7343 |
anupam.sin |
118 |
|
|
|
119 |
public Long getStoreId() {
|
|
|
120 |
return storeId;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
public void setStoreId(Long storeId) {
|
|
|
124 |
this.storeId = storeId;
|
|
|
125 |
}
|
| 7386 |
anupam.sin |
126 |
|
|
|
127 |
public String getStoreCode(){
|
|
|
128 |
return hotspotStores.get(storeId).getHotspotId();
|
|
|
129 |
}
|
| 7747 |
anupam.sin |
130 |
|
|
|
131 |
public static void setShowTestMessageField(boolean showTestMessage) {
|
|
|
132 |
BaseController.showTestMessage = showTestMessage;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public static boolean shouldShowTestMessage() {
|
|
|
136 |
return showTestMessage;
|
|
|
137 |
}
|
| 19706 |
amit.gupta |
138 |
|
|
|
139 |
public void setOCRSession(boolean oCRSession) {
|
|
|
140 |
OCRSession = oCRSession;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public boolean isOCRSession() {
|
|
|
144 |
return OCRSession;
|
|
|
145 |
}
|
| 7226 |
anupam.sin |
146 |
}
|