1   /**
2    * Copyright (c) 2000-2009 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.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.model.User;
29  import com.liferay.portal.model.UserTracker;
30  import com.liferay.portal.model.UserTrackerPath;
31  import com.liferay.portal.service.UserLocalServiceUtil;
32  
33  import java.util.ArrayList;
34  import java.util.List;
35  
36  /**
37   * <a href="UserTrackerImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class UserTrackerImpl
43      extends UserTrackerModelImpl implements UserTracker {
44  
45      public UserTrackerImpl() {
46      }
47  
48      public String getFullName() {
49          if (_fullName == null) {
50              try {
51                  if (_user == null) {
52                      _user = UserLocalServiceUtil.getUserById(getUserId());
53                  }
54  
55                  _fullName = _user.getFullName();
56              }
57              catch (Exception e) {
58              }
59          }
60  
61          if (_fullName == null) {
62              _fullName = StringPool.BLANK;
63          }
64  
65          return _fullName;
66      }
67  
68      public String getEmailAddress() {
69          if (_emailAddress == null) {
70              try {
71                  if (_user == null) {
72                      _user = UserLocalServiceUtil.getUserById(getUserId());
73                  }
74  
75                  _emailAddress = _user.getEmailAddress();
76              }
77              catch (Exception e) {
78              }
79          }
80  
81          if (_emailAddress == null) {
82              _emailAddress = StringPool.BLANK;
83          }
84  
85          return _emailAddress;
86      }
87  
88      public List<UserTrackerPath> getPaths() {
89          return _paths;
90      }
91  
92      public void addPath(UserTrackerPath path) {
93          try {
94              _paths.add(path);
95          }
96          catch (ArrayIndexOutOfBoundsException aioobe) {
97              if (_log.isWarnEnabled()) {
98                  _log.warn(aioobe);
99              }
100         }
101 
102         setModifiedDate(path.getPathDate());
103     }
104 
105     public int getHits() {
106         return _paths.size();
107     }
108 
109     public int compareTo(Object obj) {
110         UserTracker userTracker = (UserTracker)obj;
111 
112         String userName1 = getFullName().toLowerCase();
113         String userName2 = userTracker.getFullName().toLowerCase();
114 
115         int value = userName1.compareTo(userName2);
116 
117         if (value == 0) {
118             value = getModifiedDate().compareTo(userTracker.getModifiedDate());
119         }
120 
121         return value;
122     }
123 
124     private static Log _log = LogFactoryUtil.getLog(UserTrackerImpl.class);
125 
126     private User _user;
127     private String _fullName;
128     private String _emailAddress;
129     private List<UserTrackerPath> _paths = new ArrayList<UserTrackerPath>();
130 
131 }