001    /**
002     * Copyright (c) 2000-2010 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.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.UserTracker;
020    import com.liferay.portal.model.UserTrackerPath;
021    import com.liferay.portal.service.base.UserTrackerLocalServiceBaseImpl;
022    import com.liferay.portal.util.PropsValues;
023    
024    import java.util.Date;
025    import java.util.Iterator;
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class UserTrackerLocalServiceImpl
032            extends UserTrackerLocalServiceBaseImpl {
033    
034            public UserTracker addUserTracker(
035                            long companyId, long userId, Date modifiedDate, String sessionId,
036                            String remoteAddr, String remoteHost, String userAgent,
037                            List<UserTrackerPath> userTrackerPaths)
038                    throws SystemException {
039    
040                    if (PropsValues.SESSION_TRACKER_PERSISTENCE_ENABLED) {
041                            long userTrackerId = counterLocalService.increment(
042                                    UserTracker.class.getName());
043    
044                            UserTracker userTracker =
045                                    userTrackerPersistence.create(userTrackerId);
046    
047                            userTracker.setCompanyId(companyId);
048                            userTracker.setUserId(userId);
049                            userTracker.setModifiedDate(modifiedDate);
050                            userTracker.setSessionId(sessionId);
051                            userTracker.setRemoteAddr(remoteAddr);
052                            userTracker.setRemoteHost(remoteHost);
053                            userTracker.setUserAgent(userAgent);
054    
055                            userTrackerPersistence.update(userTracker, false);
056    
057                            Iterator<UserTrackerPath> itr = userTrackerPaths.iterator();
058    
059                            while (itr.hasNext()) {
060                                    UserTrackerPath userTrackerPath = itr.next();
061    
062                                    long pathId = counterLocalService.increment(
063                                            UserTrackerPath.class.getName());
064    
065                                    userTrackerPath.setUserTrackerPathId(pathId);
066                                    userTrackerPath.setUserTrackerId(userTrackerId);
067    
068                                    userTrackerPathPersistence.update(userTrackerPath, false);
069                            }
070    
071                            return userTracker;
072                    }
073                    else {
074                            return null;
075                    }
076            }
077    
078            public void deleteUserTracker(long userTrackerId)
079                    throws PortalException, SystemException {
080    
081                    // Paths
082    
083                    userTrackerPathPersistence.removeByUserTrackerId(userTrackerId);
084    
085                    // User tracker
086    
087                    userTrackerPersistence.remove(userTrackerId);
088            }
089    
090            public List<UserTracker> getUserTrackers(long companyId, int start, int end)
091                    throws SystemException {
092    
093                    return userTrackerPersistence.findByCompanyId(companyId, start, end);
094            }
095    
096    }