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