1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
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.security.permission.ActionKeys;
20  import com.liferay.portal.theme.ThemeDisplay;
21  import com.liferay.portlet.messageboards.model.MBMessage;
22  import com.liferay.portlet.messageboards.model.MBThread;
23  import com.liferay.portlet.messageboards.service.base.MBThreadServiceBaseImpl;
24  import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
25  import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
26  
27  import java.util.List;
28  
29  import javax.portlet.PortletPreferences;
30  
31  /**
32   * <a href="MBThreadServiceImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Jorge Ferrer
35   * @author Deepak Gothe
36   */
37  public class MBThreadServiceImpl extends MBThreadServiceBaseImpl {
38  
39      public void deleteThread(long threadId)
40          throws PortalException, SystemException {
41  
42          List<MBMessage> messages = mbMessagePersistence.findByThreadId(
43              threadId);
44  
45          for (MBMessage message : messages) {
46              MBMessagePermission.check(
47                  getPermissionChecker(), message.getMessageId(),
48                  ActionKeys.DELETE);
49          }
50  
51          mbThreadLocalService.deleteThread(threadId);
52      }
53  
54      public MBThread moveThread(long categoryId, long threadId)
55          throws PortalException, SystemException {
56  
57          MBThread thread = mbThreadLocalService.getThread(threadId);
58  
59          MBCategoryPermission.check(
60              getPermissionChecker(), thread.getCategoryId(),
61              ActionKeys.MOVE_THREAD);
62  
63          MBCategoryPermission.check(
64              getPermissionChecker(), categoryId, ActionKeys.MOVE_THREAD);
65  
66          return mbThreadLocalService.moveThread(categoryId, threadId);
67      }
68  
69      public MBThread splitThread(
70              long messageId, PortletPreferences prefs, ThemeDisplay themeDisplay)
71          throws PortalException, SystemException {
72  
73          MBMessage message = mbMessageLocalService.getMessage(messageId);
74  
75          MBCategoryPermission.check(
76              getPermissionChecker(), message.getCategoryId(),
77              ActionKeys.MOVE_THREAD);
78  
79          return mbThreadLocalService.splitThread(messageId, prefs, themeDisplay);
80      }
81  
82  }