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