001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.util.ArrayUtil;
021    import com.liferay.portal.kernel.util.ListUtil;
022    import com.liferay.portal.kernel.util.MapUtil;
023    import com.liferay.portal.model.Group;
024    import com.liferay.portal.model.GroupConstants;
025    import com.liferay.portal.model.Organization;
026    import com.liferay.portal.model.Portlet;
027    import com.liferay.portal.model.User;
028    import com.liferay.portal.model.UserGroup;
029    import com.liferay.portal.security.auth.PrincipalException;
030    import com.liferay.portal.security.permission.ActionKeys;
031    import com.liferay.portal.security.permission.PermissionChecker;
032    import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
033    import com.liferay.portal.service.ServiceContext;
034    import com.liferay.portal.service.base.GroupServiceBaseImpl;
035    import com.liferay.portal.service.permission.GroupPermissionUtil;
036    import com.liferay.portal.service.permission.PortalPermissionUtil;
037    import com.liferay.portal.service.permission.PortletPermissionUtil;
038    import com.liferay.portal.service.permission.RolePermissionUtil;
039    import com.liferay.portal.util.PropsValues;
040    import com.liferay.util.UniqueList;
041    
042    import java.util.ArrayList;
043    import java.util.Collection;
044    import java.util.Collections;
045    import java.util.Iterator;
046    import java.util.LinkedHashMap;
047    import java.util.List;
048    
049    /**
050     * The group remote service is responsible for accessing, creating, modifying
051     * and deleting groups. For more information on group services and Group, see
052     * {@link com.liferay.portal.service.impl.GroupLocalServiceImpl}.
053     *
054     * @author Brian Wing Shun Chan
055     */
056    public class GroupServiceImpl extends GroupServiceBaseImpl {
057    
058            /**
059             * Adds a group.
060             *
061             * @param  liveGroupId the primary key of the live group
062             * @param  name the entity's name
063             * @param  description the group's description (optionally
064             *         <code>null</code>)
065             * @param  type the group's type. For more information see {@link
066             *         com.liferay.portal.model.GroupConstants}
067             * @param  friendlyURL the group's friendlyURL (optionally
068             *         <code>null</code>)
069             * @param  site whether the group is to be associated with a main site
070             * @param  active whether the group is active
071             * @param  serviceContext the service context to be applied (optionally
072             *         <code>null</code>). Can specify the group's asset category IDs,
073             *         asset tag names, and whether the group is for staging
074             * @return the group
075             * @throws PortalException if the user did not have permission to add the
076             *         group, if a creator could not be found, if the group's
077             *         information was invalid, if a layout could not be found, or if a
078             *         valid friendly URL could not be created for the group
079             * @throws SystemException if a system exception occurred
080             */
081            public Group addGroup(
082                            long liveGroupId, String name, String description, int type,
083                            String friendlyURL, boolean site, boolean active,
084                            ServiceContext serviceContext)
085                    throws PortalException, SystemException {
086    
087                    GroupPermissionUtil.check(
088                            getPermissionChecker(), liveGroupId, ActionKeys.UPDATE);
089    
090                    return groupLocalService.addGroup(
091                            getUserId(), null, 0, liveGroupId, name, description, type,
092                            friendlyURL, site, active, serviceContext);
093            }
094    
095            /**
096             * Adds the group using the group default live group ID.
097             *
098             * @param  name the entity's name
099             * @param  description the group's description (optionally
100             *         <code>null</code>)
101             * @param  type the group's type. For more information see {@link
102             *         com.liferay.portal.model.GroupConstants}
103             * @param  friendlyURL the group's friendlyURL
104             * @param  site whether the group is to be associated with a main site
105             * @param  active whether the group is active
106             * @param  serviceContext the service context to be applied (optionally
107             *         <code>null</code>). Can specify the group's asset category IDs,
108             *         asset tag names, and whether the group is for staging
109             * @return the group
110             * @throws PortalException if the user did not have permission to add the
111             *         group, if a creator could not be found, if the group's
112             *         information was invalid, if a layout could not be found, or if a
113             *         valid friendly URL could not be created for the group
114             * @throws SystemException if a system exception occurred
115             */
116            public Group addGroup(
117                            String name, String description, int type, String friendlyURL,
118                            boolean site, boolean active, ServiceContext serviceContext)
119                    throws PortalException, SystemException {
120    
121                    PortalPermissionUtil.check(
122                            getPermissionChecker(), ActionKeys.ADD_COMMUNITY);
123    
124                    return groupLocalService.addGroup(
125                            getUserId(), null, 0, name, description, type, friendlyURL, site,
126                            active, serviceContext);
127            }
128    
129            /**
130             * Adds the groups to the role.
131             *
132             * @param  roleId the primary key of the role
133             * @param  groupIds the primary keys of the groups
134             * @throws PortalException if the user did not have permission to update the
135             *         role
136             * @throws SystemException if a system exception occurred
137             */
138            public void addRoleGroups(long roleId, long[] groupIds)
139                    throws PortalException, SystemException {
140    
141                    RolePermissionUtil.check(
142                            getPermissionChecker(), roleId, ActionKeys.UPDATE);
143    
144                    groupLocalService.addRoleGroups(roleId, groupIds);
145            }
146    
147            /**
148             * Deletes the group.
149             *
150             * <p>
151             * The group is unstaged and its assets and resources including layouts,
152             * membership requests, subscriptions, teams, blogs, bookmarks, calendar
153             * events, image gallery, journals, message boards, polls, shopping related
154             * entities, software catalog, and wikis are also deleted.
155             * </p>
156             *
157             * @param  groupId the primary key of the group
158             * @throws PortalException if the user did not have permission to delete the
159             *         group or its assets or resources, if a group with the primary key
160             *         could not be found, or if the group was a system group
161             * @throws SystemException if a system exception occurred
162             */
163            public void deleteGroup(long groupId)
164                    throws PortalException, SystemException {
165    
166                    GroupPermissionUtil.check(
167                            getPermissionChecker(), groupId, ActionKeys.DELETE);
168    
169                    groupLocalService.deleteGroup(groupId);
170            }
171    
172            /**
173             * Returns the group with the primary key.
174             *
175             * @param  groupId the primary key of the group
176             * @return the group with the primary key
177             * @throws PortalException if a group with the primary key could not be
178             *         found or if the current user did not have permission to view the
179             *         group
180             * @throws SystemException if a system exception occurred
181             */
182            public Group getGroup(long groupId)
183                    throws PortalException, SystemException {
184    
185                    GroupPermissionUtil.check(
186                            getPermissionChecker(), groupId, ActionKeys.VIEW);
187    
188                    return groupLocalService.getGroup(groupId);
189            }
190    
191            /**
192             * Returns the group with the name.
193             *
194             * @param  companyId the primary key of the company
195             * @param  name the group's name
196             * @return the group with the name
197             * @throws PortalException if a matching group could not be found or if the
198             *         current user did not have permission to view the group
199             * @throws SystemException if a system exception occurred
200             */
201            public Group getGroup(long companyId, String name)
202                    throws PortalException, SystemException {
203    
204                    Group group = groupLocalService.getGroup(companyId, name);
205    
206                    GroupPermissionUtil.check(
207                            getPermissionChecker(), group.getGroupId(), ActionKeys.VIEW);
208    
209                    return group;
210            }
211    
212            /**
213             * Returns a range of all the site groups for which the user has control
214             * panel access.
215             *
216             * @param  portlets the portlets to manage
217             * @param  max the upper bound of the range of groups to consider (not
218             *         inclusive)
219             * @return the range of site groups for which the user has control panel
220             *         access
221             * @throws PortalException if a portal exception occurred
222             * @throws SystemException if a system exception occurred
223             */
224            public List<Group> getManageableSites(Collection<Portlet> portlets, int max)
225                    throws PortalException, SystemException {
226    
227                    PermissionChecker permissionChecker = getPermissionChecker();
228    
229                    if (permissionChecker.isCompanyAdmin()) {
230                            LinkedHashMap<String, Object> params =
231                                    new LinkedHashMap<String, Object>();
232    
233                            params.put("site", Boolean.TRUE);
234    
235                            return groupLocalService.search(
236                                    permissionChecker.getCompanyId(), null, null, null, params, 0,
237                                    max);
238                    }
239    
240                    List<Group> groups = new UniqueList<Group>();
241    
242                    groups.addAll(
243                            userPersistence.getGroups(permissionChecker.getUserId(), 0, max));
244                    groups.addAll(
245                            getUserOrganizationsGroups(permissionChecker.getUserId(), 0, max));
246    
247                    Iterator<Group> itr = groups.iterator();
248    
249                    while (itr.hasNext()) {
250                            Group group = itr.next();
251    
252                            if (!group.isSite() ||
253                                    !PortletPermissionUtil.contains(
254                                            permissionChecker, group.getGroupId(), 0L, portlets,
255                                            ActionKeys.ACCESS_IN_CONTROL_PANEL)) {
256    
257                                    itr.remove();
258                            }
259                    }
260    
261                    return groups;
262            }
263    
264            /**
265             * Returns the groups associated with the organizations.
266             *
267             * @param  organizations the organizations
268             * @return the groups associated with the organizations
269             * @throws PortalException if a portal exception occurred
270             * @throws SystemException if a system exception occurred
271             */
272            public List<Group> getOrganizationsGroups(List<Organization> organizations)
273                    throws PortalException, SystemException {
274    
275                    List<Group> groups = groupLocalService.getOrganizationsGroups(
276                            organizations);
277    
278                    return filterGroups(groups);
279            }
280    
281            /**
282             * Returns the group associated with the user.
283             *
284             * @param  companyId the primary key of the company
285             * @param  userId the primary key of the user
286             * @return the group associated with the user
287             * @throws PortalException if a matching group could not be found or if the
288             *         current user did not have permission to view the group
289             * @throws SystemException if a system exception occurred
290             */
291            public Group getUserGroup(long companyId, long userId)
292                    throws PortalException, SystemException {
293    
294                    Group group = groupLocalService.getUserGroup(companyId, userId);
295    
296                    GroupPermissionUtil.check(
297                            getPermissionChecker(), group.getGroupId(), ActionKeys.VIEW);
298    
299                    return group;
300            }
301    
302            /**
303             * Returns the groups associated with the user groups.
304             *
305             * @param  userGroups the user groups
306             * @return the groups associated with the user groups
307             * @throws PortalException if any one of the user group's group could not be
308             *         found
309             * @throws SystemException if a system exception occurred
310             */
311            public List<Group> getUserGroupsGroups(List<UserGroup> userGroups)
312                    throws PortalException, SystemException {
313    
314                    List<Group> groups = groupLocalService.getUserGroupsGroups(userGroups);
315    
316                    return filterGroups(groups);
317            }
318    
319            /**
320             * Returns the range of all groups associated with the user's organization
321             * groups, including the ancestors of the organization groups, unless portal
322             * property <code>organizations.membership.strict</code> is set to
323             * <code>true</code>.
324             *
325             * <p>
326             * Useful when paginating results. Returns a maximum of <code>end -
327             * start</code> instances. <code>start</code> and <code>end</code> are not
328             * primary keys, they are indexes in the result set. Thus, <code>0</code>
329             * refers to the first result in the set. Setting both <code>start</code>
330             * and <code>end</code> to {@link
331             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
332             * result set.
333             * </p>
334             *
335             * @param  userId the primary key of the user
336             * @param  start the lower bound of the range of groups to consider
337             * @param  end the upper bound of the range of groups to consider (not
338             *         inclusive)
339             * @return the range of groups associated with the user's organizations
340             * @throws PortalException if a user with the primary key could not be found
341             *         or if another portal exception occurred
342             * @throws SystemException if a system exception occurred
343             */
344            public List<Group> getUserOrganizationsGroups(
345                            long userId, int start, int end)
346                    throws PortalException, SystemException {
347    
348                    List<Group> groups = groupLocalService.getUserOrganizationsGroups(
349                            userId, start, end);
350    
351                    return filterGroups(groups);
352            }
353    
354            /**
355             * Returns the guest or current user's layout set group, organization
356             * groups, inherited organization groups, and site groups.
357             *
358             * @return the user's layout set group, organization groups, and inherited
359             *         organization groups, and site groups
360             * @throws PortalException if a portal exception occurred
361             * @throws SystemException if a system exception occurred
362             */
363            public List<Group> getUserSites() throws PortalException, SystemException {
364                    return getUserPlaces(null, QueryUtil.ALL_POS);
365            }
366    
367            /**
368             * Returns the guest or current user's group &quot;places&quot; associated
369             * with the group entity class names, including the control panel group if
370             * the user is permitted to view the control panel.
371             *
372             * <p>
373             * <ul> <li> Class name &quot;User&quot; includes the user's layout set
374             * group. </li> <li> Class name &quot;Organization&quot; includes the user's
375             * immediate organization groups and inherited organization groups. </li>
376             * <li> Class name &quot;Group&quot; includes the user's immediate
377             * organization groups and site groups. </li> <li> A <code>classNames</code>
378             * value of <code>null</code> includes the user's layout set group,
379             * organization groups, inherited organization groups, and site groups.
380             * </li> </ul>
381             * </p>
382             *
383             * @param  classNames the group entity class names (optionally
384             *         <code>null</code>). For more information see {@link
385             *         #getUserPlaces(String[], int)}
386             * @param  max the maximum number of groups to return
387             * @return the user's group &quot;places&quot;
388             * @throws PortalException if a portal exception occurred
389             * @throws SystemException if a system exception occurred
390             */
391            public List<Group> getUserPlaces(String[] classNames, int max)
392                    throws PortalException, SystemException {
393    
394                    return getUserPlaces(getGuestOrUserId(), classNames, max);
395            }
396    
397            /**
398             * Returns the user's group &quot;places&quot; associated with the group
399             * entity class names, including the control panel group if the user is
400             * permitted to view the control panel.
401             *
402             * <p>
403             * <ul> <li> Class name &quot;User&quot; includes the user's layout set
404             * group. </li> <li> Class name &quot;Organization&quot; includes the user's
405             * immediate organization groups and inherited organization groups. </li>
406             * <li> Class name &quot;Group&quot; includes the user's immediate
407             * organization groups and site groups. </li> <li> A <code>classNames</code>
408             * value of <code>null</code> includes the user's layout set group,
409             * organization groups, inherited organization groups, and site groups.
410             * </li> </ul>
411             * </p>
412             *
413             * @param  userId the primary key of the user
414             * @param  classNames the group entity class names (optionally
415             *         <code>null</code>). For more information see {@link
416             *         #getUserPlaces(long, String[], int)}
417             * @param  max the maximum number of groups to return
418             * @return the user's group &quot;places&quot;
419             * @throws PortalException if a portal exception occurred
420             * @throws SystemException if a system exception occurred
421             */
422            public List<Group> getUserPlaces(long userId, String[] classNames, int max)
423                    throws PortalException, SystemException {
424    
425                    User user = userPersistence.fetchByPrimaryKey(userId);
426    
427                    if (user.isDefaultUser()) {
428                            return Collections.emptyList();
429                    }
430    
431                    List<Group> userPlaces = new UniqueList<Group>();
432    
433                    int start = QueryUtil.ALL_POS;
434                    int end = QueryUtil.ALL_POS;
435    
436                    if (max != QueryUtil.ALL_POS) {
437                            start = 0;
438                            end = max;
439                    }
440    
441                    if ((classNames == null) ||
442                            ArrayUtil.contains(classNames, Group.class.getName())) {
443    
444                            LinkedHashMap<String, Object> groupParams =
445                                    new LinkedHashMap<String, Object>();
446    
447                            groupParams.put("active", Boolean.TRUE);
448                            groupParams.put("usersGroups", new Long(userId));
449    
450                            userPlaces.addAll(
451                                    groupLocalService.search(
452                                            user.getCompanyId(), groupParams, start, end));
453                    }
454    
455                    if ((classNames == null) ||
456                            ArrayUtil.contains(classNames, Organization.class.getName())) {
457    
458                            LinkedHashMap<String, Object> organizationParams =
459                                    new LinkedHashMap<String, Object>();
460    
461                            organizationParams.put("usersOrgs", new Long(userId));
462    
463                            List<Organization> userOrgs = organizationLocalService.search(
464                                    user.getCompanyId(), organizationParams, start, end);
465    
466                            for (Organization organization : userOrgs) {
467                                    userPlaces.add(0, organization.getGroup());
468    
469                                    if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) {
470                                            for (Organization ancestorOrganization :
471                                                            organization.getAncestors()) {
472    
473                                                    userPlaces.add(0, ancestorOrganization.getGroup());
474                                            }
475                                    }
476                            }
477                    }
478    
479                    if ((classNames == null) ||
480                            ArrayUtil.contains(classNames, User.class.getName())) {
481    
482                            if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED ||
483                                    PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {
484    
485                                    Group userGroup = user.getGroup();
486    
487                                    userPlaces.add(0, userGroup);
488                            }
489                    }
490    
491                    PermissionChecker permissionChecker = getPermissionChecker();
492    
493                    if (permissionChecker.getUserId() != userId) {
494                            try {
495                                    permissionChecker = PermissionCheckerFactoryUtil.create(
496                                            user, true);
497                            }
498                            catch (Exception e) {
499                                    throw new PrincipalException(e);
500                            }
501                    }
502    
503                    if (PortalPermissionUtil.contains(
504                                    permissionChecker, ActionKeys.VIEW_CONTROL_PANEL)) {
505    
506                            Group controlPanelGroup = groupLocalService.getGroup(
507                                    user.getCompanyId(), GroupConstants.CONTROL_PANEL);
508    
509                            userPlaces.add(0, controlPanelGroup);
510                    }
511    
512                    if ((max != QueryUtil.ALL_POS) && (userPlaces.size() > max)) {
513                            userPlaces = ListUtil.subList(userPlaces, start, end);
514                    }
515    
516                    return Collections.unmodifiableList(userPlaces);
517            }
518    
519            /**
520             * Returns <code>true</code> if the user is associated with the group,
521             * including the user's inherited organizations and user groups. System and
522             * staged groups are not included.
523             *
524             * @param  userId the primary key of the user
525             * @param  groupId the primary key of the group
526             * @return <code>true</code> if the user is associated with the group;
527             *         <code>false</code> otherwise
528             * @throws SystemException if a system exception occurred
529             */
530            public boolean hasUserGroup(long userId, long groupId)
531                    throws SystemException {
532    
533                    return groupLocalService.hasUserGroup(userId, groupId);
534            }
535    
536            /**
537             * Returns a name ordered range of all the site groups and organization
538             * groups that match the name and description, optionally including the
539             * user's inherited organization groups and user groups. System and staged
540             * groups are not included.
541             *
542             * <p>
543             * Useful when paginating results. Returns a maximum of <code>end -
544             * start</code> instances. <code>start</code> and <code>end</code> are not
545             * primary keys, they are indexes in the result set. Thus, <code>0</code>
546             * refers to the first result in the set. Setting both <code>start</code>
547             * and <code>end</code> to {@link
548             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
549             * result set.
550             * </p>
551             *
552             * @param  companyId the primary key of the company
553             * @param  name the group's name (optionally <code>null</code>)
554             * @param  description the group's description (optionally
555             *         <code>null</code>)
556             * @param  params the finder params (optionally <code>null</code>). To
557             *         include the user's inherited organizations and user groups in the
558             *         search, add entries having &quot;usersGroups&quot; and
559             *         &quot;inherit&quot; as keys mapped to the the user's ID. For more
560             *         information see {@link
561             *         com.liferay.portal.service.persistence.GroupFinder}
562             * @param  start the lower bound of the range of groups to return
563             * @param  end the upper bound of the range of groups to return (not
564             *         inclusive)
565             * @return the matching groups ordered by name
566             * @throws PortalException if a portal exception occurred
567             * @throws SystemException if a system exception occurred
568             */
569            public List<Group> search(
570                            long companyId, String name, String description, String[] params,
571                            int start, int end)
572                    throws PortalException, SystemException {
573    
574                    LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
575                            params);
576    
577                    List<Group> groups = groupLocalService.search(
578                            companyId, name, description, paramsObj, start, end);
579    
580                    return filterGroups(groups);
581            }
582    
583            /**
584             * Returns the number of groups and organization groups that match the name
585             * and description, optionally including the user's inherited organizations
586             * and user groups. System and staged groups are not included.
587             *
588             * @param  companyId the primary key of the company
589             * @param  name the group's name (optionally <code>null</code>)
590             * @param  description the group's description (optionally
591             *         <code>null</code>)
592             * @param  params the finder params (optionally <code>null</code>). To
593             *         include the user's inherited organizations and user groups in the
594             *         search, add entries having &quot;usersGroups&quot; and
595             *         &quot;inherit&quot; as keys mapped to the the user's ID. For more
596             *         information see {@link
597             *         com.liferay.portal.service.persistence.GroupFinder}
598             * @return the number of matching groups
599             * @throws SystemException if a system exception occurred
600             */
601            public int searchCount(
602                            long companyId, String name, String description, String[] params)
603                    throws SystemException {
604    
605                    LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
606                            params);
607    
608                    return groupLocalService.searchCount(
609                            companyId, name, description, paramsObj);
610            }
611    
612            /**
613             * Sets the groups associated with the role, removing and adding
614             * associations as necessary.
615             *
616             * @param  roleId the primary key of the role
617             * @param  groupIds the primary keys of the groups
618             * @throws PortalException if the user did not have permission to update
619             *         update the role
620             * @throws SystemException if a system exception occurred
621             */
622            public void setRoleGroups(long roleId, long[] groupIds)
623                    throws PortalException, SystemException {
624    
625                    RolePermissionUtil.check(
626                            getPermissionChecker(), roleId, ActionKeys.UPDATE);
627    
628                    groupLocalService.setRoleGroups(roleId, groupIds);
629            }
630    
631            /**
632             * Removes the groups from the role.
633             *
634             * @param  roleId the primary key of the role
635             * @param  groupIds the primary keys of the groups
636             * @throws PortalException if the user did not have permission to update the
637             *         role
638             * @throws SystemException if a system exception occurred
639             */
640            public void unsetRoleGroups(long roleId, long[] groupIds)
641                    throws PortalException, SystemException {
642    
643                    RolePermissionUtil.check(
644                            getPermissionChecker(), roleId, ActionKeys.UPDATE);
645    
646                    groupLocalService.unsetRoleGroups(roleId, groupIds);
647            }
648    
649            /**
650             * Updates the group's friendly URL.
651             *
652             * @param  groupId the primary key of the group
653             * @param  friendlyURL the group's new friendlyURL (optionally
654             *         <code>null</code>)
655             * @return the group
656             * @throws PortalException if the user did not have permission to update the
657             *         group, if a group with the primary key could not be found, or if
658             *         a valid friendly URL could not be created for the group
659             * @throws SystemException if a system exception occurred
660             */
661            public Group updateFriendlyURL(long groupId, String friendlyURL)
662                    throws PortalException, SystemException {
663    
664                    GroupPermissionUtil.check(
665                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
666    
667                    return groupLocalService.updateFriendlyURL(groupId, friendlyURL);
668            }
669    
670            /**
671             * Updates the group's type settings.
672             *
673             * @param  groupId the primary key of the group
674             * @param  typeSettings the group's new type settings (optionally
675             *         <code>null</code>)
676             * @return the group
677             * @throws PortalException if the user did not have permission to update the
678             *         group or if a group with the primary key could not be found
679             * @throws SystemException if a system exception occurred
680             */
681            public Group updateGroup(long groupId, String typeSettings)
682                    throws PortalException, SystemException {
683    
684                    GroupPermissionUtil.check(
685                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
686    
687                    return groupLocalService.updateGroup(groupId, typeSettings);
688            }
689    
690            /**
691             * Updates the group.
692             *
693             * @param  groupId the primary key of the group
694             * @param  name the group's new name
695             * @param  description the group's new description (optionally
696             *         <code>null</code>)
697             * @param  type the group's new type. For more information see {@link
698             *         com.liferay.portal.model.GroupConstants}
699             * @param  friendlyURL the group's new friendlyURL (optionally
700             *         <code>null</code>)
701             * @param  active whether the group is active
702             * @param  serviceContext the service context to be applied (optionally
703             *         <code>null</code>). Can specify the group's replacement asset
704             *         category IDs and replacement asset tag names
705             * @return the group
706             * @throws PortalException if the user did not have permission to update the
707             *         group, if a group with the primary key could not be found, if the
708             *         friendly URL was invalid or could one not be created
709             * @throws SystemException if a system exception occurred
710             */
711            public Group updateGroup(
712                            long groupId, String name, String description, int type,
713                            String friendlyURL, boolean active, ServiceContext serviceContext)
714                    throws PortalException, SystemException {
715    
716                    GroupPermissionUtil.check(
717                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
718    
719                    return groupLocalService.updateGroup(
720                            groupId, name, description, type, friendlyURL, active,
721                            serviceContext);
722            }
723    
724            protected List<Group> filterGroups(List<Group> groups)
725                    throws PortalException, SystemException {
726    
727                    List<Group> filteredGroups = new ArrayList<Group>();
728    
729                    for (Group group : groups) {
730                            if (GroupPermissionUtil.contains(
731                                            getPermissionChecker(), group.getGroupId(),
732                                            ActionKeys.VIEW)) {
733    
734                                    filteredGroups.add(group);
735                            }
736                    }
737    
738                    return filteredGroups;
739            }
740    
741    }