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