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