1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.model.impl;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.kernel.util.StringPool;
25  import com.liferay.portal.model.User;
26  import com.liferay.portal.model.UserTracker;
27  import com.liferay.portal.model.UserTrackerPath;
28  import com.liferay.portal.service.UserLocalServiceUtil;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * <a href="UserTrackerImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class UserTrackerImpl
40      extends UserTrackerModelImpl implements UserTracker {
41  
42      public UserTrackerImpl() {
43      }
44  
45      public String getFullName() {
46          if (_fullName == null) {
47              try {
48                  if (_user == null) {
49                      _user = UserLocalServiceUtil.getUserById(getUserId());
50                  }
51  
52                  _fullName = _user.getFullName();
53              }
54              catch (Exception e) {
55              }
56          }
57  
58          if (_fullName == null) {
59              _fullName = StringPool.BLANK;
60          }
61  
62          return _fullName;
63      }
64  
65      public String getEmailAddress() {
66          if (_emailAddress == null) {
67              try {
68                  if (_user == null) {
69                      _user = UserLocalServiceUtil.getUserById(getUserId());
70                  }
71  
72                  _emailAddress = _user.getEmailAddress();
73              }
74              catch (Exception e) {
75              }
76          }
77  
78          if (_emailAddress == null) {
79              _emailAddress = StringPool.BLANK;
80          }
81  
82          return _emailAddress;
83      }
84  
85      public List<UserTrackerPath> getPaths() {
86          return _paths;
87      }
88  
89      public void addPath(UserTrackerPath path) {
90          try {
91              _paths.add(path);
92          }
93          catch (ArrayIndexOutOfBoundsException aioobe) {
94              if (_log.isWarnEnabled()) {
95                  _log.warn(aioobe);
96              }
97          }
98  
99          setModifiedDate(path.getPathDate());
100     }
101 
102     public int getHits() {
103         return _paths.size();
104     }
105 
106     public int compareTo(UserTracker userTracker) {
107         String userName1 = getFullName().toLowerCase();
108         String userName2 = userTracker.getFullName().toLowerCase();
109 
110         int value = userName1.compareTo(userName2);
111 
112         if (value == 0) {
113             value = getModifiedDate().compareTo(userTracker.getModifiedDate());
114         }
115 
116         return value;
117     }
118 
119     private static Log _log = LogFactoryUtil.getLog(UserTrackerImpl.class);
120 
121     private User _user;
122     private String _fullName;
123     private String _emailAddress;
124     private List<UserTrackerPath> _paths = new ArrayList<UserTrackerPath>();
125 
126 }