001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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 set the asset category IDs and asset tag
073             *         names for the group, and can set 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 set asset category IDs and asset tag
108             *         names for the group, and can set 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            public List<Group> getUserPlaces(
355                            long userId, String[] classNames, boolean includeControlPanel,
356                            int max)
357                    throws PortalException, SystemException {
358    
359                    User user = userPersistence.fetchByPrimaryKey(userId);
360    
361                    if (user.isDefaultUser()) {
362                            return Collections.emptyList();
363                    }
364    
365                    List<Group> userPlaces = new UniqueList<Group>();
366    
367                    int start = QueryUtil.ALL_POS;
368                    int end = QueryUtil.ALL_POS;
369    
370                    if (max != QueryUtil.ALL_POS) {
371                            start = 0;
372                            end = max;
373                    }
374    
375                    if ((classNames == null) ||
376                            ArrayUtil.contains(classNames, Group.class.getName())) {
377    
378                            LinkedHashMap<String, Object> groupParams =
379                                    new LinkedHashMap<String, Object>();
380    
381                            groupParams.put("active", Boolean.TRUE);
382                            groupParams.put("usersGroups", new Long(userId));
383    
384                            userPlaces.addAll(
385                                    groupLocalService.search(
386                                            user.getCompanyId(), groupParams, start, end));
387                    }
388    
389                    if ((classNames == null) ||
390                            ArrayUtil.contains(classNames, Organization.class.getName())) {
391    
392                            LinkedHashMap<String, Object> organizationParams =
393                                    new LinkedHashMap<String, Object>();
394    
395                            organizationParams.put("usersOrgs", new Long(userId));
396    
397                            List<Organization> userOrgs = organizationLocalService.search(
398                                    user.getCompanyId(), organizationParams, start, end);
399    
400                            for (Organization organization : userOrgs) {
401                                    userPlaces.add(0, organization.getGroup());
402    
403                                    if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) {
404                                            for (Organization ancestorOrganization :
405                                                            organization.getAncestors()) {
406    
407                                                    userPlaces.add(0, ancestorOrganization.getGroup());
408                                            }
409                                    }
410                            }
411                    }
412    
413                    if ((classNames == null) ||
414                            ArrayUtil.contains(classNames, User.class.getName())) {
415    
416                            if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED ||
417                                    PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {
418    
419                                    Group userGroup = user.getGroup();
420    
421                                    userPlaces.add(0, userGroup);
422                            }
423                    }
424    
425                    PermissionChecker permissionChecker = getPermissionChecker();
426    
427                    if (permissionChecker.getUserId() != userId) {
428                            try {
429                                    permissionChecker = PermissionCheckerFactoryUtil.create(
430                                            user, true);
431                            }
432                            catch (Exception e) {
433                                    throw new PrincipalException(e);
434                            }
435                    }
436    
437                    if (includeControlPanel &&
438                            PortalPermissionUtil.contains(
439                                    permissionChecker, ActionKeys.VIEW_CONTROL_PANEL)) {
440    
441                            Group controlPanelGroup = groupLocalService.getGroup(
442                                    user.getCompanyId(), GroupConstants.CONTROL_PANEL);
443    
444                            userPlaces.add(0, controlPanelGroup);
445                    }
446    
447                    if ((max != QueryUtil.ALL_POS) && (userPlaces.size() > max)) {
448                            userPlaces = ListUtil.subList(userPlaces, start, end);
449                    }
450    
451                    return Collections.unmodifiableList(userPlaces);
452            }
453    
454            /**
455             * Returns the user's group &quot;places&quot; associated with the group
456             * entity class names, including the control panel group if the user is
457             * permitted to view the control panel.
458             *
459             * <p>
460             * <ul> <li> Class name &quot;User&quot; includes the user's layout set
461             * group. </li> <li> Class name &quot;Organization&quot; includes the user's
462             * immediate organization groups and inherited organization groups. </li>
463             * <li> Class name &quot;Group&quot; includes the user's immediate
464             * organization groups and site groups. </li> <li> A <code>classNames</code>
465             * value of <code>null</code> includes the user's layout set group,
466             * organization groups, inherited organization groups, and site groups.
467             * </li> </ul>
468             * </p>
469             *
470             * @param  userId the primary key of the user
471             * @param  classNames the group entity class names (optionally
472             *         <code>null</code>). For more information see {@link
473             *         #getUserPlaces(long, String[], int)}
474             * @param  max the maximum number of groups to return
475             * @return the user's group &quot;places&quot;
476             * @throws PortalException if a portal exception occurred
477             * @throws SystemException if a system exception occurred
478             */
479            public List<Group> getUserPlaces(long userId, String[] classNames, int max)
480                    throws PortalException, SystemException {
481    
482                    return getUserPlaces(userId, classNames, false, max);
483            }
484    
485            /**
486             * Returns the guest or current user's group &quot;places&quot; associated
487             * with the group entity class names, including the control panel group if
488             * the user is permitted to view the control panel.
489             *
490             * <p>
491             * <ul> <li> Class name &quot;User&quot; includes the user's layout set
492             * group. </li> <li> Class name &quot;Organization&quot; includes the user's
493             * immediate organization groups and inherited organization groups. </li>
494             * <li> Class name &quot;Group&quot; includes the user's immediate
495             * organization groups and site groups. </li> <li> A <code>classNames</code>
496             * value of <code>null</code> includes the user's layout set group,
497             * organization groups, inherited organization groups, and site groups.
498             * </li> </ul>
499             * </p>
500             *
501             * @param  classNames the group entity class names (optionally
502             *         <code>null</code>). For more information see {@link
503             *         #getUserPlaces(String[], int)}
504             * @param  max the maximum number of groups to return
505             * @return the user's group &quot;places&quot;
506             * @throws PortalException if a portal exception occurred
507             * @throws SystemException if a system exception occurred
508             */
509            public List<Group> getUserPlaces(String[] classNames, int max)
510                    throws PortalException, SystemException {
511    
512                    return getUserPlaces(getGuestOrUserId(), classNames, false, max);
513            }
514    
515            /**
516             * Returns the guest or current user's layout set group, organization
517             * groups, inherited organization groups, and site groups.
518             *
519             * @return the user's layout set group, organization groups, and inherited
520             *         organization groups, and site groups
521             * @throws PortalException if a portal exception occurred
522             * @throws SystemException if a system exception occurred
523             */
524            public List<Group> getUserSites() throws PortalException, SystemException {
525                    return getUserPlaces(null, QueryUtil.ALL_POS);
526            }
527    
528            /**
529             * Returns <code>true</code> if the user is associated with the group,
530             * including the user's inherited organizations and user groups. System and
531             * staged groups are not included.
532             *
533             * @param  userId the primary key of the user
534             * @param  groupId the primary key of the group
535             * @return <code>true</code> if the user is associated with the group;
536             *         <code>false</code> otherwise
537             * @throws SystemException if a system exception occurred
538             */
539            public boolean hasUserGroup(long userId, long groupId)
540                    throws SystemException {
541    
542                    return groupLocalService.hasUserGroup(userId, groupId);
543            }
544    
545            /**
546             * Returns a name ordered range of all the site groups and organization
547             * groups that match the name and description, optionally including the
548             * user's inherited organization groups and user groups. System and staged
549             * groups are not included.
550             *
551             * <p>
552             * Useful when paginating results. Returns a maximum of <code>end -
553             * start</code> instances. <code>start</code> and <code>end</code> are not
554             * primary keys, they are indexes in the result set. Thus, <code>0</code>
555             * refers to the first result in the set. Setting both <code>start</code>
556             * and <code>end</code> to {@link
557             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
558             * result set.
559             * </p>
560             *
561             * @param  companyId the primary key of the company
562             * @param  name the group's name (optionally <code>null</code>)
563             * @param  description the group's description (optionally
564             *         <code>null</code>)
565             * @param  params the finder params (optionally <code>null</code>). To
566             *         include the user's inherited organizations and user groups in the
567             *         search, add entries having &quot;usersGroups&quot; and
568             *         &quot;inherit&quot; as keys mapped to the the user's ID. For more
569             *         information see {@link
570             *         com.liferay.portal.service.persistence.GroupFinder}
571             * @param  start the lower bound of the range of groups to return
572             * @param  end the upper bound of the range of groups to return (not
573             *         inclusive)
574             * @return the matching groups ordered by name
575             * @throws PortalException if a portal exception occurred
576             * @throws SystemException if a system exception occurred
577             */
578            public List<Group> search(
579                            long companyId, String name, String description, String[] params,
580                            int start, int end)
581                    throws PortalException, SystemException {
582    
583                    LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
584                            params);
585    
586                    List<Group> groups = groupLocalService.search(
587                            companyId, name, description, paramsObj, start, end);
588    
589                    return filterGroups(groups);
590            }
591    
592            /**
593             * Returns the number of groups and organization groups that match the name
594             * and description, optionally including the user's inherited organizations
595             * and user groups. System and staged groups are not included.
596             *
597             * @param  companyId the primary key of the company
598             * @param  name the group's name (optionally <code>null</code>)
599             * @param  description the group's description (optionally
600             *         <code>null</code>)
601             * @param  params the finder params (optionally <code>null</code>). To
602             *         include the user's inherited organizations and user groups in the
603             *         search, add entries having &quot;usersGroups&quot; and
604             *         &quot;inherit&quot; as keys mapped to the the user's ID. For more
605             *         information see {@link
606             *         com.liferay.portal.service.persistence.GroupFinder}
607             * @return the number of matching groups
608             * @throws SystemException if a system exception occurred
609             */
610            public int searchCount(
611                            long companyId, String name, String description, String[] params)
612                    throws SystemException {
613    
614                    LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
615                            params);
616    
617                    return groupLocalService.searchCount(
618                            companyId, name, description, paramsObj);
619            }
620    
621            /**
622             * Sets the groups associated with the role, removing and adding
623             * associations as necessary.
624             *
625             * @param  roleId the primary key of the role
626             * @param  groupIds the primary keys of the groups
627             * @throws PortalException if the user did not have permission to update
628             *         update the role
629             * @throws SystemException if a system exception occurred
630             */
631            public void setRoleGroups(long roleId, long[] groupIds)
632                    throws PortalException, SystemException {
633    
634                    RolePermissionUtil.check(
635                            getPermissionChecker(), roleId, ActionKeys.UPDATE);
636    
637                    groupLocalService.setRoleGroups(roleId, groupIds);
638            }
639    
640            /**
641             * Removes the groups from the role.
642             *
643             * @param  roleId the primary key of the role
644             * @param  groupIds the primary keys of the groups
645             * @throws PortalException if the user did not have permission to update the
646             *         role
647             * @throws SystemException if a system exception occurred
648             */
649            public void unsetRoleGroups(long roleId, long[] groupIds)
650                    throws PortalException, SystemException {
651    
652                    RolePermissionUtil.check(
653                            getPermissionChecker(), roleId, ActionKeys.UPDATE);
654    
655                    groupLocalService.unsetRoleGroups(roleId, groupIds);
656            }
657    
658            /**
659             * Updates the group's friendly URL.
660             *
661             * @param  groupId the primary key of the group
662             * @param  friendlyURL the group's new friendlyURL (optionally
663             *         <code>null</code>)
664             * @return the group
665             * @throws PortalException if the user did not have permission to update the
666             *         group, if a group with the primary key could not be found, or if
667             *         a valid friendly URL could not be created for the group
668             * @throws SystemException if a system exception occurred
669             */
670            public Group updateFriendlyURL(long groupId, String friendlyURL)
671                    throws PortalException, SystemException {
672    
673                    GroupPermissionUtil.check(
674                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
675    
676                    return groupLocalService.updateFriendlyURL(groupId, friendlyURL);
677            }
678    
679            /**
680             * Updates the group's type settings.
681             *
682             * @param  groupId the primary key of the group
683             * @param  typeSettings the group's new type settings (optionally
684             *         <code>null</code>)
685             * @return the group
686             * @throws PortalException if the user did not have permission to update the
687             *         group or if a group with the primary key could not be found
688             * @throws SystemException if a system exception occurred
689             */
690            public Group updateGroup(long groupId, String typeSettings)
691                    throws PortalException, SystemException {
692    
693                    GroupPermissionUtil.check(
694                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
695    
696                    return groupLocalService.updateGroup(groupId, typeSettings);
697            }
698    
699            /**
700             * Updates the group.
701             *
702             * @param  groupId the primary key of the group
703             * @param  name the group's new name
704             * @param  description the group's new description (optionally
705             *         <code>null</code>)
706             * @param  type the group's new type. For more information see {@link
707             *         com.liferay.portal.model.GroupConstants}
708             * @param  friendlyURL the group's new friendlyURL (optionally
709             *         <code>null</code>)
710             * @param  active whether the group is active
711             * @param  serviceContext the service context to be applied (optionally
712             *         <code>null</code>). Can set the asset category IDs and asset tag
713             *         names for the group.
714             * @return the group
715             * @throws PortalException if the user did not have permission to update the
716             *         group, if a group with the primary key could not be found, if the
717             *         friendly URL was invalid or could one not be created
718             * @throws SystemException if a system exception occurred
719             */
720            public Group updateGroup(
721                            long groupId, String name, String description, int type,
722                            String friendlyURL, boolean active, ServiceContext serviceContext)
723                    throws PortalException, SystemException {
724    
725                    GroupPermissionUtil.check(
726                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
727    
728                    return groupLocalService.updateGroup(
729                            groupId, name, description, type, friendlyURL, active,
730                            serviceContext);
731            }
732    
733            protected List<Group> filterGroups(List<Group> groups)
734                    throws PortalException, SystemException {
735    
736                    List<Group> filteredGroups = new ArrayList<Group>();
737    
738                    for (Group group : groups) {
739                            if (GroupPermissionUtil.contains(
740                                            getPermissionChecker(), group.getGroupId(),
741                                            ActionKeys.VIEW)) {
742    
743                                    filteredGroups.add(group);
744                            }
745                    }
746    
747                    return filteredGroups;
748            }
749    
750    }