| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.model.v1.user.Address;
|
|
|
7 |
import in.shop2020.model.v1.user.AddressType;
|
| 595 |
rajveer |
8 |
import in.shop2020.model.v1.user.Sex;
|
| 555 |
chandransh |
9 |
import in.shop2020.model.v1.user.User;
|
| 507 |
rajveer |
10 |
import in.shop2020.model.v1.user.UserState;
|
|
|
11 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
12 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
13 |
import in.shop2020.serving.pages.PageManager;
|
| 595 |
rajveer |
14 |
import in.shop2020.serving.services.PageLoaderHandler;
|
| 507 |
rajveer |
15 |
import in.shop2020.serving.utils.Utils;
|
|
|
16 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
17 |
|
|
|
18 |
import java.io.UnsupportedEncodingException;
|
|
|
19 |
import java.util.Date;
|
|
|
20 |
import java.util.HashMap;
|
|
|
21 |
import java.util.Map;
|
|
|
22 |
|
|
|
23 |
import org.apache.juli.logging.Log;
|
|
|
24 |
import org.apache.juli.logging.LogFactory;
|
|
|
25 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
26 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
27 |
import org.apache.struts2.interceptor.ParameterAware;
|
|
|
28 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
29 |
import org.apache.struts2.rest.HttpHeaders;
|
| 595 |
rajveer |
30 |
import org.apache.velocity.VelocityContext;
|
| 507 |
rajveer |
31 |
|
|
|
32 |
/**
|
|
|
33 |
* @author rajveer
|
|
|
34 |
*
|
|
|
35 |
*/
|
|
|
36 |
|
| 595 |
rajveer |
37 |
@Results({
|
|
|
38 |
@Result(name="success", type="redirectAction",
|
|
|
39 |
params = {"actionName" , "personal-details"})
|
|
|
40 |
})
|
| 507 |
rajveer |
41 |
|
| 595 |
rajveer |
42 |
public class PersonalDetailsController extends BaseController {
|
|
|
43 |
|
| 507 |
rajveer |
44 |
|
|
|
45 |
/**
|
|
|
46 |
*
|
|
|
47 |
*/
|
| 517 |
rajveer |
48 |
private static Log log = LogFactory.getLog(PersonalDetailsController.class);
|
| 507 |
rajveer |
49 |
|
| 595 |
rajveer |
50 |
private Map<String,String> htmlSnippets = new HashMap<String, String>();
|
|
|
51 |
|
|
|
52 |
private Map<String,String> velocityParams = new HashMap<String, String>();
|
| 507 |
rajveer |
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
*/
|
|
|
56 |
|
| 517 |
rajveer |
57 |
public PersonalDetailsController() {
|
| 507 |
rajveer |
58 |
super();
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
// POST /logindetails
|
|
|
62 |
public String create() {
|
|
|
63 |
log.info("PersonaldetailsController.create");
|
|
|
64 |
|
|
|
65 |
if(this.userinfo.isLoggedIn()){
|
| 595 |
rajveer |
66 |
String name = this.request.getParameter("txtName");
|
| 620 |
rajveer |
67 |
String dateOfBirth = this.request.getParameter("txtDateOfBirth");
|
| 595 |
rajveer |
68 |
String sex = this.request.getParameter("sex");
|
|
|
69 |
String communicationEmail = this.request.getParameter("txtCommEmail");
|
|
|
70 |
String subscribeNewsletter = this.request.getParameter("subscribe");
|
|
|
71 |
String phone = this.request.getParameter("txtPhone");
|
|
|
72 |
|
|
|
73 |
if(Utils.UpdatePersonalDetails(userinfo.getUserId(), name, phone, dateOfBirth, sex,communicationEmail,subscribeNewsletter))
|
|
|
74 |
{
|
|
|
75 |
addActionMessage("Your personal details updated");
|
| 507 |
rajveer |
76 |
return "success";
|
|
|
77 |
}
|
|
|
78 |
}
|
| 595 |
rajveer |
79 |
addActionError("Unable to update your personal details");
|
|
|
80 |
return "success";
|
| 507 |
rajveer |
81 |
}
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
// GET /test
|
| 595 |
rajveer |
85 |
public String index() throws UnsupportedEncodingException {
|
| 507 |
rajveer |
86 |
log.info("this.request=" + this.request);
|
|
|
87 |
|
|
|
88 |
|
| 595 |
rajveer |
89 |
|
| 507 |
rajveer |
90 |
if(this.userinfo.isLoggedIn()){
|
| 595 |
rajveer |
91 |
long userId = this.userinfo.getUserId();
|
|
|
92 |
PageLoaderHandler pageLoader = new PageLoaderHandler();
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(this.userinfo.isLoggedIn(), this.userinfo.getNameOfUser()));
|
|
|
96 |
htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
|
|
|
97 |
|
|
|
98 |
htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
|
|
|
99 |
htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 0));
|
|
|
100 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
|
|
|
101 |
htmlSnippets.put("PERSONAL_DETAILS", pageLoader.getPersonalDetailsHtml(userinfo.getUserId()));
|
|
|
102 |
htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
|
|
|
103 |
htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), true));
|
|
|
104 |
htmlSnippets.put("BROWSE_HISTORY", pageLoader.getBrowseHistoryHtml(userinfo.getUserId(), userinfo.isLoggedIn()));
|
|
|
105 |
htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());
|
|
|
106 |
return "index";
|
| 507 |
rajveer |
107 |
|
|
|
108 |
}else{
|
| 595 |
rajveer |
109 |
return "failure";
|
| 507 |
rajveer |
110 |
}
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
|
| 595 |
rajveer |
114 |
|
|
|
115 |
public Map<String, String> getVelocityParams(){
|
|
|
116 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
117 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
118 |
try{
|
|
|
119 |
User user = null;
|
|
|
120 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
121 |
userClient = userContextServiceClient.getClient();
|
|
|
122 |
user = userClient.getUserById(userinfo.getUserId());
|
|
|
123 |
|
|
|
124 |
velocityParams.put("email", user.getCommunicationEmail());
|
|
|
125 |
velocityParams.put("sex", user.getSex().getValue()+"");
|
|
|
126 |
velocityParams.put("name", user.getName());
|
|
|
127 |
velocityParams.put("phone", user.getMobileNumber());
|
|
|
128 |
velocityParams.put("dateOfBirth", user.getDateOfBirth());
|
|
|
129 |
}catch (Exception e){
|
|
|
130 |
e.printStackTrace();
|
|
|
131 |
}
|
|
|
132 |
return velocityParams;
|
|
|
133 |
}
|
|
|
134 |
|
| 507 |
rajveer |
135 |
public String getHeaderSnippet(){
|
|
|
136 |
return htmlSnippets.get("HEADER");
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public String getMainMenuSnippet(){
|
|
|
140 |
return htmlSnippets.get("MAIN_MENU");
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
public String getSearchBarSnippet(){
|
|
|
144 |
return htmlSnippets.get("SEARCH_BAR");
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
public String getCustomerServiceSnippet(){
|
|
|
149 |
return htmlSnippets.get("CUSTOMER_SERVICE");
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
public String getMyaccountHeaderSnippet(){
|
|
|
153 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public String getPersonalDetailsSnippet(){
|
|
|
157 |
return htmlSnippets.get("PERSONAL_DETAILS");
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
public String getMyResearchSnippet(){
|
|
|
161 |
return htmlSnippets.get("MY_RESEARCH");
|
|
|
162 |
}
|
| 595 |
rajveer |
163 |
|
|
|
164 |
public String getBrowseHistorySnippet(){
|
|
|
165 |
return htmlSnippets.get("BROWSE_HISTORY");
|
|
|
166 |
}
|
|
|
167 |
|
| 507 |
rajveer |
168 |
public String getFooterSnippet(){
|
|
|
169 |
return htmlSnippets.get("FOOTER");
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
public String getJsFileSnippet(){
|
|
|
173 |
return htmlSnippets.get("JS_FILES");
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
public String getCssFileSnippet(){
|
|
|
177 |
return htmlSnippets.get("CSS_FILES");
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
}
|