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.kernel.util.ListUtil;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portlet.messageboards.model.MBCategory;
30  import com.liferay.portlet.messageboards.service.base.MBCategoryServiceBaseImpl;
31  import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
32  
33  import java.util.Iterator;
34  import java.util.List;
35  
36  /**
37   * <a href="MBCategoryServiceImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class MBCategoryServiceImpl extends MBCategoryServiceBaseImpl {
43  
44      public MBCategory addCategory(
45              long plid, long parentCategoryId, String name, String description,
46              boolean addCommunityPermissions, boolean addGuestPermissions)
47          throws PortalException, SystemException {
48  
49          MBCategoryPermission.check(
50              getPermissionChecker(), plid, parentCategoryId,
51              ActionKeys.ADD_CATEGORY);
52  
53          return mbCategoryLocalService.addCategory(
54              getUserId(), plid, parentCategoryId, name, description,
55              addCommunityPermissions, addGuestPermissions);
56      }
57  
58      public MBCategory addCategory(
59              long plid, long parentCategoryId, String name, String description,
60              String[] communityPermissions, String[] guestPermissions)
61          throws PortalException, SystemException {
62  
63          MBCategoryPermission.check(
64              getPermissionChecker(), plid, parentCategoryId,
65              ActionKeys.ADD_CATEGORY);
66  
67          return mbCategoryLocalService.addCategory(
68              getUserId(), plid, parentCategoryId, name, description,
69              communityPermissions, guestPermissions);
70      }
71  
72      public void deleteCategory(long categoryId)
73          throws PortalException, SystemException {
74  
75          MBCategoryPermission.check(
76              getPermissionChecker(), categoryId, ActionKeys.DELETE);
77  
78          mbCategoryLocalService.deleteCategory(categoryId);
79      }
80  
81      public MBCategory getCategory(long categoryId)
82          throws PortalException, SystemException {
83  
84          MBCategoryPermission.check(
85              getPermissionChecker(), categoryId, ActionKeys.VIEW);
86  
87          return mbCategoryLocalService.getCategory(categoryId);
88      }
89  
90      public List<MBCategory> getCategories(
91              long groupId, long parentCategoryId, int start, int end)
92          throws PortalException, SystemException {
93  
94          List<MBCategory> categories = mbCategoryLocalService.getCategories(
95              groupId, parentCategoryId, start, end);
96  
97          categories = ListUtil.copy(categories);
98  
99          Iterator<MBCategory> itr = categories.iterator();
100 
101         while (itr.hasNext()) {
102             MBCategory category = itr.next();
103 
104             if (!MBCategoryPermission.contains(
105                     getPermissionChecker(), category, ActionKeys.VIEW)) {
106 
107                 itr.remove();
108             }
109         }
110 
111         return categories;
112     }
113 
114     public int getCategoriesCount(long groupId, long parentCategoryId)
115         throws SystemException {
116 
117         return mbCategoryLocalService.getCategoriesCount(
118             groupId, parentCategoryId);
119     }
120 
121     public void subscribeCategory(long categoryId)
122         throws PortalException, SystemException {
123 
124         MBCategoryPermission.check(
125             getPermissionChecker(), categoryId, ActionKeys.SUBSCRIBE);
126 
127         mbCategoryLocalService.subscribeCategory(getUserId(), categoryId);
128     }
129 
130     public void unsubscribeCategory(long categoryId)
131         throws PortalException, SystemException {
132 
133         MBCategoryPermission.check(
134             getPermissionChecker(), categoryId, ActionKeys.SUBSCRIBE);
135 
136         mbCategoryLocalService.unsubscribeCategory(getUserId(), categoryId);
137     }
138 
139     public MBCategory updateCategory(
140             long categoryId, long parentCategoryId, String name,
141             String description, boolean mergeWithParentCategory)
142         throws PortalException, SystemException {
143 
144         MBCategoryPermission.check(
145             getPermissionChecker(), categoryId, ActionKeys.UPDATE);
146 
147         return mbCategoryLocalService.updateCategory(
148             categoryId, parentCategoryId, name, description,
149             mergeWithParentCategory);
150     }
151 
152 }