1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.impl;
24  
25  import com.liferay.counter.service.CounterLocalServiceUtil;
26  import com.liferay.portal.PortalException;
27  import com.liferay.portal.SystemException;
28  import com.liferay.portal.kernel.util.GetterUtil;
29  import com.liferay.portal.model.UserTracker;
30  import com.liferay.portal.model.UserTrackerPath;
31  import com.liferay.portal.service.base.UserTrackerLocalServiceBaseImpl;
32  import com.liferay.portal.service.persistence.UserTrackerPathUtil;
33  import com.liferay.portal.service.persistence.UserTrackerUtil;
34  import com.liferay.portal.util.PropsUtil;
35  
36  import java.util.Date;
37  import java.util.Iterator;
38  import java.util.List;
39  
40  /**
41   * <a href="UserTrackerLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class UserTrackerLocalServiceImpl
47      extends UserTrackerLocalServiceBaseImpl {
48  
49      public UserTracker addUserTracker(
50              long companyId, long userId, Date modifiedDate, String sessionId,
51              String remoteAddr, String remoteHost, String userAgent,
52              List userTrackerPaths)
53          throws SystemException {
54  
55          if (GetterUtil.getBoolean(PropsUtil.get(
56                  PropsUtil.SESSION_TRACKER_PERSISTENCE_ENABLED))) {
57  
58              long userTrackerId = CounterLocalServiceUtil.increment(
59                  UserTracker.class.getName());
60  
61              UserTracker userTracker = UserTrackerUtil.create(userTrackerId);
62  
63              userTracker.setCompanyId(companyId);
64              userTracker.setUserId(userId);
65              userTracker.setModifiedDate(modifiedDate);
66              userTracker.setSessionId(sessionId);
67              userTracker.setRemoteAddr(remoteAddr);
68              userTracker.setRemoteHost(remoteHost);
69              userTracker.setUserAgent(userAgent);
70  
71              UserTrackerUtil.update(userTracker);
72  
73              Iterator itr = userTrackerPaths.iterator();
74  
75              while (itr.hasNext()) {
76                  UserTrackerPath userTrackerPath = (UserTrackerPath)itr.next();
77  
78                  long pathId = CounterLocalServiceUtil.increment(
79                      UserTrackerPath.class.getName());
80  
81                  userTrackerPath.setUserTrackerPathId(pathId);
82                  userTrackerPath.setUserTrackerId(userTrackerId);
83  
84                  UserTrackerPathUtil.update(userTrackerPath);
85              }
86  
87              return userTracker;
88          }
89          else {
90              return null;
91          }
92      }
93  
94      public void deleteUserTracker(long userTrackerId)
95          throws PortalException, SystemException {
96  
97          // Paths
98  
99          UserTrackerPathUtil.removeByUserTrackerId(userTrackerId);
100 
101         // User tracker
102 
103         UserTrackerUtil.remove(userTrackerId);
104     }
105 
106     public List getUserTrackers(long companyId, int begin, int end)
107         throws SystemException {
108 
109         return UserTrackerUtil.findByCompanyId(companyId, begin, end);
110     }
111 
112 }