1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.model.UserTracker;
20  import com.liferay.portal.model.UserTrackerPath;
21  import com.liferay.portal.service.base.UserTrackerLocalServiceBaseImpl;
22  import com.liferay.portal.util.PropsValues;
23  
24  import java.util.Date;
25  import java.util.Iterator;
26  import java.util.List;
27  
28  /**
29   * <a href="UserTrackerLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class UserTrackerLocalServiceImpl
34      extends UserTrackerLocalServiceBaseImpl {
35  
36      public UserTracker addUserTracker(
37              long companyId, long userId, Date modifiedDate, String sessionId,
38              String remoteAddr, String remoteHost, String userAgent,
39              List<UserTrackerPath> userTrackerPaths)
40          throws SystemException {
41  
42          if (PropsValues.SESSION_TRACKER_PERSISTENCE_ENABLED) {
43              long userTrackerId = counterLocalService.increment(
44                  UserTracker.class.getName());
45  
46              UserTracker userTracker =
47                  userTrackerPersistence.create(userTrackerId);
48  
49              userTracker.setCompanyId(companyId);
50              userTracker.setUserId(userId);
51              userTracker.setModifiedDate(modifiedDate);
52              userTracker.setSessionId(sessionId);
53              userTracker.setRemoteAddr(remoteAddr);
54              userTracker.setRemoteHost(remoteHost);
55              userTracker.setUserAgent(userAgent);
56  
57              userTrackerPersistence.update(userTracker, false);
58  
59              Iterator<UserTrackerPath> itr = userTrackerPaths.iterator();
60  
61              while (itr.hasNext()) {
62                  UserTrackerPath userTrackerPath = itr.next();
63  
64                  long pathId = counterLocalService.increment(
65                      UserTrackerPath.class.getName());
66  
67                  userTrackerPath.setUserTrackerPathId(pathId);
68                  userTrackerPath.setUserTrackerId(userTrackerId);
69  
70                  userTrackerPathPersistence.update(userTrackerPath, false);
71              }
72  
73              return userTracker;
74          }
75          else {
76              return null;
77          }
78      }
79  
80      public void deleteUserTracker(long userTrackerId)
81          throws PortalException, SystemException {
82  
83          // Paths
84  
85          userTrackerPathPersistence.removeByUserTrackerId(userTrackerId);
86  
87          // User tracker
88  
89          userTrackerPersistence.remove(userTrackerId);
90      }
91  
92      public List<UserTracker> getUserTrackers(long companyId, int start, int end)
93          throws SystemException {
94  
95          return userTrackerPersistence.findByCompanyId(companyId, start, end);
96      }
97  
98  }