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