Subversion Repositories SmartDukaan

Rev

Rev 10384 | Rev 10849 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9269 amit.gupta 1
package in.shop2020.mobileapi.serving.controllers;
9103 anupam.sin 2
 
9269 amit.gupta 3
import in.shop2020.mobileapi.serving.interceptors.UserAware;
4
import in.shop2020.mobileapi.serving.services.PageLoaderHandler;
5
import in.shop2020.mobileapi.serving.services.UserSessionInfo;
6
import in.shop2020.mobileapi.serving.utils.DesEncrypter;
9103 anupam.sin 7
import in.shop2020.model.v1.catalog.Banner;
8
import in.shop2020.model.v1.catalog.BannerMap;
9
 
10
import java.util.ArrayList;
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
 
15
import javax.servlet.http.Cookie;
16
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletResponse;
18
import javax.servlet.http.HttpSession;
19
 
20
import org.apache.log4j.Logger;
21
import org.apache.struts2.interceptor.ServletRequestAware;
22
import org.apache.struts2.interceptor.ServletResponseAware;
23
 
10300 amit.gupta 24
import com.google.gson.Gson;
9103 anupam.sin 25
import com.opensymphony.xwork2.ValidationAwareSupport;
26
 
27
/**
28
 * Base class for all user action handlers i.e. controllers
29
 * 
30
 * @author rajveer
31
 */
32
public abstract class BaseController extends ValidationAwareSupport implements
9601 amit.gupta 33
ServletResponseAware, ServletRequestAware, UserAware {
9103 anupam.sin 34
	/**
35
	 * 
36
	 */
37
	private static final long serialVersionUID = 1L;
38
	protected Map<String, Cookie> cookiesMap = null;
39
	protected HttpServletResponse response;
40
	protected HttpServletRequest request;
41
	protected HttpSession session;
42
	protected String domainName;
43
	protected UserSessionInfo userinfo = null;
44
	private static Logger log = Logger.getLogger(Class.class);
10283 amit.gupta 45
	private String resultJson;
9103 anupam.sin 46
 
47
	protected Cookie userCookie = null;
48
 
49
	protected Map<String, String> htmlSnippets;
50
 
51
	PageLoaderHandler pageLoader = null;
52
 
53
	public static Map<String,List<Banner>> activeBanners = null;
54
	public static Map<String, List<BannerMap>> allBannersMap = null;
55
 
9157 amit.gupta 56
 
9103 anupam.sin 57
 
58
	public List<BannerMap> getbannermapdetails(String bannerName) {
59
		return allBannersMap.get(bannerName);
60
	}
61
 
62
 
63
	public BaseController() {
64
		pageLoader = new PageLoaderHandler();
65
		htmlSnippets = new HashMap<String, String>();
66
	}
67
 
68
	@Override
69
	public void setCookiesMap(Map<String, Cookie> cookiesMap) {
70
		log.info("Received cookiesMap.");
71
		this.cookiesMap = cookiesMap;
72
	}
73
 
74
	@Override
75
	public void setServletResponse(HttpServletResponse response) {
76
		this.response = response;
77
	}
78
 
79
	@Override
80
	public void setServletRequest(HttpServletRequest request) {
81
		this.request = request;
10797 amit.gupta 82
		log.info("ip: " + request.getRemoteAddr());
83
		log.info("ip: " + request.getRemoteHost());
84
		log.info("ip: " + request.getRemotePort());
85
		log.info("ip: " + request.getRemoteUser());
9103 anupam.sin 86
	}
87
 
88
	@Override
89
	public void setSession(HttpSession session) {
90
		this.session = session;
91
	}
92
 
93
	@Override
94
	public void setUserSessionInfo(UserSessionInfo userInfo) {
95
		this.userinfo = userInfo;
96
	}
97
 
98
	@Override
99
	public void setUserCookie(Cookie userCookie) {
100
		if(userCookie != null){
101
			log.info("cookie name is:" +  userCookie.getName() + "   value is:"+ userCookie.getValue() + " path : " + userCookie.getPath());
102
		}
103
		this.userCookie = userCookie;
104
	}
105
 
106
	@Override
107
	public void setCookieDomainName(String domainName) {
108
		this.domainName = domainName;
109
	}
110
 
111
	public UserSessionInfo getUserInfo(){
112
		return this.userinfo;
113
	}
114
 
115
	@Override
116
	public List<Cookie> getCookies() {
117
		List<Cookie> cookies = new ArrayList<Cookie>();
118
		return cookies;
119
	}
120
 
121
	public String getCookie(String cookieName, boolean isEncripted, String encriptionString) {
122
		Cookie cookie = (Cookie) cookiesMap.get(cookieName);
123
		String cookieVal = null;
124
		if (cookie != null) {
125
			cookieVal = cookie.getValue();
126
			if (isEncripted) {
127
				DesEncrypter desEncrypter = new DesEncrypter(encriptionString);
128
				cookieVal = desEncrypter.decrypt(cookieVal);
129
			}
130
		}
131
		return cookieVal;
132
	}
10283 amit.gupta 133
 
134
 
10300 amit.gupta 135
	public void setResultJson(Object resultJSon) {
136
		if(!resultJSon.getClass().equals(String.class)) {
137
			this.resultJson = new Gson().toJson(resultJSon);
138
		} else {
139
			this.resultJson = (String)resultJSon;
140
		}
10384 amit.gupta 141
		log.info("resultJson: " + this.resultJson);
10283 amit.gupta 142
	}
143
 
144
 
145
	public String getResultJson() {
146
		return resultJson;
147
	}
9103 anupam.sin 148
}