1
14
15 package com.liferay.portlet.messageboards.service.impl;
16
17 import com.liferay.portal.PortalException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.model.Lock;
20 import com.liferay.portal.security.permission.ActionKeys;
21 import com.liferay.portal.service.ServiceContext;
22 import com.liferay.portlet.messageboards.LockedThreadException;
23 import com.liferay.portlet.messageboards.model.MBMessage;
24 import com.liferay.portlet.messageboards.model.MBThread;
25 import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
26 import com.liferay.portlet.messageboards.service.base.MBThreadServiceBaseImpl;
27 import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
28 import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
29
30 import java.util.List;
31
32
39 public class MBThreadServiceImpl extends MBThreadServiceBaseImpl {
40
41 public void deleteThread(long threadId)
42 throws PortalException, SystemException {
43
44 if (lockLocalService.isLocked(
45 MBThread.class.getName(), threadId)) {
46
47 throw new LockedThreadException();
48 }
49
50 List<MBMessage> messages = mbMessagePersistence.findByThreadId(
51 threadId);
52
53 for (MBMessage message : messages) {
54 MBMessagePermission.check(
55 getPermissionChecker(), message.getMessageId(),
56 ActionKeys.DELETE);
57 }
58
59 mbThreadLocalService.deleteThread(threadId);
60 }
61
62 public Lock lockThread(long threadId)
63 throws PortalException, SystemException {
64
65 MBThread thread = mbThreadLocalService.getThread(threadId);
66
67 MBCategoryPermission.check(
68 getPermissionChecker(), thread.getGroupId(), thread.getCategoryId(),
69 ActionKeys.LOCK_THREAD);
70
71 return lockLocalService.lock(
72 getUserId(), MBThread.class.getName(), threadId,
73 String.valueOf(threadId), false,
74 MBThreadModelImpl.LOCK_EXPIRATION_TIME);
75 }
76
77 public MBThread moveThread(long categoryId, long threadId)
78 throws PortalException, SystemException {
79
80 MBThread thread = mbThreadLocalService.getThread(threadId);
81
82 MBCategoryPermission.check(
83 getPermissionChecker(), thread.getCategoryId(),
84 ActionKeys.MOVE_THREAD);
85
86 MBCategoryPermission.check(
87 getPermissionChecker(), categoryId, ActionKeys.MOVE_THREAD);
88
89 return mbThreadLocalService.moveThread(categoryId, threadId);
90 }
91
92 public MBThread splitThread(long messageId, ServiceContext serviceContext)
93 throws PortalException, SystemException {
94
95 MBMessage message = mbMessageLocalService.getMessage(messageId);
96
97 MBCategoryPermission.check(
98 getPermissionChecker(), message.getCategoryId(),
99 ActionKeys.MOVE_THREAD);
100
101 return mbThreadLocalService.splitThread(messageId, serviceContext);
102 }
103
104 public void unlockThread(long threadId)
105 throws PortalException, SystemException {
106
107 MBThread thread = mbThreadLocalService.getThread(threadId);
108
109 MBCategoryPermission.check(
110 getPermissionChecker(), thread.getGroupId(), thread.getCategoryId(),
111 ActionKeys.LOCK_THREAD);
112
113 lockLocalService.unlock(MBThread.class.getName(), threadId);
114 }
115
116 }