| Line 12... |
Line 12... |
| 12 |
|
12 |
|
| 13 |
import java.util.*;
|
13 |
import java.util.*;
|
| 14 |
|
14 |
|
| 15 |
import org.apache.juli.logging.Log;
|
15 |
import org.apache.juli.logging.Log;
|
| 16 |
import org.apache.juli.logging.LogFactory;
|
16 |
import org.apache.juli.logging.LogFactory;
|
| - |
|
17 |
import org.apache.struts2.convention.annotation.Result;
|
| - |
|
18 |
import org.apache.struts2.convention.annotation.Results;
|
| 17 |
import org.apache.struts2.interceptor.ParameterAware;
|
19 |
import org.apache.struts2.interceptor.ParameterAware;
|
| 18 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
20 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
| 19 |
import org.apache.struts2.rest.HttpHeaders;
|
21 |
import org.apache.struts2.rest.HttpHeaders;
|
| 20 |
import org.apache.thrift.TException;
|
22 |
import org.apache.thrift.TException;
|
| 21 |
|
23 |
|
| - |
|
24 |
@Results({
|
| - |
|
25 |
@Result(name="redirect", type="redirectAction",
|
| - |
|
26 |
params = {"actionName" , "shipping"}),
|
| - |
|
27 |
@Result(name="login", type="redirectAction",
|
| - |
|
28 |
params = {"actionName" , "login"})
|
| - |
|
29 |
})
|
| 22 |
public class ShippingController extends BaseController implements ParameterAware{
|
30 |
public class ShippingController extends BaseController implements ParameterAware{
|
| 23 |
|
31 |
|
| 24 |
private static final long serialVersionUID = 1L;
|
32 |
private static final long serialVersionUID = 1L;
|
| 25 |
private static Log log = LogFactory.getLog(ShippingController.class);
|
33 |
private static Log log = LogFactory.getLog(ShippingController.class);
|
| 26 |
Map<String, String[]> reqparams = null;
|
34 |
Map<String, String[]> reqparams = null;
|
| Line 34... |
Line 42... |
| 34 |
super();
|
42 |
super();
|
| 35 |
pageManager = PageManager.getPageManager();
|
43 |
pageManager = PageManager.getPageManager();
|
| 36 |
}
|
44 |
}
|
| 37 |
|
45 |
|
| 38 |
// GET /shipping
|
46 |
// GET /shipping
|
| 39 |
public HttpHeaders index() {
|
47 |
public String index() {
|
| - |
|
48 |
if(!userinfo.isLoggedIn()){
|
| - |
|
49 |
this.request.getSession().setAttribute("REDIRECT_URL", this.request.getRequestURI());
|
| - |
|
50 |
return "login";
|
| - |
|
51 |
}
|
| 40 |
long userId = userinfo.getUserId();
|
52 |
long userId = userinfo.getUserId();
|
| 41 |
boolean isLoggedIn = userinfo.isLoggedIn();
|
53 |
boolean isLoggedIn = userinfo.isLoggedIn();
|
| 42 |
|
54 |
|
| 43 |
|
- |
|
| 44 |
try {
|
55 |
try {
|
| 45 |
UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
|
56 |
UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
|
| 46 |
User user = userClient.getUserById(userId);
|
57 |
long defaultAddressId = userClient.getDefaultAddressId(userId);
|
| 47 |
log.info("The default address id of this user is: " + user.getDefaultAddressId());
|
58 |
log.info("The default address id of this user is: " + defaultAddressId);
|
| 48 |
if(user.getDefaultAddressId() > 0)
|
59 |
if(defaultAddressId > 0)
|
| 49 |
userClient.addAddressToCart(userinfo.getCartId(), user.getDefaultAddressId());
|
60 |
userClient.addAddressToCart(userinfo.getCartId(), defaultAddressId);
|
| 50 |
if(!userClient.validateCart(userinfo.getCartId()))
|
61 |
if(!userClient.validateCart(userinfo.getCartId()))
|
| 51 |
errorMsg = "Your cart has been updated.";
|
62 |
errorMsg = "Your cart has been updated.";
|
| 52 |
|
63 |
|
| 53 |
} catch (Exception e) {
|
64 |
} catch (Exception e) {
|
| 54 |
// This exception can be ignored for showing the cart. Not so
|
65 |
// This exception can be ignored for showing the cart. Not so
|
| Line 65... |
Line 76... |
| 65 |
params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");
|
76 |
params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");
|
| 66 |
params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
|
77 |
params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
|
| 67 |
params.put(PageContentKeys.ERROR_MSG, errorMsg);
|
78 |
params.put(PageContentKeys.ERROR_MSG, errorMsg);
|
| 68 |
htmlSnippets = pageManager.getPageContents(PageEnum.SHIPPING_PAGE, params);
|
79 |
htmlSnippets = pageManager.getPageContents(PageEnum.SHIPPING_PAGE, params);
|
| 69 |
|
80 |
|
| 70 |
return new DefaultHttpHeaders("index").disableCaching();
|
81 |
return "index";
|
| 71 |
}
|
82 |
}
|
| 72 |
|
83 |
|
| 73 |
// POST /entity
|
84 |
// POST /entity
|
| 74 |
public HttpHeaders create(){
|
85 |
public String create(){
|
| 75 |
UserContextServiceClient userContextServiceClient = null;
|
86 |
UserContextServiceClient userContextServiceClient = null;
|
| 76 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
87 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
| 77 |
|
88 |
|
| 78 |
printParams();
|
- |
|
| 79 |
|
- |
|
| 80 |
String action = this.request.getParameter("action");
|
89 |
String action = this.request.getParameter("action");
|
| 81 |
if(action == null){
|
90 |
if(action == null){
|
| 82 |
return new DefaultHttpHeaders("failure");
|
91 |
return "failure";
|
| 83 |
}
|
92 |
}
|
| 84 |
|
93 |
|
| 85 |
try {
|
94 |
try {
|
| 86 |
userContextServiceClient = new UserContextServiceClient();
|
95 |
userContextServiceClient = new UserContextServiceClient();
|
| 87 |
userClient = userContextServiceClient.getClient();
|
96 |
userClient = userContextServiceClient.getClient();
|
| 88 |
} catch (Exception e) {
|
- |
|
| 89 |
return new DefaultHttpHeaders("failure");
|
- |
|
| 90 |
}
|
- |
|
| 91 |
|
- |
|
| 92 |
if(action.equals("addnew")){
|
- |
|
| 93 |
|
97 |
|
| - |
|
98 |
if(action != null){
|
| - |
|
99 |
if(action.equals("add")){
|
| 94 |
Address address = new Address();
|
100 |
Address address = new Address();
|
| 95 |
address.setName(this.request.getParameter("customername"));
|
101 |
address.setName(this.request.getParameter("name"));
|
| 96 |
address.setLine1(this.request.getParameter("line1"));
|
102 |
address.setLine1(this.request.getParameter("line1"));
|
| 97 |
address.setLine2(this.request.getParameter("line2"));
|
103 |
address.setLine2(this.request.getParameter("line2"));
|
| 98 |
address.setCity(this.request.getParameter("city"));
|
104 |
address.setCity(this.request.getParameter("city"));
|
| 99 |
address.setState(this.request.getParameter("state"));
|
105 |
address.setState(this.request.getParameter("state"));
|
| 100 |
address.setPin(this.request.getParameter("pincode"));
|
106 |
address.setPin(this.request.getParameter("pincode"));
|
| 101 |
address.setPhone(this.request.getParameter("mobilenumber"));
|
107 |
address.setPhone(this.request.getParameter("phone"));
|
| 102 |
address.setCountry(this.request.getParameter("country"));
|
108 |
address.setCountry(this.request.getParameter("country"));
|
| 103 |
address.setEnabled(true);
|
109 |
address.setEnabled(true);
|
| 104 |
address.setType(AddressType.HOME);
|
110 |
address.setType(AddressType.HOME);
|
| 105 |
|
- |
|
| 106 |
if(userinfo.isLoggedIn()){
|
- |
|
| 107 |
try {
|
- |
|
| 108 |
this.addressId = userClient.addAddressForUser(userinfo.getUserId(), address, false);
|
111 |
long addressId = userClient.addAddressForUser(userinfo.getUserId(), address, false);
|
| 109 |
// to set the address in cart
|
- |
|
| 110 |
userClient.addAddressToCart(userinfo.getCartId(), this.addressId);
|
112 |
userClient.addAddressToCart(userinfo.getCartId(), addressId);
|
| 111 |
} catch (Exception e) {
|
113 |
addActionMessage("Address added successfully.");
|
| 112 |
e.printStackTrace();
|
114 |
return "redirect";
|
| 113 |
return new DefaultHttpHeaders("failure");
|
- |
|
| 114 |
}
|
115 |
}
|
| 115 |
|
116 |
|
| 116 |
return new DefaultHttpHeaders("success");
|
- |
|
| 117 |
}else{
|
- |
|
| 118 |
return new DefaultHttpHeaders("failure");
|
- |
|
| 119 |
}
|
- |
|
| 120 |
}
|
- |
|
| 121 |
if(action.equals("change")){
|
117 |
if(action.equals("change")){
|
| 122 |
try {
|
- |
|
| 123 |
long addressId = Long.parseLong(this.request.getParameter("addressid"));
|
118 |
long addressId = Long.parseLong(this.request.getParameter("addressid"));
|
| 124 |
userClient.addAddressToCart(userinfo.getCartId(), addressId);
|
119 |
userClient.addAddressToCart(userinfo.getCartId(), addressId);
|
| 125 |
} catch (TException e) {
|
- |
|
| 126 |
e.printStackTrace();
|
120 |
return "success";
|
| 127 |
} catch (Exception e) {
|
- |
|
| 128 |
e.printStackTrace();
|
121 |
}
|
| 129 |
}
|
122 |
}
|
| - |
|
123 |
} catch (Exception e) {
|
| 130 |
return new DefaultHttpHeaders("success");
|
124 |
return "failure";
|
| 131 |
}
|
125 |
}
|
| 132 |
return new DefaultHttpHeaders("failure");
|
126 |
return null;
|
| 133 |
}
|
127 |
}
|
| 134 |
|
128 |
|
| 135 |
public void printParams(){
|
- |
|
| 136 |
for(String param : reqparams.keySet()) {
|
- |
|
| 137 |
log.info("param name is " + param);
|
- |
|
| 138 |
log.info("param first is " + reqparams.get(param)[0]);
|
- |
|
| 139 |
}
|
- |
|
| 140 |
log.info(this.reqparams);
|
- |
|
| 141 |
}
|
- |
|
| 142 |
|
129 |
|
| 143 |
@Override
|
130 |
@Override
|
| 144 |
public void setParameters(Map<String, String[]> reqmap) {
|
131 |
public void setParameters(Map<String, String[]> reqmap) {
|
| 145 |
log.info("setParameters:" + reqmap);
|
132 |
log.info("setParameters:" + reqmap);
|
| 146 |
|
133 |
|