1
22
23 package com.liferay.portlet.blogs.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.util.OrderByComparator;
28 import com.liferay.portal.model.Group;
29 import com.liferay.portlet.blogs.model.BlogsStatsUser;
30 import com.liferay.portlet.blogs.service.base.BlogsStatsUserLocalServiceBaseImpl;
31
32 import java.util.Date;
33 import java.util.List;
34
35
42 public class BlogsStatsUserLocalServiceImpl
43 extends BlogsStatsUserLocalServiceBaseImpl {
44
45 public void deleteStatsUserByGroupId(long groupId)
46 throws SystemException {
47
48 blogsStatsUserPersistence.removeByGroupId(groupId);
49 }
50
51 public void deleteStatsUserByUserId(long userId) throws SystemException {
52 blogsStatsUserPersistence.removeByUserId(userId);
53 }
54
55 public List<BlogsStatsUser> getCompanyStatsUsers(
56 long companyId, int begin, int end, OrderByComparator obc)
57 throws SystemException {
58
59 return blogsStatsUserPersistence.findByC_E(
60 companyId, 0, begin, end, obc);
61 }
62
63 public int getCompanyStatsUsersCount(long companyId)
64 throws SystemException {
65
66 return blogsStatsUserPersistence.countByC_E(companyId, 0);
67 }
68
69 public List<BlogsStatsUser> getGroupStatsUsers(
70 long groupId, int begin, int end, OrderByComparator obc)
71 throws SystemException {
72
73 return blogsStatsUserPersistence.findByG_E(groupId, 0, begin, end, obc);
74 }
75
76 public int getGroupStatsUsersCount(long groupId) throws SystemException {
77 return blogsStatsUserPersistence.countByG_E(groupId, 0);
78 }
79
80 public List<BlogsStatsUser> getOrganizationStatsUsers(
81 long organizationId, int begin, int end, OrderByComparator obc)
82 throws SystemException {
83
84 return blogsStatsUserFinder.findByOrganizationId(
85 organizationId, begin, end, obc);
86 }
87
88 public int getOrganizationStatsUsersCount(long organizationId)
89 throws SystemException {
90
91 return blogsStatsUserFinder.countByOrganizationId(organizationId);
92 }
93
94 public BlogsStatsUser getStatsUser(long groupId, long userId)
95 throws PortalException, SystemException {
96
97 BlogsStatsUser statsUser = blogsStatsUserPersistence.fetchByG_U(
98 groupId, userId);
99
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, false);
112 }
113
114 return statsUser;
115 }
116
117 public void updateStatsUser(long groupId, long userId, Date lastPostDate)
118 throws PortalException, SystemException {
119
120 int entryCount = blogsEntryPersistence.countByG_U(groupId, userId);
121
122 BlogsStatsUser statsUser = getStatsUser(groupId, userId);
123
124 statsUser.setEntryCount(entryCount);
125 statsUser.setLastPostDate(lastPostDate);
126
127 blogsStatsUserPersistence.update(statsUser, false);
128 }
129
130 }