001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.model.User;
021    import com.liferay.portal.model.UserTracker;
022    import com.liferay.portal.model.UserTrackerPath;
023    import com.liferay.portal.service.UserLocalServiceUtil;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class UserTrackerImpl extends UserTrackerBaseImpl {
032    
033            public UserTrackerImpl() {
034            }
035    
036            public String getFullName() {
037                    if (_fullName == null) {
038                            try {
039                                    if (_user == null) {
040                                            _user = UserLocalServiceUtil.getUserById(getUserId());
041                                    }
042    
043                                    _fullName = _user.getFullName();
044                            }
045                            catch (Exception e) {
046                            }
047                    }
048    
049                    if (_fullName == null) {
050                            _fullName = StringPool.BLANK;
051                    }
052    
053                    return _fullName;
054            }
055    
056            public String getEmailAddress() {
057                    if (_emailAddress == null) {
058                            try {
059                                    if (_user == null) {
060                                            _user = UserLocalServiceUtil.getUserById(getUserId());
061                                    }
062    
063                                    _emailAddress = _user.getEmailAddress();
064                            }
065                            catch (Exception e) {
066                            }
067                    }
068    
069                    if (_emailAddress == null) {
070                            _emailAddress = StringPool.BLANK;
071                    }
072    
073                    return _emailAddress;
074            }
075    
076            public List<UserTrackerPath> getPaths() {
077                    return _paths;
078            }
079    
080            public void addPath(UserTrackerPath path) {
081                    try {
082                            _paths.add(path);
083                    }
084                    catch (ArrayIndexOutOfBoundsException aioobe) {
085                            if (_log.isWarnEnabled()) {
086                                    _log.warn(aioobe);
087                            }
088                    }
089    
090                    setModifiedDate(path.getPathDate());
091            }
092    
093            public int getHits() {
094                    return _paths.size();
095            }
096    
097            @Override
098            public int compareTo(UserTracker userTracker) {
099                    String userName1 = getFullName().toLowerCase();
100                    String userName2 = userTracker.getFullName().toLowerCase();
101    
102                    int value = userName1.compareTo(userName2);
103    
104                    if (value == 0) {
105                            value = getModifiedDate().compareTo(userTracker.getModifiedDate());
106                    }
107    
108                    return value;
109            }
110    
111            private static Log _log = LogFactoryUtil.getLog(UserTrackerImpl.class);
112    
113            private User _user;
114            private String _fullName;
115            private String _emailAddress;
116            private List<UserTrackerPath> _paths = new ArrayList<UserTrackerPath>();
117    
118    }