1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.model.impl;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.model.User;
27  import com.liferay.portal.model.UserTracker;
28  import com.liferay.portal.model.UserTrackerPath;
29  import com.liferay.portal.service.UserLocalServiceUtil;
30  
31  import java.util.ArrayList;
32  import java.util.List;
33  
34  import javax.servlet.http.HttpSession;
35  
36  import org.apache.commons.logging.Log;
37  import org.apache.commons.logging.LogFactory;
38  
39  /**
40   * <a href="UserTrackerImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class UserTrackerImpl
46      extends UserTrackerModelImpl implements UserTracker {
47  
48      public UserTrackerImpl() {
49      }
50  
51      public HttpSession getHttpSession() {
52          return _ses;
53      }
54  
55      public void setHttpSession(HttpSession ses) {
56          _ses = ses;
57  
58          setSessionId(_ses.getId());
59      }
60  
61      public String getFullName() {
62          if (_fullName == null) {
63              try {
64                  if (_user == null) {
65                      _user = UserLocalServiceUtil.getUserById(getUserId());
66                  }
67  
68                  _fullName = _user.getFullName();
69              }
70              catch (Exception e) {
71              }
72          }
73  
74          if (_fullName == null) {
75              _fullName = StringPool.BLANK;
76          }
77  
78          return _fullName;
79      }
80  
81      public String getEmailAddress() {
82          if (_emailAddress == null) {
83              try {
84                  if (_user == null) {
85                      _user = UserLocalServiceUtil.getUserById(getUserId());
86                  }
87  
88                  _emailAddress = _user.getEmailAddress();
89              }
90              catch (Exception e) {
91              }
92          }
93  
94          if (_emailAddress == null) {
95              _emailAddress = StringPool.BLANK;
96          }
97  
98          return _emailAddress;
99      }
100 
101     public List<UserTrackerPath> getPaths() {
102         return _paths;
103     }
104 
105     public void addPath(UserTrackerPath path) {
106         try {
107             _paths.add(path);
108         }
109         catch (ArrayIndexOutOfBoundsException aioobe) {
110             if (_log.isWarnEnabled()) {
111                 _log.warn(aioobe);
112             }
113         }
114 
115         setModifiedDate(path.getPathDate());
116     }
117 
118     public int getHits() {
119         return _paths.size();
120     }
121 
122     public int compareTo(Object obj) {
123         UserTracker userTracker = (UserTracker)obj;
124 
125         String userName1 = getFullName().toLowerCase();
126         String userName2 = userTracker.getFullName().toLowerCase();
127 
128         int value = userName1.compareTo(userName2);
129 
130         if (value == 0) {
131             value = getModifiedDate().compareTo(userTracker.getModifiedDate());
132         }
133 
134         return value;
135     }
136 
137     private static Log _log = LogFactory.getLog(UserTrackerImpl.class);
138 
139     private HttpSession _ses;
140     private User _user;
141     private String _fullName;
142     private String _emailAddress;
143     private List<UserTrackerPath> _paths = new ArrayList<UserTrackerPath>();
144 
145 }