Subversion Repositories SmartDukaan

Rev

Rev 712 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 712 Rev 822
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.model.v1.user.Address;
3
import in.shop2020.model.v1.user.Address;
4
import in.shop2020.model.v1.user.AddressType;
4
import in.shop2020.model.v1.user.AddressType;
5
import in.shop2020.model.v1.user.User;
-
 
6
import in.shop2020.model.v1.user.UserContextService;
5
import in.shop2020.model.v1.user.UserContextService;
7
import in.shop2020.serving.controllers.BaseController;
6
import in.shop2020.serving.controllers.BaseController;
8
import in.shop2020.thrift.clients.UserContextServiceClient;
7
import in.shop2020.thrift.clients.UserContextServiceClient;
9
 
8
 
10
import java.util.*;
-
 
11
 
9
 
12
import org.apache.juli.logging.Log;
10
import org.apache.juli.logging.Log;
13
import org.apache.juli.logging.LogFactory;
11
import org.apache.juli.logging.LogFactory;
-
 
12
import org.apache.struts2.convention.annotation.InterceptorRef;
-
 
13
import org.apache.struts2.convention.annotation.InterceptorRefs;
14
import org.apache.struts2.convention.annotation.Result;
14
import org.apache.struts2.convention.annotation.Result;
15
import org.apache.struts2.convention.annotation.Results;
15
import org.apache.struts2.convention.annotation.Results;
-
 
16
 
16
import org.apache.struts2.interceptor.ParameterAware;
17
@InterceptorRefs({
17
import org.apache.struts2.rest.DefaultHttpHeaders;
18
    @InterceptorRef("myDefault"),
18
import org.apache.struts2.rest.HttpHeaders;
-
 
19
import org.apache.thrift.TException;
19
    @InterceptorRef("login")
-
 
20
})
20
 
21
 
21
@Results({
22
@Results({
22
    @Result(name="redirect", type="redirectAction", 
23
    @Result(name="redirect", type="redirectAction", 
23
    		params = {"actionName" , "shipping"}),
24
    		params = {"actionName" , "shipping"})
24
    @Result(name="login", type="redirectAction", 
-
 
25
    		params = {"actionName" , "login"})		
-
 
26
})
25
})
27
public class ShippingController extends BaseController implements ParameterAware{
26
public class ShippingController extends BaseController{
28
	
27
	
29
	private static final long serialVersionUID = 1L;
28
	private static final long serialVersionUID = 1L;
30
	private static Log log = LogFactory.getLog(ShippingController.class);
29
	private static Log log = LogFactory.getLog(ShippingController.class);
31
	Map<String, String[]> reqparams = null;
-
 
32
	
30
	
33
	private long addressId = 0;
31
	private long addressId = 0;
34
	private String errorMsg = "";
32
	private String errorMsg = "";
35
	
33
	
-
 
34
	private String name;
-
 
35
	private String line1;
-
 
36
	private String line2;
-
 
37
	private String city;
-
 
38
	private String state;
-
 
39
	private String pincode;
-
 
40
	private String phone;
-
 
41
	private String country;
-
 
42
	
36
	public ShippingController(){
43
	public ShippingController(){
37
		super();
44
		super();
38
	}
45
	}
39
	
46
	
40
	 // GET /shipping
47
	 // GET /shipping
41
	 public String index() {
48
	 public String index() {
42
		if(!userinfo.isLoggedIn()){
-
 
43
			setRedirectUrl();
-
 
44
			return "login";
-
 
45
		}
-
 
46
    	long userId = userinfo.getUserId();
49
    	long userId = userinfo.getUserId();
47
    	boolean isLoggedIn = userinfo.isLoggedIn();
50
    	boolean isLoggedIn = userinfo.isLoggedIn();
48
    	long cartId = userinfo.getCartId();
51
    	long cartId = userinfo.getCartId();
49
    	try {
52
    	try {
50
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
53
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
Line 61... Line 64...
61
			// innocent when this occurs at the time of checkout or when the
64
			// innocent when this occurs at the time of checkout or when the
62
			// user is proceeding to pay.
65
			// user is proceeding to pay.
63
			e.printStackTrace();
66
			e.printStackTrace();
64
		}
67
		}
65
    	// in case this page is redirected from payment failure
68
    	// in case this page is redirected from payment failure
66
		/*
69
		
67
		if(getActionErrors()!=null){
70
		if(getActionErrors()!=null){
68
			this.errorMsg = getActionErrors().toArray()[0].toString();
71
			this.errorMsg = getActionErrors().toArray()[0].toString();
69
		}
72
		}
70
		*/
73
		
71
		htmlSnippets.put("SHIPPING_HEADER", pageLoader.getShippingHeaderHtml());
74
		htmlSnippets.put("SHIPPING_HEADER", pageLoader.getShippingHeaderHtml());
72
		htmlSnippets.put("SHIPPING_DETAILS", pageLoader.getShippingDetailsHtml(userinfo.getCartId(), errorMsg));
75
		htmlSnippets.put("SHIPPING_DETAILS", pageLoader.getShippingDetailsHtml(userinfo.getCartId(), errorMsg));
73
		
76
		
74
    	return "index";
77
    	return "index";
75
	 }
78
	 }
Line 89... Line 92...
89
			userClient = userContextServiceClient.getClient();
92
			userClient = userContextServiceClient.getClient();
90
			
93
			
91
			if(action != null){
94
			if(action != null){
92
				if(action.equals("add")){
95
				if(action.equals("add")){
93
					Address address = new Address();
96
					Address address = new Address();
94
					address.setName(this.request.getParameter("name"));
97
					address.setName(this.name);
95
					address.setLine1(this.request.getParameter("line1"));
98
					address.setLine1(this.line1);
96
					address.setLine2(this.request.getParameter("line2"));
99
					address.setLine2(this.line2);
97
					address.setCity(this.request.getParameter("city"));
100
					address.setCity(this.city);
98
					address.setState(this.request.getParameter("state"));
101
					address.setState(this.state);
99
					address.setPin(this.request.getParameter("pincode"));
102
					address.setPin(this.pincode);
100
					address.setPhone(this.request.getParameter("phone"));
103
					address.setPhone(this.phone);
101
					address.setCountry(this.request.getParameter("country"));
104
					address.setCountry(this.country);
102
					address.setEnabled(true);
105
					address.setEnabled(true);
103
					address.setType(AddressType.HOME);
106
					address.setType(AddressType.HOME);
104
					long addressId = userClient.addAddressForUser(userinfo.getUserId(), address, false);
107
					long addressId = userClient.addAddressForUser(userinfo.getUserId(), address, false);
105
					userClient.addAddressToCart(userinfo.getCartId(), addressId);
108
					userClient.addAddressToCart(userinfo.getCartId(), addressId);
106
					addActionMessage("Address added successfully.");
109
					addActionMessage("Address added successfully.");
Line 117... Line 120...
117
			return "failure";
120
			return "failure";
118
		}
121
		}
119
		return null;
122
		return null;
120
	}
123
	}
121
 
124
 
122
	@Override
-
 
123
	public void setParameters(Map<String, String[]> reqmap) {
-
 
124
		log.info("setParameters:" + reqmap);
-
 
125
		
-
 
126
		this.reqparams = reqmap;
-
 
127
	}
-
 
128
 
-
 
129
	public String getShippingHeaderSnippet(){
125
	public String getShippingHeaderSnippet(){
130
		return htmlSnippets.get("SHIPPING_HEADER");
126
		return htmlSnippets.get("SHIPPING_HEADER");
131
	}
127
	}
132
	
128
	
133
	public String getShippingDetailsSnippet(){
129
	public String getShippingDetailsSnippet(){
Line 139... Line 135...
139
	}
135
	}
140
	
136
	
141
	public String getErrorMsg(){
137
	public String getErrorMsg(){
142
		return this.errorMsg;
138
		return this.errorMsg;
143
	}
139
	}
-
 
140
	
-
 
141
	public String getName() {
-
 
142
		return name;
-
 
143
	}
-
 
144
 
-
 
145
	public void setName(String name) {
-
 
146
		this.name = name;
-
 
147
	}
-
 
148
 
-
 
149
	public String getLine1() {
-
 
150
		return line1;
-
 
151
	}
-
 
152
 
-
 
153
	public void setLine1(String line1) {
-
 
154
		this.line1 = line1;
-
 
155
	}
-
 
156
 
-
 
157
	public String getLine2() {
-
 
158
		return line2;
-
 
159
	}
-
 
160
 
-
 
161
	public void setLine2(String line2) {
-
 
162
		this.line2 = line2;
-
 
163
	}
-
 
164
 
-
 
165
	public String getCity() {
-
 
166
		return city;
-
 
167
	}
-
 
168
 
-
 
169
	public void setCity(String city) {
-
 
170
		this.city = city;
-
 
171
	}
-
 
172
 
-
 
173
	public String getState() {
-
 
174
		return state;
-
 
175
	}
-
 
176
 
-
 
177
	public void setState(String state) {
-
 
178
		this.state = state;
-
 
179
	}
-
 
180
 
-
 
181
	public String getPincode() {
-
 
182
		return pincode;
-
 
183
	}
-
 
184
 
-
 
185
	public void setPincode(String pincode) {
-
 
186
		this.pincode = pincode;
-
 
187
	}
-
 
188
 
-
 
189
	public String getCountry() {
-
 
190
		return country;
-
 
191
	}
-
 
192
 
-
 
193
	public void setCountry(String country) {
-
 
194
		this.country = country;
-
 
195
	}
-
 
196
	
-
 
197
	public String getPhone() {
-
 
198
		return phone;
-
 
199
	}
-
 
200
 
-
 
201
	public void setPhone(String phone) {
-
 
202
		this.phone = phone;
-
 
203
	}
144
}
204
}