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.portlet.blogs.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.OrderByComparator;
026: import com.liferay.portal.model.Group;
027: import com.liferay.portlet.blogs.model.BlogsStatsUser;
028: import com.liferay.portlet.blogs.service.base.BlogsStatsUserLocalServiceBaseImpl;
029:
030: import java.util.Date;
031: import java.util.List;
032:
033: /**
034: * <a href="BlogsStatsUserLocalServiceImpl.java.html"><b><i>View Source</i></b>
035: * </a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class BlogsStatsUserLocalServiceImpl extends
041: BlogsStatsUserLocalServiceBaseImpl {
042:
043: public void deleteStatsUserByGroupId(long groupId)
044: throws SystemException {
045:
046: blogsStatsUserPersistence.removeByGroupId(groupId);
047: }
048:
049: public void deleteStatsUserByUserId(long userId)
050: throws SystemException {
051: blogsStatsUserPersistence.removeByUserId(userId);
052: }
053:
054: public List getCompanyStatsUsers(long companyId, int begin,
055: int end, OrderByComparator obc) throws SystemException {
056:
057: return blogsStatsUserPersistence.findByC_E(companyId, 0, begin,
058: end, obc);
059: }
060:
061: public int getCompanyStatsUsersCount(long companyId)
062: throws SystemException {
063:
064: return blogsStatsUserPersistence.countByC_E(companyId, 0);
065: }
066:
067: public List getGroupStatsUsers(long groupId, int begin, int end,
068: OrderByComparator obc) throws SystemException {
069:
070: return blogsStatsUserPersistence.findByG_E(groupId, 0, begin,
071: end, obc);
072: }
073:
074: public int getGroupStatsUsersCount(long groupId)
075: throws SystemException {
076: return blogsStatsUserPersistence.countByG_E(groupId, 0);
077: }
078:
079: public List getOrganizationStatsUsers(long organizationId,
080: int begin, int end, OrderByComparator obc)
081: throws SystemException {
082:
083: return blogsStatsUserFinder.findByOrganizationId(
084: organizationId, begin, end, obc);
085: }
086:
087: public int getOrganizationStatsUsersCount(long organizationId)
088: throws SystemException {
089:
090: return blogsStatsUserFinder
091: .countByOrganizationId(organizationId);
092: }
093:
094: public BlogsStatsUser getStatsUser(long groupId, long userId)
095: throws PortalException, SystemException {
096:
097: BlogsStatsUser statsUser = blogsStatsUserPersistence
098: .fetchByG_U(groupId, userId);
099:
100: if (statsUser == null) {
101: Group group = groupPersistence.findByPrimaryKey(groupId);
102:
103: long statsUserId = counterLocalService.increment();
104:
105: statsUser = blogsStatsUserPersistence.create(statsUserId);
106:
107: statsUser.setCompanyId(group.getCompanyId());
108: statsUser.setGroupId(groupId);
109: statsUser.setUserId(userId);
110:
111: blogsStatsUserPersistence.update(statsUser);
112: }
113:
114: return statsUser;
115: }
116:
117: public void updateStatsUser(long groupId, long userId,
118: Date lastPostDate) throws PortalException, SystemException {
119:
120: int entryCount = blogsEntryPersistence.countByG_U(groupId,
121: userId);
122:
123: BlogsStatsUser statsUser = getStatsUser(groupId, userId);
124:
125: statsUser.setEntryCount(entryCount);
126: statsUser.setLastPostDate(lastPostDate);
127:
128: blogsStatsUserPersistence.update(statsUser);
129: }
130:
131: }
|