1
22
23 package com.liferay.portal.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.kernel.util.MapUtil;
29 import com.liferay.portal.model.Group;
30 import com.liferay.portal.model.Organization;
31 import com.liferay.portal.model.UserGroup;
32 import com.liferay.portal.security.permission.ActionKeys;
33 import com.liferay.portal.security.permission.PermissionChecker;
34 import com.liferay.portal.service.ServiceContext;
35 import com.liferay.portal.service.base.GroupServiceBaseImpl;
36 import com.liferay.portal.service.permission.GroupPermissionUtil;
37 import com.liferay.portal.service.permission.PortalPermissionUtil;
38 import com.liferay.portal.service.permission.RolePermissionUtil;
39
40 import java.util.Iterator;
41 import java.util.LinkedHashMap;
42 import java.util.List;
43
44
50 public class GroupServiceImpl extends GroupServiceBaseImpl {
51
52 public Group addGroup(
53 String name, String description, int type, String friendlyURL,
54 boolean active, ServiceContext serviceContext)
55 throws PortalException, SystemException {
56
57 PortalPermissionUtil.check(
58 getPermissionChecker(), ActionKeys.ADD_COMMUNITY);
59
60 return groupLocalService.addGroup(
61 getUserId(), null, 0, name, description, type, friendlyURL, active,
62 serviceContext);
63 }
64
65 public Group addGroup(
66 long liveGroupId, String name, String description, int type,
67 String friendlyURL, boolean active, ServiceContext serviceContext)
68 throws PortalException, SystemException {
69
70 GroupPermissionUtil.check(
71 getPermissionChecker(), liveGroupId, ActionKeys.UPDATE);
72
73 return groupLocalService.addGroup(
74 getUserId(), null, 0, liveGroupId, name, description, type,
75 friendlyURL, active, serviceContext);
76 }
77
78 public void addRoleGroups(long roleId, long[] groupIds)
79 throws PortalException, SystemException {
80
81 RolePermissionUtil.check(
82 getPermissionChecker(), roleId, ActionKeys.UPDATE);
83
84 groupLocalService.addRoleGroups(roleId, groupIds);
85 }
86
87 public void deleteGroup(long groupId)
88 throws PortalException, SystemException {
89
90 GroupPermissionUtil.check(
91 getPermissionChecker(), groupId, ActionKeys.DELETE);
92
93 groupLocalService.deleteGroup(groupId);
94 }
95
96 public Group getGroup(long groupId)
97 throws PortalException, SystemException {
98
99 return groupLocalService.getGroup(groupId);
100 }
101
102 public Group getGroup(long companyId, String name)
103 throws PortalException, SystemException {
104
105 return groupLocalService.getGroup(companyId, name);
106 }
107
108 public List<Group> getManageableGroups(String actionId, int max)
109 throws PortalException, SystemException {
110
111 PermissionChecker permissionChecker = getPermissionChecker();
112
113 if (permissionChecker.isCompanyAdmin()) {
114 return groupLocalService.search(
115 permissionChecker.getCompanyId(), null, null, null, 0, max);
116 }
117
118 List<Group> groups = userPersistence.getGroups(
119 permissionChecker.getUserId(), 0, max);
120
121 groups = ListUtil.copy(groups);
122
123 Iterator<Group> itr = groups.iterator();
124
125 while (itr.hasNext()) {
126 Group group = itr.next();
127
128 if (!GroupPermissionUtil.contains(
129 permissionChecker, group.getGroupId(), actionId)) {
130
131 itr.remove();
132 }
133 }
134
135 return groups;
136 }
137
138 public List<Group> getOrganizationsGroups(
139 List<Organization> organizations) {
140
141 return groupLocalService.getOrganizationsGroups(organizations);
142 }
143
144 public Group getUserGroup(long companyId, long userId)
145 throws PortalException, SystemException {
146
147 return groupLocalService.getUserGroup(companyId, userId);
148 }
149
150 public List<Group> getUserGroupsGroups(List<UserGroup> userGroups) {
151 return groupLocalService.getUserGroupsGroups(userGroups);
152 }
153
154 public List<Group> getUserOrganizationsGroups(
155 long userId, int start, int end)
156 throws PortalException, SystemException {
157
158 return groupLocalService.getUserOrganizationsGroups(userId, start, end);
159 }
160
161 public boolean hasUserGroup(long userId, long groupId)
162 throws SystemException {
163
164 return groupLocalService.hasUserGroup(userId, groupId);
165 }
166
167 public List<Group> search(
168 long companyId, String name, String description, String[] params,
169 int start, int end)
170 throws SystemException {
171
172 LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
173 params);
174
175 return groupLocalService.search(
176 companyId, name, description, paramsObj, start, end);
177 }
178
179 public int searchCount(
180 long companyId, String name, String description, String[] params)
181 throws SystemException {
182
183 LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
184 params);
185
186 return groupLocalService.searchCount(
187 companyId, name, description, paramsObj);
188 }
189
190 public void setRoleGroups(long roleId, long[] groupIds)
191 throws PortalException, SystemException {
192
193 RolePermissionUtil.check(
194 getPermissionChecker(), roleId, ActionKeys.UPDATE);
195
196 groupLocalService.setRoleGroups(roleId, groupIds);
197 }
198
199 public void unsetRoleGroups(long roleId, long[] groupIds)
200 throws PortalException, SystemException {
201
202 RolePermissionUtil.check(
203 getPermissionChecker(), roleId, ActionKeys.UPDATE);
204
205 groupLocalService.unsetRoleGroups(roleId, groupIds);
206 }
207
208 public Group updateFriendlyURL(long groupId, String friendlyURL)
209 throws PortalException, SystemException {
210
211 GroupPermissionUtil.check(
212 getPermissionChecker(), groupId, ActionKeys.UPDATE);
213
214 return groupLocalService.updateFriendlyURL(groupId, friendlyURL);
215 }
216
217 public Group updateGroup(
218 long groupId, String name, String description, int type,
219 String friendlyURL, boolean active, ServiceContext serviceContext)
220 throws PortalException, SystemException {
221
222 GroupPermissionUtil.check(
223 getPermissionChecker(), groupId, ActionKeys.UPDATE);
224
225 return groupLocalService.updateGroup(
226 groupId, name, description, type, friendlyURL, active,
227 serviceContext);
228 }
229
230 public Group updateGroup(long groupId, String typeSettings)
231 throws PortalException, SystemException {
232
233 GroupPermissionUtil.check(
234 getPermissionChecker(), groupId, ActionKeys.UPDATE);
235
236 return groupLocalService.updateGroup(groupId, typeSettings);
237 }
238
239 public Group updateWorkflow(
240 long groupId, boolean workflowEnabled, int workflowStages,
241 String workflowRoleNames)
242 throws PortalException, SystemException {
243
244 GroupPermissionUtil.check(
245 getPermissionChecker(), groupId, ActionKeys.MANAGE_STAGING);
246
247 return groupLocalService.updateWorkflow(
248 groupId, workflowEnabled, workflowStages, workflowRoleNames);
249 }
250
251 }