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 String getFullName() {
52          if (_fullName == null) {
53              try {
54                  if (_user == null) {
55                      _user = UserLocalServiceUtil.getUserById(getUserId());
56                  }
57  
58                  _fullName = _user.getFullName();
59              }
60              catch (Exception e) {
61              }
62          }
63  
64          if (_fullName == null) {
65              _fullName = StringPool.BLANK;
66          }
67  
68          return _fullName;
69      }
70  
71      public String getEmailAddress() {
72          if (_emailAddress == null) {
73              try {
74                  if (_user == null) {
75                      _user = UserLocalServiceUtil.getUserById(getUserId());
76                  }
77  
78                  _emailAddress = _user.getEmailAddress();
79              }
80              catch (Exception e) {
81              }
82          }
83  
84          if (_emailAddress == null) {
85              _emailAddress = StringPool.BLANK;
86          }
87  
88          return _emailAddress;
89      }
90  
91      public List<UserTrackerPath> getPaths() {
92          return _paths;
93      }
94  
95      public void addPath(UserTrackerPath path) {
96          try {
97              _paths.add(path);
98          }
99          catch (ArrayIndexOutOfBoundsException aioobe) {
100             if (_log.isWarnEnabled()) {
101                 _log.warn(aioobe);
102             }
103         }
104 
105         setModifiedDate(path.getPathDate());
106     }
107 
108     public int getHits() {
109         return _paths.size();
110     }
111 
112     public int compareTo(Object obj) {
113         UserTracker userTracker = (UserTracker)obj;
114 
115         String userName1 = getFullName().toLowerCase();
116         String userName2 = userTracker.getFullName().toLowerCase();
117 
118         int value = userName1.compareTo(userName2);
119 
120         if (value == 0) {
121             value = getModifiedDate().compareTo(userTracker.getModifiedDate());
122         }
123 
124         return value;
125     }
126 
127     private static Log _log = LogFactory.getLog(UserTrackerImpl.class);
128 
129     private HttpSession _session;
130     private User _user;
131     private String _fullName;
132     private String _emailAddress;
133     private List<UserTrackerPath> _paths = new ArrayList<UserTrackerPath>();
134 
135 }