| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
| 762 |
rajveer |
6 |
import in.shop2020.model.v1.user.Sex;
|
| 555 |
chandransh |
7 |
import in.shop2020.model.v1.user.User;
|
| 762 |
rajveer |
8 |
import in.shop2020.model.v1.user.UserContextException;
|
| 507 |
rajveer |
9 |
import in.shop2020.serving.utils.Utils;
|
|
|
10 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
11 |
|
|
|
12 |
import java.io.UnsupportedEncodingException;
|
|
|
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.Map;
|
|
|
15 |
|
| 832 |
rajveer |
16 |
import org.apache.log4j.Logger;
|
| 507 |
rajveer |
17 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
18 |
import org.apache.struts2.convention.annotation.Results;
|
| 762 |
rajveer |
19 |
import org.apache.thrift.TException;
|
| 507 |
rajveer |
20 |
|
|
|
21 |
/**
|
|
|
22 |
* @author rajveer
|
|
|
23 |
*
|
|
|
24 |
*/
|
|
|
25 |
|
| 595 |
rajveer |
26 |
@Results({
|
|
|
27 |
@Result(name="success", type="redirectAction",
|
| 650 |
rajveer |
28 |
params = {"actionName" , "personal-details"}),
|
|
|
29 |
@Result(name="redirect", type="redirectAction",
|
|
|
30 |
params = {"actionName" , "login"})
|
|
|
31 |
|
| 595 |
rajveer |
32 |
})
|
| 507 |
rajveer |
33 |
|
| 595 |
rajveer |
34 |
public class PersonalDetailsController extends BaseController {
|
|
|
35 |
|
| 507 |
rajveer |
36 |
|
| 650 |
rajveer |
37 |
private static final long serialVersionUID = 1L;
|
|
|
38 |
|
| 832 |
rajveer |
39 |
private static Logger log = Logger.getLogger(Class.class);
|
| 507 |
rajveer |
40 |
|
| 595 |
rajveer |
41 |
private Map<String,String> velocityParams = new HashMap<String, String>();
|
| 507 |
rajveer |
42 |
|
| 517 |
rajveer |
43 |
public PersonalDetailsController() {
|
| 507 |
rajveer |
44 |
super();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
// POST /logindetails
|
|
|
48 |
public String create() {
|
|
|
49 |
log.info("PersonaldetailsController.create");
|
|
|
50 |
|
|
|
51 |
if(this.userinfo.isLoggedIn()){
|
| 595 |
rajveer |
52 |
String name = this.request.getParameter("txtName");
|
| 620 |
rajveer |
53 |
String dateOfBirth = this.request.getParameter("txtDateOfBirth");
|
| 595 |
rajveer |
54 |
String sex = this.request.getParameter("sex");
|
|
|
55 |
String communicationEmail = this.request.getParameter("txtCommEmail");
|
|
|
56 |
String subscribeNewsletter = this.request.getParameter("subscribe");
|
|
|
57 |
String phone = this.request.getParameter("txtPhone");
|
|
|
58 |
|
| 762 |
rajveer |
59 |
if(UpdatePersonalDetails(userinfo.getUserId(), name, phone, dateOfBirth, sex,communicationEmail,subscribeNewsletter))
|
| 595 |
rajveer |
60 |
{
|
|
|
61 |
addActionMessage("Your personal details updated");
|
| 507 |
rajveer |
62 |
return "success";
|
|
|
63 |
}
|
|
|
64 |
}
|
| 595 |
rajveer |
65 |
addActionError("Unable to update your personal details");
|
|
|
66 |
return "success";
|
| 507 |
rajveer |
67 |
}
|
|
|
68 |
|
|
|
69 |
|
| 595 |
rajveer |
70 |
public String index() throws UnsupportedEncodingException {
|
| 507 |
rajveer |
71 |
log.info("this.request=" + this.request);
|
|
|
72 |
|
|
|
73 |
if(this.userinfo.isLoggedIn()){
|
| 595 |
rajveer |
74 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
|
|
|
75 |
htmlSnippets.put("PERSONAL_DETAILS", pageLoader.getPersonalDetailsHtml(userinfo.getUserId()));
|
| 650 |
rajveer |
76 |
return "index";
|
| 507 |
rajveer |
77 |
}else{
|
| 650 |
rajveer |
78 |
return "redirect";
|
| 507 |
rajveer |
79 |
}
|
|
|
80 |
|
|
|
81 |
}
|
|
|
82 |
|
| 762 |
rajveer |
83 |
private boolean UpdatePersonalDetails(long userId, String name, String phone, String dateOfBirth, String sex, String communicationEmail,
|
|
|
84 |
String subscribeNewsletter) {
|
|
|
85 |
|
|
|
86 |
try {
|
|
|
87 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
|
|
88 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
User user = userClient.getUserById(userId);
|
|
|
92 |
user.setDateOfBirth(dateOfBirth);
|
|
|
93 |
user.setName(name);
|
|
|
94 |
user.setCommunicationEmail(communicationEmail);
|
| 1634 |
vikas |
95 |
try {
|
|
|
96 |
user.setSex(Sex.findByValue(Integer.parseInt(sex)));
|
|
|
97 |
}
|
|
|
98 |
catch (NumberFormatException e) {
|
|
|
99 |
e.printStackTrace();
|
|
|
100 |
}
|
| 762 |
rajveer |
101 |
user.setMobileNumber(phone);
|
|
|
102 |
userClient.updateUser(user);
|
|
|
103 |
|
|
|
104 |
return true;
|
|
|
105 |
} catch (UserContextException e) {
|
|
|
106 |
e.printStackTrace();
|
|
|
107 |
} catch (TException e) {
|
|
|
108 |
e.printStackTrace();
|
|
|
109 |
} catch (Exception e) {
|
|
|
110 |
e.printStackTrace();
|
|
|
111 |
}
|
|
|
112 |
return false;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
| 595 |
rajveer |
117 |
|
|
|
118 |
public Map<String, String> getVelocityParams(){
|
|
|
119 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
120 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
121 |
try{
|
|
|
122 |
User user = null;
|
|
|
123 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
124 |
userClient = userContextServiceClient.getClient();
|
|
|
125 |
user = userClient.getUserById(userinfo.getUserId());
|
|
|
126 |
|
|
|
127 |
velocityParams.put("email", user.getCommunicationEmail());
|
|
|
128 |
velocityParams.put("sex", user.getSex().getValue()+"");
|
|
|
129 |
velocityParams.put("name", user.getName());
|
|
|
130 |
velocityParams.put("phone", user.getMobileNumber());
|
|
|
131 |
velocityParams.put("dateOfBirth", user.getDateOfBirth());
|
|
|
132 |
}catch (Exception e){
|
|
|
133 |
e.printStackTrace();
|
|
|
134 |
}
|
|
|
135 |
return velocityParams;
|
|
|
136 |
}
|
|
|
137 |
|
| 650 |
rajveer |
138 |
public String getMyaccountHeaderSnippet(){
|
| 507 |
rajveer |
139 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
public String getPersonalDetailsSnippet(){
|
|
|
143 |
return htmlSnippets.get("PERSONAL_DETAILS");
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
}
|