01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.portlet.messageboards.service.impl;
22:
23: import com.liferay.portal.PortalException;
24: import com.liferay.portal.SystemException;
25: import com.liferay.portal.model.User;
26: import com.liferay.portlet.messageboards.model.MBMessage;
27: import com.liferay.portlet.messageboards.model.MBMessageFlag;
28: import com.liferay.portlet.messageboards.model.impl.MBMessageFlagImpl;
29: import com.liferay.portlet.messageboards.service.base.MBMessageFlagLocalServiceBaseImpl;
30:
31: import java.util.Iterator;
32: import java.util.List;
33:
34: /**
35: * <a href="MBMessageFlagLocalServiceImpl.java.html"><b><i>View Source</i></b>
36: * </a>
37: *
38: * @author Brian Wing Shun Chan
39: *
40: */
41: public class MBMessageFlagLocalServiceImpl extends
42: MBMessageFlagLocalServiceBaseImpl {
43:
44: public void addReadFlags(long userId, List messages)
45: throws PortalException, SystemException {
46:
47: User user = userPersistence.findByPrimaryKey(userId);
48:
49: if (user.isDefaultUser()) {
50: return;
51: }
52:
53: Iterator itr = messages.iterator();
54:
55: while (itr.hasNext()) {
56: MBMessage message = (MBMessage) itr.next();
57:
58: MBMessageFlag messageFlag = mbMessageFlagPersistence
59: .fetchByU_M(userId, message.getMessageId());
60:
61: if (messageFlag == null) {
62: long messageFlagId = counterLocalService.increment();
63:
64: messageFlag = mbMessageFlagPersistence
65: .create(messageFlagId);
66:
67: messageFlag.setUserId(userId);
68: messageFlag.setMessageId(message.getMessageId());
69: messageFlag.setFlag(MBMessageFlagImpl.READ_FLAG);
70:
71: mbMessageFlagPersistence.update(messageFlag);
72: }
73: }
74: }
75:
76: public void deleteFlags(long userId) throws SystemException {
77: mbMessageFlagPersistence.removeByUserId(userId);
78: }
79:
80: public boolean hasReadFlag(long userId, long messageId)
81: throws PortalException, SystemException {
82:
83: User user = userPersistence.findByPrimaryKey(userId);
84:
85: if (user.isDefaultUser()) {
86: return true;
87: }
88:
89: MBMessageFlag messageFlag = mbMessageFlagPersistence
90: .fetchByU_M(userId, messageId);
91:
92: if (messageFlag != null) {
93: return true;
94: } else {
95: return false;
96: }
97: }
98:
99: }
|