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            public UserTracker addUserTracker(
034                            long companyId, long userId, Date modifiedDate, String sessionId,
035                            String remoteAddr, String remoteHost, String userAgent,
036                            List<UserTrackerPath> userTrackerPaths)
037                    throws SystemException {
038    
039                    if (PropsValues.SESSION_TRACKER_PERSISTENCE_ENABLED) {
040                            long userTrackerId = counterLocalService.increment(
041                                    UserTracker.class.getName());
042    
043                            UserTracker userTracker = userTrackerPersistence.create(
044                                    userTrackerId);
045    
046                            userTracker.setCompanyId(companyId);
047                            userTracker.setUserId(userId);
048                            userTracker.setModifiedDate(modifiedDate);
049                            userTracker.setSessionId(sessionId);
050                            userTracker.setRemoteAddr(remoteAddr);
051                            userTracker.setRemoteHost(remoteHost);
052                            userTracker.setUserAgent(userAgent);
053    
054                            userTrackerPersistence.update(userTracker);
055    
056                            for (UserTrackerPath userTrackerPath : userTrackerPaths) {
057                                    long pathId = counterLocalService.increment(
058                                            UserTrackerPath.class.getName());
059    
060                                    userTrackerPath.setUserTrackerPathId(pathId);
061                                    userTrackerPath.setUserTrackerId(userTrackerId);
062    
063                                    userTrackerPathPersistence.update(userTrackerPath);
064                            }
065    
066                            return userTracker;
067                    }
068                    else {
069                            return null;
070                    }
071            }
072    
073            @Override
074            public UserTracker deleteUserTracker(long userTrackerId)
075                    throws PortalException, SystemException {
076    
077                    UserTracker userTracker = userTrackerPersistence.findByPrimaryKey(
078                            userTrackerId);
079    
080                    return deleteUserTracker(userTracker);
081            }
082    
083            @Override
084            public UserTracker deleteUserTracker(UserTracker userTracker)
085                    throws SystemException {
086    
087                    // Paths
088    
089                    userTrackerPathPersistence.removeByUserTrackerId(
090                            userTracker.getUserTrackerId());
091    
092                    // User tracker
093    
094                    return userTrackerPersistence.remove(userTracker);
095            }
096    
097            public List<UserTracker> getUserTrackers(long companyId, int start, int end)
098                    throws SystemException {
099    
100                    return userTrackerPersistence.findByCompanyId(companyId, start, end);
101            }
102    
103    }