1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.model.UserTracker;
25  import com.liferay.portal.model.UserTrackerPath;
26  import com.liferay.portal.service.base.UserTrackerLocalServiceBaseImpl;
27  import com.liferay.portal.util.PropsValues;
28  
29  import java.util.Date;
30  import java.util.Iterator;
31  import java.util.List;
32  
33  /**
34   * <a href="UserTrackerLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class UserTrackerLocalServiceImpl
40      extends UserTrackerLocalServiceBaseImpl {
41  
42      public UserTracker addUserTracker(
43              long companyId, long userId, Date modifiedDate, String sessionId,
44              String remoteAddr, String remoteHost, String userAgent,
45              List<UserTrackerPath> userTrackerPaths)
46          throws SystemException {
47  
48          if (PropsValues.SESSION_TRACKER_PERSISTENCE_ENABLED) {
49              long userTrackerId = counterLocalService.increment(
50                  UserTracker.class.getName());
51  
52              UserTracker userTracker =
53                  userTrackerPersistence.create(userTrackerId);
54  
55              userTracker.setCompanyId(companyId);
56              userTracker.setUserId(userId);
57              userTracker.setModifiedDate(modifiedDate);
58              userTracker.setSessionId(sessionId);
59              userTracker.setRemoteAddr(remoteAddr);
60              userTracker.setRemoteHost(remoteHost);
61              userTracker.setUserAgent(userAgent);
62  
63              userTrackerPersistence.update(userTracker, false);
64  
65              Iterator<UserTrackerPath> itr = userTrackerPaths.iterator();
66  
67              while (itr.hasNext()) {
68                  UserTrackerPath userTrackerPath = itr.next();
69  
70                  long pathId = counterLocalService.increment(
71                      UserTrackerPath.class.getName());
72  
73                  userTrackerPath.setUserTrackerPathId(pathId);
74                  userTrackerPath.setUserTrackerId(userTrackerId);
75  
76                  userTrackerPathPersistence.update(userTrackerPath, false);
77              }
78  
79              return userTracker;
80          }
81          else {
82              return null;
83          }
84      }
85  
86      public void deleteUserTracker(long userTrackerId)
87          throws PortalException, SystemException {
88  
89          // Paths
90  
91          userTrackerPathPersistence.removeByUserTrackerId(userTrackerId);
92  
93          // User tracker
94  
95          userTrackerPersistence.remove(userTrackerId);
96      }
97  
98      public List<UserTracker> getUserTrackers(long companyId, int start, int end)
99          throws SystemException {
100 
101         return userTrackerPersistence.findByCompanyId(companyId, start, end);
102     }
103 
104 }