Subversion Repositories SmartDukaan

Rev

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

Rev 405 Rev 413
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
-
 
6
import in.shop2020.model.v1.user.Address;
-
 
7
import in.shop2020.model.v1.user.UserContext;
-
 
8
import in.shop2020.model.v1.user.UserContextException;
-
 
9
import in.shop2020.model.v1.user.UserPrimaryInfo;
-
 
10
import in.shop2020.model.v1.user.UserState;
6
import in.shop2020.serving.pages.PageContentKeys;
11
import in.shop2020.serving.pages.PageContentKeys;
7
import in.shop2020.serving.pages.PageEnum;
12
import in.shop2020.serving.pages.PageEnum;
8
import in.shop2020.serving.pages.PageManager;
13
import in.shop2020.serving.pages.PageManager;
-
 
14
import in.shop2020.thrift.clients.ShoppingCartClient;
-
 
15
import in.shop2020.thrift.clients.UserContextServiceClient;
9
 
16
 
10
import java.io.UnsupportedEncodingException;
17
import java.io.UnsupportedEncodingException;
11
import java.net.URLEncoder;
18
import java.net.URLEncoder;
-
 
19
import java.sql.Timestamp;
12
import java.util.ArrayList;
20
import java.util.ArrayList;
13
import java.util.Arrays;
21
import java.util.Arrays;
-
 
22
import java.util.Date;
14
import java.util.HashMap;
23
import java.util.HashMap;
15
import java.util.LinkedHashMap;
24
import java.util.LinkedHashMap;
16
import java.util.List;
25
import java.util.List;
17
import java.util.Map;
26
import java.util.Map;
18
 
27
 
-
 
28
import javax.servlet.http.Cookie;
19
import javax.servlet.http.HttpServletRequest;
29
import javax.servlet.http.HttpServletRequest;
20
 
30
 
21
import org.apache.commons.lang.StringUtils;
31
import org.apache.commons.lang.StringUtils;
22
import org.apache.juli.logging.Log;
32
import org.apache.juli.logging.Log;
23
import org.apache.juli.logging.LogFactory;
33
import org.apache.juli.logging.LogFactory;
-
 
34
import org.apache.struts2.convention.annotation.Result;
-
 
35
import org.apache.struts2.convention.annotation.Results;
-
 
36
import org.apache.struts2.interceptor.ParameterAware;
24
import org.apache.struts2.interceptor.ServletRequestAware;
37
import org.apache.struts2.interceptor.ServletRequestAware;
25
import org.apache.struts2.rest.DefaultHttpHeaders;
38
import org.apache.struts2.rest.DefaultHttpHeaders;
26
import org.apache.struts2.rest.HttpHeaders;
39
import org.apache.struts2.rest.HttpHeaders;
-
 
40
import org.apache.thrift.TException;
27
 
41
 
28
import com.opensymphony.xwork2.ModelDriven;
42
import com.opensymphony.xwork2.ModelDriven;
29
 
43
 
30
/**
44
/**
31
 * @author naveen
45
 * @author rajveer
32
 *
46
 *
33
 */
47
 */
-
 
48
@Results({
-
 
49
    @Result(name="success", type="redirectAction", 
-
 
50
    		params = {"actionName" , "myaccount"})
-
 
51
})
-
 
52
 
34
public class MyaccountController extends BaseController 
53
public class MyaccountController extends BaseController 
35
	implements ServletRequestAware {
54
	implements ServletRequestAware, ParameterAware {
36
 
55
 
37
	
56
	
38
	/**
57
	/**
39
	 * 
58
	 * 
40
	 */
59
	 */
Line 44... Line 63...
44
	/**
63
	/**
45
	 * 
64
	 * 
46
	 */
65
	 */
47
	private HttpServletRequest request;
66
	private HttpServletRequest request;
48
	
67
	
-
 
68
	private Map<String, String[]> reqparams;
-
 
69
	
49
	private String id;
70
	private String id;
50
	
71
	
-
 
72
	private int action;
-
 
73
	
-
 
74
	enum actionType{
-
 
75
		LOGIN_PASSWORD,
-
 
76
		ADDRESS,
-
 
77
		LOGIN_PASSWORD_ADDRESS
-
 
78
	}
-
 
79
	
51
	public MyaccountController() {
80
	public MyaccountController() {
52
		// TODO Auto-generated constructor stub
81
		// TODO Auto-generated constructor stub
53
		super();
82
		super();
54
		
83
		
55
	}
84
	}
56
	
85
	
-
 
86
    // POST /entity
-
 
87
    public String create() {
-
 
88
    	log.info("MyAccountController.create");
-
 
89
    	log.info("action type is " + this.reqparams.get("action"));
-
 
90
    	
-
 
91
    	action = Integer.parseInt(this.reqparams.get("action")[0]);
-
 
92
    	
-
 
93
    	
-
 
94
    	try {
-
 
95
			if(addUpdateuserDetails(action)){   	
-
 
96
				return "success";
-
 
97
			}else{
-
 
98
				return "failure";
-
 
99
			}
-
 
100
		} catch (Exception e) {
-
 
101
			// TODO Auto-generated catch block
-
 
102
			e.printStackTrace();
-
 
103
		}
-
 
104
		return "failure";
-
 
105
    }
-
 
106
 
-
 
107
    
57
    // GET /test
108
    // GET /test
58
    public HttpHeaders index() throws UnsupportedEncodingException {
109
    public HttpHeaders index() throws UnsupportedEncodingException {
59
    	log.info("this.request=" + this.request);
110
    	log.info("this.request=" + this.request);
60
	
111
	
61
        return new DefaultHttpHeaders("index")
112
        return new DefaultHttpHeaders("index")
Line 80... Line 131...
80
     */
131
     */
81
    public void setId(String id) {
132
    public void setId(String id) {
82
        this.id = id;
133
        this.id = id;
83
    }
134
    }
84
 
135
 
-
 
136
    public boolean addUpdateuserDetails(int action) throws Exception{
-
 
137
    	
-
 
138
		UserContextServiceClient userContextServiceClient = null;
-
 
139
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
-
 
140
 
-
 
141
		userContextServiceClient = new UserContextServiceClient();
-
 
142
		userClient = userContextServiceClient.getClient();
-
 
143
 
-
 
144
		switch (action) {
-
 
145
		case 1:
-
 
146
			String email = this.reqparams.get("email")[0];
-
 
147
			String password = this.reqparams.get("password")[0];
-
 
148
			
-
 
149
			if(userClient.userExists(email)){
-
 
150
				return false;
-
 
151
			}else{
-
 
152
				UserContext context = new UserContext();
-
 
153
				UserPrimaryInfo primaryInfo = new UserPrimaryInfo();
-
 
154
				UserState userState = new UserState();
-
 
155
				
-
 
156
				primaryInfo.setPassword(password);
-
 
157
				primaryInfo.setEmail(email);
-
 
158
				userState.setIsLoggedIn(true);
-
 
159
				
-
 
160
				context.setPrimaryInfo(primaryInfo);
-
 
161
				context.setUserState(userState);
-
 
162
				
-
 
163
//				context.getPrimaryInfo().setPassword(email);
-
 
164
//				context.getPrimaryInfo().setPassword(password);
-
 
165
//				context.getUserState().setIsLoggedIn(true);
-
 
166
				
-
 
167
				context = userClient.createContext(context, false);
-
 
168
				return true;
-
 
169
			}
-
 
170
 
-
 
171
			//add address
-
 
172
		case 2:
-
 
173
			long userId = Long.parseLong(this.reqparams.get("user_id")[0]);
-
 
174
			String line1 = this.reqparams.get("line1")[0];
-
 
175
			String line2 = this.reqparams.get("line2")[0];
-
 
176
			String landmark = this.reqparams.get("landmark")[0];
-
 
177
			String city = this.reqparams.get("city")[0];
-
 
178
			String state = this.reqparams.get("state")[0];
-
 
179
			String pin = this.reqparams.get("pin")[0];
-
 
180
			String country = this.reqparams.get("country")[0];
-
 
181
			
-
 
182
	
-
 
183
			Address address = new Address();
-
 
184
			address.setLine1(line1);
-
 
185
			address.setLine1(line2);
-
 
186
			address.setLandmark(landmark);
-
 
187
			address.setCity(city);
-
 
188
			address.setState(state);
-
 
189
			address.setPin(pin);
-
 
190
			address.setCountry(country);
-
 
191
			long timestamp = (new  Date()).getTime();
-
 
192
			
-
 
193
			if(userClient.addAddressForUser(address, userId, timestamp)){
-
 
194
				return true;
-
 
195
			} else{
-
 
196
				return false;
-
 
197
			}
-
 
198
			
-
 
199
			
-
 
200
		case 3:
-
 
201
			
-
 
202
			break;
-
 
203
	
-
 
204
		default:
-
 
205
			break;
-
 
206
		}
-
 
207
		return false;
85
    
208
    }
-
 
209
 
-
 
210
 
86
    
211
    
87
    /**
212
    /**
88
     * 
213
     * 
89
     */
214
     */
90
    @Override
215
    @Override
91
	public void setServletRequest(HttpServletRequest request) {
216
	public void setServletRequest(HttpServletRequest request) {
92
		this.request = request;
217
		this.request = request;
93
	}
218
	}
94
 
219
 
95
    
220
    
-
 
221
	@Override
-
 
222
	public void setParameters(Map<String, String[]> reqmap) {
-
 
223
		log.info("setParameters:" + reqmap);
-
 
224
		
-
 
225
		this.reqparams = reqmap;
-
 
226
	}
-
 
227
	
-
 
228
	
96
    public String getMyAccountSnippets(){
229
    public String getMyAccountSnippets(){
97
    	return htmlSnippets.get("My_ACCOUNT");
230
    	return htmlSnippets.get("My_ACCOUNT");
98
    }
231
    }
99
 
232
 
100
    public String getMyOrdersSnippets(){
233
    public String getMyOrdersSnippets(){