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