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
49 public class GroupServiceImpl extends GroupServiceBaseImpl {
50
51 public Group addGroup(
52 String name, String description, int type, String friendlyURL,
53 boolean active, ServiceContext serviceContext)
54 throws PortalException, SystemException {
55
56 PortalPermissionUtil.check(
57 getPermissionChecker(), ActionKeys.ADD_COMMUNITY);
58
59 return groupLocalService.addGroup(
60 getUserId(), null, 0, name, description, type, friendlyURL, active,
61 serviceContext);
62 }
63
64 public Group addGroup(
65 long liveGroupId, String name, String description, int type,
66 String friendlyURL, boolean active, ServiceContext serviceContext)
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, serviceContext);
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(String actionId, int max)
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, max);
115 }
116
117 List<Group> groups = userPersistence.getGroups(
118 permissionChecker.getUserId(), 0, max);
119
120 groups = ListUtil.copy(groups);
121
122 Iterator<Group> itr = groups.iterator();
123
124 while (itr.hasNext()) {
125 Group group = itr.next();
126
127 if (!GroupPermissionUtil.contains(
128 permissionChecker, group.getGroupId(), actionId)) {
129
130 itr.remove();
131 }
132 }
133
134 return groups;
135 }
136
137 public List<Group> getOrganizationsGroups(
138 List<Organization> organizations) {
139
140 return groupLocalService.getOrganizationsGroups(organizations);
141 }
142
143 public Group getUserGroup(long companyId, long userId)
144 throws PortalException, SystemException {
145
146 return groupLocalService.getUserGroup(companyId, userId);
147 }
148
149 public List<Group> getUserGroupsGroups(List<UserGroup> userGroups) {
150 return groupLocalService.getUserGroupsGroups(userGroups);
151 }
152
153 public List<Group> getUserOrganizationsGroups(
154 long userId, int start, int end)
155 throws PortalException, SystemException {
156
157 return groupLocalService.getUserOrganizationsGroups(userId, start, end);
158 }
159
160 public boolean hasUserGroup(long userId, long groupId)
161 throws SystemException {
162
163 return groupLocalService.hasUserGroup(userId, groupId);
164 }
165
166 public List<Group> search(
167 long companyId, String name, String description, String[] params,
168 int start, int end)
169 throws SystemException {
170
171 LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
172 params);
173
174 return groupLocalService.search(
175 companyId, name, description, paramsObj, start, end);
176 }
177
178 public int searchCount(
179 long companyId, String name, String description, String[] params)
180 throws SystemException {
181
182 LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
183 params);
184
185 return groupLocalService.searchCount(
186 companyId, name, description, paramsObj);
187 }
188
189 public void setRoleGroups(long roleId, long[] groupIds)
190 throws PortalException, SystemException {
191
192 RolePermissionUtil.check(
193 getPermissionChecker(), roleId, ActionKeys.UPDATE);
194
195 groupLocalService.setRoleGroups(roleId, groupIds);
196 }
197
198 public void unsetRoleGroups(long roleId, long[] groupIds)
199 throws PortalException, SystemException {
200
201 RolePermissionUtil.check(
202 getPermissionChecker(), roleId, ActionKeys.UPDATE);
203
204 groupLocalService.unsetRoleGroups(roleId, groupIds);
205 }
206
207 public Group updateFriendlyURL(long groupId, String friendlyURL)
208 throws PortalException, SystemException {
209
210 GroupPermissionUtil.check(
211 getPermissionChecker(), groupId, ActionKeys.UPDATE);
212
213 return groupLocalService.updateFriendlyURL(groupId, friendlyURL);
214 }
215
216 public Group updateGroup(
217 long groupId, String name, String description, int type,
218 String friendlyURL, boolean active, ServiceContext serviceContext)
219 throws PortalException, SystemException {
220
221 GroupPermissionUtil.check(
222 getPermissionChecker(), groupId, ActionKeys.UPDATE);
223
224 return groupLocalService.updateGroup(
225 groupId, name, description, type, friendlyURL, active,
226 serviceContext);
227 }
228
229 public Group updateGroup(long groupId, String typeSettings)
230 throws PortalException, SystemException {
231
232 GroupPermissionUtil.check(
233 getPermissionChecker(), groupId, ActionKeys.UPDATE);
234
235 return groupLocalService.updateGroup(groupId, typeSettings);
236 }
237
238 public Group updateWorkflow(
239 long groupId, boolean workflowEnabled, int workflowStages,
240 String workflowRoleNames)
241 throws PortalException, SystemException {
242
243 GroupPermissionUtil.check(
244 getPermissionChecker(), groupId, ActionKeys.MANAGE_STAGING);
245
246 return groupLocalService.updateWorkflow(
247 groupId, workflowEnabled, workflowStages, workflowRoleNames);
248 }
249
250 }