1
22
23 package com.liferay.portlet.messageboards.service.impl;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.log.Log;
27 import com.liferay.portal.kernel.log.LogFactoryUtil;
28 import com.liferay.portlet.messageboards.model.MBStatsUser;
29 import com.liferay.portlet.messageboards.service.base.MBStatsUserLocalServiceBaseImpl;
30
31 import java.util.Date;
32 import java.util.List;
33
34
40 public class MBStatsUserLocalServiceImpl
41 extends MBStatsUserLocalServiceBaseImpl {
42
43 public MBStatsUser addStatsUser(long groupId, long userId)
44 throws SystemException {
45
46 long statsUserId = counterLocalService.increment();
47
48 MBStatsUser statsUser = mbStatsUserPersistence.create(statsUserId);
49
50 statsUser.setGroupId(groupId);
51 statsUser.setUserId(userId);
52
53 try {
54 mbStatsUserPersistence.update(statsUser, false);
55 }
56 catch (SystemException se) {
57 if (_log.isWarnEnabled()) {
58 _log.warn(
59 "Add failed, fetch {groupId=" + groupId + ", userId=" +
60 userId + "}");
61 }
62
63 statsUser = mbStatsUserPersistence.fetchByG_U(
64 groupId, userId, false);
65
66 if (statsUser == null) {
67 throw se;
68 }
69 }
70
71 return statsUser;
72 }
73
74 public void deleteStatsUserByGroupId(long groupId)
75 throws SystemException {
76
77 mbStatsUserPersistence.removeByGroupId(groupId);
78 }
79
80 public void deleteStatsUserByUserId(long userId) throws SystemException {
81 mbStatsUserPersistence.removeByUserId(userId);
82 }
83
84 public MBStatsUser getStatsUser(long groupId, long userId)
85 throws SystemException {
86
87 MBStatsUser statsUser = mbStatsUserPersistence.fetchByG_U(
88 groupId, userId);
89
90 if (statsUser == null) {
91 statsUser = mbStatsUserLocalService.addStatsUser(groupId, userId);
92 }
93
94 return statsUser;
95 }
96
97 public List<MBStatsUser> getStatsUsers(long groupId, int start, int end)
98 throws SystemException {
99
100 return mbStatsUserPersistence.findByG_M(groupId, 0, start, end);
101 }
102
103 public int getStatsUsersCount(long groupId) throws SystemException {
104 return mbStatsUserPersistence.countByG_M(groupId, 0);
105 }
106
107 public MBStatsUser updateStatsUser(long groupId, long userId)
108 throws SystemException {
109
110 return updateStatsUser(groupId, userId, null);
111 }
112
113 public MBStatsUser updateStatsUser(
114 long groupId, long userId, Date lastPostDate)
115 throws SystemException {
116
117 int messageCount = mbMessagePersistence.countByG_U(groupId, userId);
118
119 MBStatsUser statsUser = getStatsUser(groupId, userId);
120
121 statsUser.setMessageCount(messageCount);
122
123 if (lastPostDate != null) {
124 statsUser.setLastPostDate(lastPostDate);
125 }
126
127 mbStatsUserPersistence.update(statsUser, false);
128
129 return statsUser;
130 }
131
132 private static Log _log =
133 LogFactoryUtil.getLog(MBStatsUserLocalServiceImpl.class);
134
135 }