Subversion Repositories SmartDukaan

Rev

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

Rev 572 Rev 762
Line 47... Line 47...
47
		User existingUser = null;
47
		User existingUser = null;
48
		try {
48
		try {
49
			ucsc = new UserContextServiceClient();
49
			ucsc = new UserContextServiceClient();
50
			userClient = ucsc.getClient();
50
			userClient = ucsc.getClient();
51
			existingUser = userClient.getUserById(userId);
51
			existingUser = userClient.getUserById(userId);
52
			if(existingUser == null || existingUser.getUserId() == -1)
52
			if(existingUser == null || existingUser.getUserId() == -1){
53
				existingUser = userClient.createAnonymousUser(jsessionId);
53
				existingUser = userClient.createAnonymousUser(jsessionId);
-
 
54
			}
-
 
55
			totalItems = userClient.getCart(existingUser.getActiveCartId()).getLinesSize();
54
		} catch (UserContextException e) {
56
		} catch (UserContextException e) {
55
			e.printStackTrace();
57
			e.printStackTrace();
56
		} catch (TException e) {
58
		} catch (TException e) {
57
			e.printStackTrace();
59
			e.printStackTrace();
58
		} catch (Exception e) {
60
		} catch (Exception e) {
59
			e.printStackTrace();
61
			e.printStackTrace();
60
		} finally {
-
 
61
			
-
 
62
		}
62
		}
-
 
63
		/*
-
 
64
		finally {
-
 
65
			ucsc.closeConnection();
63
		
66
		}
-
 
67
		*/
64
		initialize(existingUser);
68
		initialize(existingUser, totalItems);
65
	}
69
	}
66
 
70
 
67
	public UserSessionInfo(String jsessionId) {
71
	public UserSessionInfo(String jsessionId) {
68
		this();
72
		this();
69
		UserContextServiceClient ucsc = null;
73
		UserContextServiceClient ucsc = null;
70
		try {
74
		try {
71
			ucsc = new UserContextServiceClient();
75
			ucsc = new UserContextServiceClient();
72
			in.shop2020.model.v1.user.UserContextService.Client userClient = ucsc.getClient();
76
			in.shop2020.model.v1.user.UserContextService.Client userClient = ucsc.getClient();
73
			User anonUser = userClient.createAnonymousUser(jsessionId);
77
			User anonUser = userClient.createAnonymousUser(jsessionId);
-
 
78
			int totalItems= userClient.getCart(anonUser.getActiveCartId()).getLinesSize();
74
			initialize(anonUser);
79
			initialize(anonUser, totalItems);
75
		} catch (UserContextException e) {
80
		} catch (UserContextException e) {
76
			e.printStackTrace();
81
			e.printStackTrace();
77
		} catch (TException e) {
82
		} catch (TException e) {
78
			e.printStackTrace();
83
			e.printStackTrace();
79
		} catch (Exception e) {
84
		} catch (Exception e) {
80
			e.printStackTrace();
85
			e.printStackTrace();
81
		}
86
		}
-
 
87
		/*
-
 
88
		finally{
-
 
89
			ucsc.closeConnection();
-
 
90
		}
-
 
91
		*/
82
	}
92
	}
83
 
93
 
84
	private void initialize(User user){
94
	private void initialize(User user, int totalItems){
85
		if(user!=null){
95
		if(user!=null){
86
			this.isLoggedIn = !user.isIsAnonymous();
96
			this.isLoggedIn = !user.isIsAnonymous();
87
			this.userId = user.getUserId();
97
			this.userId = user.getUserId();
88
			this.email = user.getEmail();
98
			this.email = user.getEmail();
89
			this.nameOfUser = user.getName();
99
			this.nameOfUser = user.getName();
90
			this.cartId = user.getActiveCartId();
100
			this.cartId = user.getActiveCartId();
91
			this.totalItems = Utils.getNumberOfItemsInCart(this.cartId);
101
			this.totalItems = totalItems;
92
		}else{
102
		}else{
93
			this.isLoggedIn = false;
103
			this.isLoggedIn = false;
94
			this.userId = -1;
104
			this.userId = -1;
95
			this.email = "";
105
			this.email = "";
96
			this.nameOfUser = "";
106
			this.nameOfUser = "";