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