1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class UserTrackerImpl
42      extends UserTrackerModelImpl implements UserTracker {
43  
44      public UserTrackerImpl() {
45      }
46  
47      public String getFullName() {
48          if (_fullName == null) {
49              try {
50                  if (_user == null) {
51                      _user = UserLocalServiceUtil.getUserById(getUserId());
52                  }
53  
54                  _fullName = _user.getFullName();
55              }
56              catch (Exception e) {
57              }
58          }
59  
60          if (_fullName == null) {
61              _fullName = StringPool.BLANK;
62          }
63  
64          return _fullName;
65      }
66  
67      public String getEmailAddress() {
68          if (_emailAddress == null) {
69              try {
70                  if (_user == null) {
71                      _user = UserLocalServiceUtil.getUserById(getUserId());
72                  }
73  
74                  _emailAddress = _user.getEmailAddress();
75              }
76              catch (Exception e) {
77              }
78          }
79  
80          if (_emailAddress == null) {
81              _emailAddress = StringPool.BLANK;
82          }
83  
84          return _emailAddress;
85      }
86  
87      public List<UserTrackerPath> getPaths() {
88          return _paths;
89      }
90  
91      public void addPath(UserTrackerPath path) {
92          try {
93              _paths.add(path);
94          }
95          catch (ArrayIndexOutOfBoundsException aioobe) {
96              if (_log.isWarnEnabled()) {
97                  _log.warn(aioobe);
98              }
99          }
100 
101         setModifiedDate(path.getPathDate());
102     }
103 
104     public int getHits() {
105         return _paths.size();
106     }
107 
108     public int compareTo(UserTracker userTracker) {
109         String userName1 = getFullName().toLowerCase();
110         String userName2 = userTracker.getFullName().toLowerCase();
111 
112         int value = userName1.compareTo(userName2);
113 
114         if (value == 0) {
115             value = getModifiedDate().compareTo(userTracker.getModifiedDate());
116         }
117 
118         return value;
119     }
120 
121     private static Log _log = LogFactoryUtil.getLog(UserTrackerImpl.class);
122 
123     private User _user;
124     private String _fullName;
125     private String _emailAddress;
126     private List<UserTrackerPath> _paths = new ArrayList<UserTrackerPath>();
127 
128 }