1   /**
2    * Copyright (c) 2000-2008 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.security.permission.ActionKeys;
28  import com.liferay.portlet.messageboards.model.MBCategory;
29  import com.liferay.portlet.messageboards.service.base.MBCategoryServiceBaseImpl;
30  import com.liferay.portlet.messageboards.service.permission.MBCategoryPermission;
31  
32  import java.util.ArrayList;
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              String[] communityPermissions, String[] guestPermissions)
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              communityPermissions, guestPermissions);
56      }
57  
58      public void deleteCategory(long categoryId)
59          throws PortalException, SystemException {
60  
61          MBCategoryPermission.check(
62              getPermissionChecker(), categoryId, ActionKeys.DELETE);
63  
64          mbCategoryLocalService.deleteCategory(categoryId);
65      }
66  
67      public MBCategory getCategory(long categoryId)
68          throws PortalException, SystemException {
69  
70          MBCategoryPermission.check(
71              getPermissionChecker(), categoryId, ActionKeys.VIEW);
72  
73          return mbCategoryLocalService.getCategory(categoryId);
74      }
75  
76      public List getCategories(
77              long groupId, long parentCategoryId, int begin, int end)
78          throws PortalException, SystemException {
79  
80          List categories = new ArrayList();
81  
82          Iterator itr = mbCategoryLocalService.getCategories(
83              groupId, parentCategoryId, begin, end).iterator();
84  
85          while (itr.hasNext()) {
86              MBCategory category = (MBCategory)itr.next();
87  
88              if (MBCategoryPermission.contains(
89                      getPermissionChecker(), category, ActionKeys.VIEW)) {
90  
91                  categories.add(category);
92              }
93          }
94  
95          return categories;
96      }
97  
98      public int getCategoriesCount(long groupId, long parentCategoryId)
99          throws SystemException {
100 
101         return mbCategoryLocalService.getCategoriesCount(
102             groupId, parentCategoryId);
103     }
104 
105     public void subscribeCategory(long categoryId)
106         throws PortalException, SystemException {
107 
108         MBCategoryPermission.check(
109             getPermissionChecker(), categoryId, ActionKeys.SUBSCRIBE);
110 
111         mbCategoryLocalService.subscribeCategory(getUserId(), categoryId);
112     }
113 
114     public void unsubscribeCategory(long categoryId)
115         throws PortalException, SystemException {
116 
117         MBCategoryPermission.check(
118             getPermissionChecker(), categoryId, ActionKeys.SUBSCRIBE);
119 
120         mbCategoryLocalService.unsubscribeCategory(getUserId(), categoryId);
121     }
122 
123     public MBCategory updateCategory(
124             long categoryId, long parentCategoryId, String name,
125             String description, boolean mergeWithParentCategory)
126         throws PortalException, SystemException {
127 
128         MBCategoryPermission.check(
129             getPermissionChecker(), categoryId, ActionKeys.UPDATE);
130 
131         return mbCategoryLocalService.updateCategory(
132             categoryId, parentCategoryId, name, description,
133             mergeWithParentCategory);
134     }
135 
136 }