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