1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * 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   */
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  /**
41   * <a href="MBThreadServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Jorge Ferrer
44   * @author Deepak Gothe
45   * @author Mika Koivisto
46   */
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 }