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