001    /**
002     * Copyright (c) 2000-2013 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.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class UserTrackerLocalServiceImpl
031            extends UserTrackerLocalServiceBaseImpl {
032    
033            @Override
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 = userTrackerPersistence.create(
045                                    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);
056    
057                            for (UserTrackerPath userTrackerPath : userTrackerPaths) {
058                                    long pathId = counterLocalService.increment(
059                                            UserTrackerPath.class.getName());
060    
061                                    userTrackerPath.setUserTrackerPathId(pathId);
062                                    userTrackerPath.setUserTrackerId(userTrackerId);
063    
064                                    userTrackerPathPersistence.update(userTrackerPath);
065                            }
066    
067                            return userTracker;
068                    }
069                    else {
070                            return null;
071                    }
072            }
073    
074            @Override
075            public UserTracker deleteUserTracker(long userTrackerId)
076                    throws PortalException, SystemException {
077    
078                    UserTracker userTracker = userTrackerPersistence.findByPrimaryKey(
079                            userTrackerId);
080    
081                    return deleteUserTracker(userTracker);
082            }
083    
084            @Override
085            public UserTracker deleteUserTracker(UserTracker userTracker)
086                    throws SystemException {
087    
088                    // Paths
089    
090                    userTrackerPathPersistence.removeByUserTrackerId(
091                            userTracker.getUserTrackerId());
092    
093                    // User tracker
094    
095                    return userTrackerPersistence.remove(userTracker);
096            }
097    
098            @Override
099            public List<UserTracker> getUserTrackers(long companyId, int start, int end)
100                    throws SystemException {
101    
102                    return userTrackerPersistence.findByCompanyId(companyId, start, end);
103            }
104    
105    }