1   /**
2    * Copyright (c) 2000-2008 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.portal.NoSuchUserException;
26  import com.liferay.portal.PortalException;
27  import com.liferay.portal.SystemException;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.model.ActivityTracker;
30  import com.liferay.portal.model.User;
31  import com.liferay.portal.service.base.ActivityTrackerLocalServiceBaseImpl;
32  import com.liferay.portal.util.PortalUtil;
33  
34  import java.util.Date;
35  import java.util.List;
36  
37  import org.apache.commons.logging.Log;
38  import org.apache.commons.logging.LogFactory;
39  
40  /**
41   * <a href="ActivityTrackerLocalServiceImpl.java.html"><b><i>View Source</i></b>
42   * </a>
43   *
44   * @author Brian Wing Shun Chan
45   *
46   */
47  public class ActivityTrackerLocalServiceImpl
48      extends ActivityTrackerLocalServiceBaseImpl {
49  
50      public ActivityTracker addActivityTracker(
51              long userId, long groupId, String className, long classPK,
52              String activity, String extraData, long receiverUserId)
53          throws PortalException, SystemException {
54  
55          User user = userPersistence.findByPrimaryKey(userId);
56          long classNameId = PortalUtil.getClassNameId(className);
57  
58          String receiverUserName = StringPool.BLANK;
59  
60          if (receiverUserId > 0) {
61              try {
62                  User receiverUser = userPersistence.findByPrimaryKey(
63                      receiverUserId);
64  
65                  receiverUserName = receiverUser.getFullName();
66              }
67              catch (NoSuchUserException nsue) {
68                  if (_log.isWarnEnabled()) {
69                      _log.warn(nsue);
70                  }
71              }
72          }
73  
74          long activityTrackerId = counterLocalService.increment(
75              ActivityTracker.class.getName());
76  
77          ActivityTracker activityTracker = activityTrackerPersistence.create(
78              activityTrackerId);
79  
80          activityTracker.setGroupId(groupId);
81          activityTracker.setCompanyId(user.getCompanyId());
82          activityTracker.setUserId(user.getUserId());
83          activityTracker.setUserName(user.getFullName());
84          activityTracker.setCreateDate(new Date());
85          activityTracker.setClassNameId(classNameId);
86          activityTracker.setClassPK(classPK);
87          activityTracker.setActivity(activity);
88          activityTracker.setExtraData(extraData);
89          activityTracker.setReceiverUserId(receiverUserId);
90          activityTracker.setReceiverUserName(receiverUserName);
91  
92          activityTrackerPersistence.update(activityTracker);
93  
94          return activityTracker;
95      }
96  
97      public void deleteActivityTrackers(String className, long classPK)
98          throws SystemException {
99  
100         long classNameId = PortalUtil.getClassNameId(className);
101 
102         activityTrackerPersistence.removeByC_C(classNameId, classPK);
103     }
104 
105     public List getCompanyActivityTrackers(long companyId, int begin, int end)
106         throws SystemException {
107 
108         return activityTrackerPersistence.findByCompanyId(
109             companyId, begin, end);
110     }
111 
112     public int getCompanyActivityTrackersCount(long companyId)
113         throws SystemException {
114 
115         return activityTrackerPersistence.countByCompanyId(companyId);
116     }
117 
118     public List getGroupActivityTrackers(long groupId, int begin, int end)
119         throws SystemException {
120 
121         return activityTrackerPersistence.findByGroupId(groupId, begin, end);
122     }
123 
124     public int getGroupActivityTrackersCount(long groupId)
125         throws SystemException {
126 
127         return activityTrackerPersistence.countByGroupId(groupId);
128     }
129 
130     public List getUserActivityTrackers(long userId, int begin, int end)
131         throws SystemException {
132 
133         return activityTrackerFinder.findByU_R(userId, userId, begin, end);
134     }
135 
136     public int getUserActivityTrackersCount(long userId)
137         throws SystemException {
138 
139         return activityTrackerFinder.countByU_R(userId, userId);
140     }
141 
142     private static Log _log =
143         LogFactory.getLog(ActivityTrackerLocalServiceImpl.class);
144 
145 }