001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.impl;
022:
023: import com.liferay.portal.NoSuchUserException;
024: import com.liferay.portal.PortalException;
025: import com.liferay.portal.SystemException;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.model.ActivityTracker;
028: import com.liferay.portal.model.User;
029: import com.liferay.portal.service.base.ActivityTrackerLocalServiceBaseImpl;
030: import com.liferay.portal.util.PortalUtil;
031:
032: import java.util.Date;
033: import java.util.List;
034:
035: import org.apache.commons.logging.Log;
036: import org.apache.commons.logging.LogFactory;
037:
038: /**
039: * <a href="ActivityTrackerLocalServiceImpl.java.html"><b><i>View Source</i></b>
040: * </a>
041: *
042: * @author Brian Wing Shun Chan
043: *
044: */
045: public class ActivityTrackerLocalServiceImpl extends
046: ActivityTrackerLocalServiceBaseImpl {
047:
048: public ActivityTracker addActivityTracker(long userId,
049: long groupId, String className, long classPK,
050: String activity, String extraData, long receiverUserId)
051: throws PortalException, SystemException {
052:
053: User user = userPersistence.findByPrimaryKey(userId);
054: long classNameId = PortalUtil.getClassNameId(className);
055:
056: String receiverUserName = StringPool.BLANK;
057:
058: if (receiverUserId > 0) {
059: try {
060: User receiverUser = userPersistence
061: .findByPrimaryKey(receiverUserId);
062:
063: receiverUserName = receiverUser.getFullName();
064: } catch (NoSuchUserException nsue) {
065: if (_log.isWarnEnabled()) {
066: _log.warn(nsue);
067: }
068: }
069: }
070:
071: long activityTrackerId = counterLocalService
072: .increment(ActivityTracker.class.getName());
073:
074: ActivityTracker activityTracker = activityTrackerPersistence
075: .create(activityTrackerId);
076:
077: activityTracker.setGroupId(groupId);
078: activityTracker.setCompanyId(user.getCompanyId());
079: activityTracker.setUserId(user.getUserId());
080: activityTracker.setUserName(user.getFullName());
081: activityTracker.setCreateDate(new Date());
082: activityTracker.setClassNameId(classNameId);
083: activityTracker.setClassPK(classPK);
084: activityTracker.setActivity(activity);
085: activityTracker.setExtraData(extraData);
086: activityTracker.setReceiverUserId(receiverUserId);
087: activityTracker.setReceiverUserName(receiverUserName);
088:
089: activityTrackerPersistence.update(activityTracker);
090:
091: return activityTracker;
092: }
093:
094: public void deleteActivityTrackers(String className, long classPK)
095: throws SystemException {
096:
097: long classNameId = PortalUtil.getClassNameId(className);
098:
099: activityTrackerPersistence.removeByC_C(classNameId, classPK);
100: }
101:
102: public List getCompanyActivityTrackers(long companyId, int begin,
103: int end) throws SystemException {
104:
105: return activityTrackerPersistence.findByCompanyId(companyId,
106: begin, end);
107: }
108:
109: public int getCompanyActivityTrackersCount(long companyId)
110: throws SystemException {
111:
112: return activityTrackerPersistence.countByCompanyId(companyId);
113: }
114:
115: public List getGroupActivityTrackers(long groupId, int begin,
116: int end) throws SystemException {
117:
118: return activityTrackerPersistence.findByGroupId(groupId, begin,
119: end);
120: }
121:
122: public int getGroupActivityTrackersCount(long groupId)
123: throws SystemException {
124:
125: return activityTrackerPersistence.countByGroupId(groupId);
126: }
127:
128: public List getUserActivityTrackers(long userId, int begin, int end)
129: throws SystemException {
130:
131: return activityTrackerFinder.findByU_R(userId, userId, begin,
132: end);
133: }
134:
135: public int getUserActivityTrackersCount(long userId)
136: throws SystemException {
137:
138: return activityTrackerFinder.countByU_R(userId, userId);
139: }
140:
141: private static Log _log = LogFactory
142: .getLog(ActivityTrackerLocalServiceImpl.class);
143:
144: }
|