| 507 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.user.Address;
|
|
|
4 |
import in.shop2020.model.v1.user.AddressType;
|
|
|
5 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
|
|
6 |
import in.shop2020.serving.controllers.BaseController;
|
|
|
7 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
8 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
9 |
import in.shop2020.serving.pages.PageManager;
|
|
|
10 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
11 |
|
|
|
12 |
import java.util.*;
|
|
|
13 |
|
|
|
14 |
import org.apache.juli.logging.Log;
|
|
|
15 |
import org.apache.juli.logging.LogFactory;
|
|
|
16 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
17 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
18 |
import org.apache.struts2.interceptor.ParameterAware;
|
|
|
19 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
20 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
21 |
|
| 595 |
rajveer |
22 |
@Results({
|
|
|
23 |
@Result(name="redirect", type="redirectAction",
|
|
|
24 |
params = {"actionName" , "address"})
|
|
|
25 |
})
|
| 507 |
rajveer |
26 |
public class AddressController extends BaseController implements ParameterAware{
|
|
|
27 |
|
|
|
28 |
private static final long serialVersionUID = 1L;
|
|
|
29 |
private static Log log = LogFactory.getLog(AddressController.class);
|
|
|
30 |
Map<String, String[]> reqparams = null;
|
|
|
31 |
|
|
|
32 |
private Map<String,String> htmlSnippets;
|
|
|
33 |
private PageManager pageManager = null;
|
|
|
34 |
public AddressController(){
|
|
|
35 |
super();
|
|
|
36 |
pageManager = PageManager.getPageManager();
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
// GET /address
|
|
|
40 |
public HttpHeaders index() {
|
| 555 |
chandransh |
41 |
long userId = userinfo.getUserId();
|
|
|
42 |
boolean isLoggedIn = !userinfo.isLoggedIn();
|
|
|
43 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
| 507 |
rajveer |
44 |
|
|
|
45 |
params.put(PageContentKeys.CUSTOMER_ID, userId+"");
|
| 555 |
chandransh |
46 |
params.put(PageContentKeys.IS_LOGGED_IN, isLoggedIn+"");
|
| 507 |
rajveer |
47 |
params.put(PageContentKeys.CART_ID, userinfo.getCartId()+"");
|
|
|
48 |
params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");
|
| 620 |
rajveer |
49 |
params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
|
| 507 |
rajveer |
50 |
|
|
|
51 |
htmlSnippets = pageManager.getPageContents(PageEnum.SHIPPING_ADDRESS_PAGE, params);
|
|
|
52 |
|
|
|
53 |
return new DefaultHttpHeaders("index").disableCaching();
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
// POST /address
|
|
|
57 |
public HttpHeaders create(){
|
|
|
58 |
printParams();
|
|
|
59 |
|
|
|
60 |
if(userinfo.isLoggedIn()){
|
|
|
61 |
UserContextServiceClient userContextServiceClient;
|
|
|
62 |
try {
|
|
|
63 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
64 |
Client userClient = userContextServiceClient.getClient();
|
|
|
65 |
|
| 517 |
rajveer |
66 |
String action = this.request.getParameter("action");
|
|
|
67 |
String isDefault = this.request.getParameter("default");
|
|
|
68 |
|
|
|
69 |
if(action != null){
|
|
|
70 |
if(action.equals("add")){
|
|
|
71 |
Address address = new Address();
|
| 595 |
rajveer |
72 |
address.setName(this.request.getParameter("name"));
|
| 517 |
rajveer |
73 |
address.setLine1(this.request.getParameter("line1"));
|
|
|
74 |
address.setLine2(this.request.getParameter("line2"));
|
|
|
75 |
address.setCity(this.request.getParameter("city"));
|
|
|
76 |
address.setState(this.request.getParameter("state"));
|
|
|
77 |
address.setPin(this.request.getParameter("pincode"));
|
| 595 |
rajveer |
78 |
address.setPhone(this.request.getParameter("phone"));
|
| 517 |
rajveer |
79 |
address.setCountry(this.request.getParameter("country"));
|
|
|
80 |
address.setEnabled(true);
|
| 595 |
rajveer |
81 |
address.setType(AddressType.HOME);
|
| 517 |
rajveer |
82 |
if(isDefault.equals("true")){
|
| 569 |
rajveer |
83 |
userClient.addAddressForUser(userinfo.getUserId(), address, true);
|
| 595 |
rajveer |
84 |
addActionMessage("Address added successfully.");
|
| 517 |
rajveer |
85 |
}else{
|
| 569 |
rajveer |
86 |
userClient.addAddressForUser(userinfo.getUserId(), address, false);
|
| 595 |
rajveer |
87 |
addActionMessage("Address added successfully.");
|
| 517 |
rajveer |
88 |
}
|
| 595 |
rajveer |
89 |
return new DefaultHttpHeaders("redirect");
|
| 517 |
rajveer |
90 |
}
|
| 507 |
rajveer |
91 |
|
| 517 |
rajveer |
92 |
if(action.equals("delete")){
|
|
|
93 |
Long addressId = Long.parseLong(this.request.getParameter("addressid"));
|
|
|
94 |
userClient.removeAddressForUser(userinfo.getUserId(), addressId);
|
| 595 |
rajveer |
95 |
addActionMessage("Address deleted successfully.");
|
|
|
96 |
return new DefaultHttpHeaders("success");
|
| 517 |
rajveer |
97 |
}
|
|
|
98 |
|
|
|
99 |
if(action.equals("setdefault")){
|
|
|
100 |
Long addressId = Long.parseLong(this.request.getParameter("addressid"));
|
|
|
101 |
userClient.setDefaultAddress(userinfo.getUserId(), addressId);
|
| 595 |
rajveer |
102 |
addActionMessage("Address set default successfully.");
|
|
|
103 |
return new DefaultHttpHeaders("success");
|
| 517 |
rajveer |
104 |
}
|
| 507 |
rajveer |
105 |
}
|
| 595 |
rajveer |
106 |
|
| 507 |
rajveer |
107 |
} catch (Exception e) {
|
|
|
108 |
e.printStackTrace();
|
| 595 |
rajveer |
109 |
addActionError("Unable to update address.");
|
|
|
110 |
return new DefaultHttpHeaders("redirect");
|
| 507 |
rajveer |
111 |
}
|
|
|
112 |
|
| 595 |
rajveer |
113 |
return new DefaultHttpHeaders("redirect");
|
| 507 |
rajveer |
114 |
}else{
|
|
|
115 |
return new DefaultHttpHeaders("failure");
|
|
|
116 |
}
|
|
|
117 |
|
| 595 |
rajveer |
118 |
|
| 507 |
rajveer |
119 |
}
|
|
|
120 |
|
|
|
121 |
public void printParams(){
|
|
|
122 |
for(String param : reqparams.keySet()) {
|
|
|
123 |
log.info("param name is " + param);
|
|
|
124 |
log.info("param first is " + reqparams.get(param)[0]);
|
|
|
125 |
}
|
|
|
126 |
log.info(this.reqparams);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
@Override
|
|
|
130 |
public void setParameters(Map<String, String[]> reqmap) {
|
|
|
131 |
log.info("setParameters:" + reqmap);
|
|
|
132 |
|
|
|
133 |
this.reqparams = reqmap;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
public String getHeaderSnippet(){
|
|
|
137 |
return htmlSnippets.get("HEADER");
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
public String getMainMenuSnippet(){
|
|
|
141 |
return htmlSnippets.get("MAIN_MENU");
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
public String getSearchBarSnippet(){
|
|
|
145 |
return htmlSnippets.get("SEARCH_BAR");
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
public String getCustomerServiceSnippet(){
|
|
|
150 |
return htmlSnippets.get("CUSTOMER_SERVICE");
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
public String getShippingAddressHeaderSnippet(){
|
|
|
154 |
return htmlSnippets.get("SHIPPING_ADDRESS_HEADER");
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
public String getShippingAddressDetailsSnippet(){
|
|
|
158 |
return htmlSnippets.get("SHIPPING_ADDRESS_DETAILS");
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
public String getMyResearchSnippet(){
|
|
|
162 |
return htmlSnippets.get("MY_RESEARCH");
|
|
|
163 |
}
|
| 620 |
rajveer |
164 |
|
|
|
165 |
public String getBrowseHistorySnippet(){
|
|
|
166 |
return htmlSnippets.get("BROWSE_HISTORY");
|
|
|
167 |
}
|
|
|
168 |
|
| 507 |
rajveer |
169 |
public String getFooterSnippet(){
|
|
|
170 |
return htmlSnippets.get("FOOTER");
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
public String getJsFileSnippet(){
|
|
|
174 |
return htmlSnippets.get("JS_FILES");
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
public String getCssFileSnippet(){
|
|
|
178 |
return htmlSnippets.get("CSS_FILES");
|
|
|
179 |
}
|
|
|
180 |
}
|