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