Subversion Repositories SmartDukaan

Rev

Rev 2907 | Rev 2955 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2907 Rev 2935
Line 5... Line 5...
5
import in.shop2020.serving.interceptors.UserInterceptor;
5
import in.shop2020.serving.interceptors.UserInterceptor;
6
import in.shop2020.thrift.clients.UserContextServiceClient;
6
import in.shop2020.thrift.clients.UserContextServiceClient;
7
 
7
 
8
import java.io.Serializable;
8
import java.io.Serializable;
9
 
9
 
-
 
10
import org.apache.log4j.Logger;
10
import org.apache.thrift.TException;
11
import org.apache.thrift.TException;
11
 
12
 
12
import com.google.gson.Gson;
13
import com.google.gson.Gson;
13
 
14
 
14
/**
15
/**
Line 19... Line 20...
19
 * restarts.
20
 * restarts.
20
 * 
21
 * 
21
 * @author Chandranshu
22
 * @author Chandranshu
22
 * 
23
 * 
23
 */
24
 */
-
 
25
@SuppressWarnings("serial")
24
public class UserSessionInfo implements Serializable{
26
public class UserSessionInfo implements Serializable{
-
 
27
    
-
 
28
    private static Logger logger = Logger.getLogger(UserSessionInfo.class);
-
 
29
    
25
	/**
30
	/**
26
	 * 
31
	 * 
27
	 */
32
	 */
28
	private static final long serialVersionUID = 1L;
-
 
29
	private boolean isLoggedIn;
33
	private boolean isLoggedIn;
30
	private long userId;
34
	private long userId;
31
	private String email;
35
	private String email;
32
	private String nameOfUser;
36
	private String nameOfUser;
33
	private int totalItems;
37
	private int totalItems;
Line 44... Line 48...
44
		this.pincode = "110001";
48
		this.pincode = "110001";
45
	}
49
	}
46
 
50
 
47
	public UserSessionInfo(long userId, String jsessionId){
51
	public UserSessionInfo(long userId, String jsessionId){
48
		this();
52
		this();
49
		UserContextServiceClient ucsc = null;
-
 
50
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
-
 
51
		User existingUser = null;
-
 
52
		try {
53
		try {
53
			ucsc = new UserContextServiceClient();
54
		    UserContextServiceClient ucsc = new UserContextServiceClient();
54
			userClient = ucsc.getClient();
55
		    in.shop2020.model.v1.user.UserContextService.Client userClient = ucsc.getClient();
55
			existingUser = userClient.getUserById(userId);
56
		    User existingUser = userClient.getUserById(userId);
56
			if(existingUser == null || existingUser.getUserId() == -1){
57
			if(existingUser != null && existingUser.getUserId() != -1){
-
 
58
    			totalItems = userClient.getCart(existingUser.getActiveCartId()).getLinesSize();
57
				existingUser = userClient.createAnonymousUser(jsessionId);
59
    			pincode = userClient.getDefaultPincode(existingUser.getUserId());
-
 
60
    			initialize(existingUser, totalItems, pincode);
58
			}
61
			}
59
			totalItems = userClient.getCart(existingUser.getActiveCartId()).getLinesSize();
-
 
60
			pincode = userClient.getDefaultPincode(existingUser.getUserId());
-
 
61
		} catch (UserContextException e) {
62
		} catch (UserContextException e) {
62
			e.printStackTrace();
63
		    logger.error("Unable to get user info from user service: ", e);
63
		} catch (TException e) {
64
		} catch (TException e) {
64
			e.printStackTrace();
65
		    logger.error("Unable to get user info from user service: ", e);
65
		} catch (Exception e) {
66
		} catch (Exception e) {
66
			e.printStackTrace();
-
 
67
		}
-
 
68
		/*
-
 
69
		finally {
-
 
70
			ucsc.closeConnection();
67
		    logger.error("Unexpected exception: ", e);
71
		}
68
		}	
72
		*/
-
 
73
		initialize(existingUser, totalItems, pincode);
-
 
74
	}
69
	}
75
 
70
 
76
	public UserSessionInfo(String jsessionId) {
71
	public UserSessionInfo(String jsessionId) {
77
		this();
72
		this();
78
		UserContextServiceClient ucsc = null;
73
		UserContextServiceClient ucsc = null;
Line 82... Line 77...
82
			User anonUser = userClient.createAnonymousUser(jsessionId);
77
			User anonUser = userClient.createAnonymousUser(jsessionId);
83
			int totalItems= userClient.getCart(anonUser.getActiveCartId()).getLinesSize();
78
			int totalItems= userClient.getCart(anonUser.getActiveCartId()).getLinesSize();
84
			pincode = userClient.getDefaultPincode(anonUser.getUserId());
79
			pincode = userClient.getDefaultPincode(anonUser.getUserId());
85
			initialize(anonUser, totalItems, pincode);
80
			initialize(anonUser, totalItems, pincode);
86
		} catch (UserContextException e) {
81
		} catch (UserContextException e) {
87
			e.printStackTrace();
82
		    logger.error("Unable to get user info from user service: ", e);
88
		} catch (TException e) {
83
		} catch (TException e) {
89
			e.printStackTrace();
84
		    logger.error("Unable to get user info from user service: ", e);
90
		} catch (Exception e) {
85
		} catch (Exception e) {
91
			e.printStackTrace();
-
 
92
		}
-
 
93
		/*
-
 
94
		finally{
-
 
95
			ucsc.closeConnection();
86
		    logger.error("Unexpected exception: ", e);
96
		}
87
		}
97
		*/
-
 
98
	}
88
	}
99
 
89
 
100
	private void initialize(User user, int totalItems, String pincode){
90
	private void initialize(User user, int totalItems, String pincode){
101
		if(user!=null){
91
		if(user!=null){
102
			this.isLoggedIn = !user.isIsAnonymous();
92
			this.isLoggedIn = !user.isIsAnonymous();