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.exception.PortalException; 018 import com.liferay.portal.kernel.exception.SystemException; 019 import com.liferay.portal.model.User; 020 import com.liferay.portal.model.UserGroup; 021 import com.liferay.portal.security.permission.ActionKeys; 022 import com.liferay.portal.service.base.UserGroupServiceBaseImpl; 023 import com.liferay.portal.service.permission.GroupPermissionUtil; 024 import com.liferay.portal.service.permission.PortalPermissionUtil; 025 import com.liferay.portal.service.permission.TeamPermissionUtil; 026 import com.liferay.portal.service.permission.UserGroupPermissionUtil; 027 028 import java.util.List; 029 030 /** 031 * The implementation of the user group remote service. 032 * 033 * @author Charles May 034 */ 035 public class UserGroupServiceImpl extends UserGroupServiceBaseImpl { 036 037 /** 038 * Adds the user groups to the group. 039 * 040 * @param groupId the primary key of the group 041 * @param userGroupIds the primary keys of the user groups 042 * @throws PortalException if a group or user group with the primary key 043 * could not be found, or if the user did not have permission to 044 * assign group members 045 * @throws SystemException if a system exception occurred 046 */ 047 public void addGroupUserGroups(long groupId, long[] userGroupIds) 048 throws PortalException, SystemException { 049 050 GroupPermissionUtil.check( 051 getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS); 052 053 userGroupLocalService.addGroupUserGroups(groupId, userGroupIds); 054 } 055 056 /** 057 * Adds the user groups to the team 058 * 059 * @param teamId the primary key of the team 060 * @param userGroupIds the primary keys of the user groups 061 * @throws PortalException if a team or user group with the primary key 062 * could not be found, or if the user did not have permission to 063 * assign team members 064 * @throws SystemException if a system exception occurred 065 */ 066 public void addTeamUserGroups(long teamId, long[] userGroupIds) 067 throws PortalException, SystemException { 068 069 TeamPermissionUtil.check( 070 getPermissionChecker(), teamId, ActionKeys.ASSIGN_MEMBERS); 071 072 userGroupLocalService.addTeamUserGroups(teamId, userGroupIds); 073 } 074 075 /** 076 * Adds a user group. 077 * 078 * <p> 079 * This method handles the creation and bookkeeping of the user group, 080 * including its resources, metadata, and internal data structures. 081 * </p> 082 * 083 * @param name the user group's name 084 * @param description the user group's description 085 * @return the user group 086 * @throws PortalException if the user group's information was invalid or if 087 * the user did not have permission to add the user group 088 * @throws SystemException if a system exception occurred 089 */ 090 public UserGroup addUserGroup(String name, String description) 091 throws PortalException, SystemException { 092 093 PortalPermissionUtil.check( 094 getPermissionChecker(), ActionKeys.ADD_USER_GROUP); 095 096 User user = getUser(); 097 098 return userGroupLocalService.addUserGroup( 099 user.getUserId(), user.getCompanyId(), name, description); 100 } 101 102 /** 103 * Deletes the user group. 104 * 105 * @param userGroupId the primary key of the user group 106 * @throws PortalException if a user group with the primary key could not be 107 * found, if the user did not have permission to delete the user 108 * group, or if the user group had a workflow in approved status 109 * @throws SystemException if a system exception occurred 110 */ 111 public void deleteUserGroup(long userGroupId) 112 throws PortalException, SystemException { 113 114 UserGroupPermissionUtil.check( 115 getPermissionChecker(), userGroupId, ActionKeys.DELETE); 116 117 userGroupLocalService.deleteUserGroup(userGroupId); 118 } 119 120 /** 121 * Returns the user group with the primary key. 122 * 123 * @param userGroupId the primary key of the user group 124 * @return Returns the user group with the primary key 125 * @throws PortalException if a user group with the primary key could not be 126 * found or if the user did not have permission to view the user 127 * group 128 * @throws SystemException if a system exception occurred 129 */ 130 public UserGroup getUserGroup(long userGroupId) 131 throws PortalException, SystemException { 132 133 UserGroupPermissionUtil.check( 134 getPermissionChecker(), userGroupId, ActionKeys.VIEW); 135 136 return userGroupLocalService.getUserGroup(userGroupId); 137 } 138 139 /** 140 * Returns the user group with the name. 141 * 142 * @param name the user group's name 143 * @return Returns the user group with the name 144 * @throws PortalException if a user group with the name could not be found 145 * or if the user did not have permission to view the user group 146 * @throws SystemException if a system exception occurred 147 */ 148 public UserGroup getUserGroup(String name) 149 throws PortalException, SystemException { 150 151 User user = getUser(); 152 153 UserGroup userGroup = userGroupLocalService.getUserGroup( 154 user.getCompanyId(), name); 155 156 long userGroupId = userGroup.getUserGroupId(); 157 158 UserGroupPermissionUtil.check( 159 getPermissionChecker(), userGroupId, ActionKeys.VIEW); 160 161 return userGroup; 162 } 163 164 /** 165 * Returns all the user groups to which the user belongs. 166 * 167 * @param userId the primary key of the user 168 * @return the user groups to which the user belongs 169 * @throws SystemException if a system exception occurred 170 */ 171 public List<UserGroup> getUserUserGroups(long userId) 172 throws SystemException { 173 174 return userGroupLocalService.getUserUserGroups(userId); 175 } 176 177 /** 178 * Removes the user groups from the group. 179 * 180 * @param groupId the primary key of the group 181 * @param userGroupIds the primary keys of the user groups 182 * @throws PortalException if the user did not have permission to assign 183 * group members 184 * @throws SystemException if a system exception occurred 185 */ 186 public void unsetGroupUserGroups(long groupId, long[] userGroupIds) 187 throws PortalException, SystemException { 188 189 GroupPermissionUtil.check( 190 getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS); 191 192 userGroupLocalService.unsetGroupUserGroups(groupId, userGroupIds); 193 } 194 195 /** 196 * Removes the user groups from the team. 197 * 198 * @param teamId the primary key of the team 199 * @param userGroupIds the primary keys of the user groups 200 * @throws PortalException if the user did not have permission to assign 201 * team members 202 * @throws SystemException if a system exception occurred 203 */ 204 public void unsetTeamUserGroups(long teamId, long[] userGroupIds) 205 throws PortalException, SystemException { 206 207 TeamPermissionUtil.check( 208 getPermissionChecker(), teamId, ActionKeys.ASSIGN_MEMBERS); 209 210 userGroupLocalService.unsetTeamUserGroups(teamId, userGroupIds); 211 } 212 213 /** 214 * Updates the user group. 215 * 216 * @param userGroupId the primary key of the user group 217 * @param name the user group's name 218 * @param description the the user group's description 219 * @return the user group 220 * @throws PortalException if a user group with the primary key was not 221 * found, if the new information was invalid, or if the user did not 222 * have permission to update the user group information 223 * @throws SystemException if a system exception occurred 224 */ 225 public UserGroup updateUserGroup( 226 long userGroupId, String name, String description) 227 throws PortalException, SystemException { 228 229 UserGroupPermissionUtil.check( 230 getPermissionChecker(), userGroupId, ActionKeys.UPDATE); 231 232 User user = getUser(); 233 234 return userGroupLocalService.updateUserGroup( 235 user.getCompanyId(), userGroupId, name, description); 236 } 237 238 }