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