1
22
23 package com.liferay.portlet.blogs.service.impl;
24
25 import com.liferay.counter.service.CounterLocalServiceUtil;
26 import com.liferay.portal.PortalException;
27 import com.liferay.portal.SystemException;
28 import com.liferay.portal.kernel.util.OrderByComparator;
29 import com.liferay.portal.model.Group;
30 import com.liferay.portal.service.persistence.GroupUtil;
31 import com.liferay.portlet.blogs.model.BlogsStatsUser;
32 import com.liferay.portlet.blogs.service.base.BlogsStatsUserLocalServiceBaseImpl;
33 import com.liferay.portlet.blogs.service.persistence.BlogsEntryUtil;
34 import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserFinder;
35 import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserUtil;
36
37 import java.util.Date;
38 import java.util.List;
39
40
46 public class BlogsStatsUserLocalServiceImpl
47 extends BlogsStatsUserLocalServiceBaseImpl {
48
49 public void deleteStatsUserByGroupId(long groupId)
50 throws SystemException {
51
52 BlogsStatsUserUtil.removeByGroupId(groupId);
53 }
54
55 public void deleteStatsUserByUserId(long userId) throws SystemException {
56 BlogsStatsUserUtil.removeByUserId(userId);
57 }
58
59 public List getCompanyStatsUsers(
60 long companyId, int begin, int end, OrderByComparator obc)
61 throws SystemException {
62
63 return BlogsStatsUserUtil.findByC_E(companyId, 0, begin, end, obc);
64 }
65
66 public int getCompanyStatsUsersCount(long companyId)
67 throws SystemException {
68
69 return BlogsStatsUserUtil.countByC_E(companyId, 0);
70 }
71
72 public List getGroupStatsUsers(
73 long groupId, int begin, int end, OrderByComparator obc)
74 throws SystemException {
75
76 return BlogsStatsUserUtil.findByG_E(groupId, 0, begin, end, obc);
77 }
78
79 public int getGroupStatsUsersCount(long groupId) throws SystemException {
80 return BlogsStatsUserUtil.countByG_E(groupId, 0);
81 }
82
83 public List getOrganizationStatsUsers(
84 long organizationId, int begin, int end, OrderByComparator obc)
85 throws SystemException {
86
87 return BlogsStatsUserFinder.findByOrganizationId(
88 organizationId, begin, end, obc);
89 }
90
91 public int getOrganizationStatsUsersCount(long organizationId)
92 throws SystemException {
93
94 return BlogsStatsUserFinder.countByOrganizationId(organizationId);
95 }
96
97 public BlogsStatsUser getStatsUser(long groupId, long userId)
98 throws PortalException, SystemException {
99
100 BlogsStatsUser statsUser = BlogsStatsUserUtil.fetchByG_U(
101 groupId, userId);
102
103 if (statsUser == null) {
104 Group group = GroupUtil.findByPrimaryKey(groupId);
105
106 long statsUserId = CounterLocalServiceUtil.increment();
107
108 statsUser = BlogsStatsUserUtil.create(statsUserId);
109
110 statsUser.setCompanyId(group.getCompanyId());
111 statsUser.setGroupId(groupId);
112 statsUser.setUserId(userId);
113
114 BlogsStatsUserUtil.update(statsUser);
115 }
116
117 return statsUser;
118 }
119
120 public void updateStatsUser(long groupId, long userId, Date lastPostDate)
121 throws PortalException, SystemException {
122
123 int entryCount = BlogsEntryUtil.countByG_U(groupId, userId);
124
125 BlogsStatsUser statsUser = getStatsUser(groupId, userId);
126
127 statsUser.setEntryCount(entryCount);
128 statsUser.setLastPostDate(lastPostDate);
129
130 BlogsStatsUserUtil.update(statsUser);
131 }
132
133 }