1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.model.User;
25  import com.liferay.portal.model.UserGroup;
26  import com.liferay.portal.security.permission.ActionKeys;
27  import com.liferay.portal.service.base.UserGroupServiceBaseImpl;
28  import com.liferay.portal.service.permission.GroupPermissionUtil;
29  import com.liferay.portal.service.permission.PortalPermissionUtil;
30  import com.liferay.portal.service.permission.UserGroupPermissionUtil;
31  
32  import java.util.List;
33  
34  /**
35   * <a href="UserGroupServiceImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Charles May
38   *
39   */
40  public class UserGroupServiceImpl extends UserGroupServiceBaseImpl {
41  
42      public void addGroupUserGroups(long groupId, long[] userGroupIds)
43          throws PortalException, SystemException {
44  
45          GroupPermissionUtil.check(
46              getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
47  
48          userGroupLocalService.addGroupUserGroups(groupId, userGroupIds);
49      }
50  
51      public UserGroup addUserGroup(String name, String description)
52          throws PortalException, SystemException {
53  
54          PortalPermissionUtil.check(
55              getPermissionChecker(), ActionKeys.ADD_USER_GROUP);
56  
57          User user = getUser();
58  
59          return userGroupLocalService.addUserGroup(
60              user.getUserId(), user.getCompanyId(), name, description);
61      }
62  
63      public void deleteUserGroup(long userGroupId)
64          throws PortalException, SystemException {
65  
66          UserGroupPermissionUtil.check(
67              getPermissionChecker(), userGroupId, ActionKeys.DELETE);
68  
69          userGroupLocalService.deleteUserGroup(userGroupId);
70      }
71  
72      public UserGroup getUserGroup(long userGroupId)
73          throws PortalException, SystemException {
74  
75          UserGroupPermissionUtil.check(
76              getPermissionChecker(), userGroupId, ActionKeys.VIEW);
77  
78          return userGroupLocalService.getUserGroup(userGroupId);
79      }
80  
81      public UserGroup getUserGroup(String name)
82          throws PortalException, SystemException {
83  
84          UserGroup userGroup = userGroupLocalService.getUserGroup(
85              getUser().getCompanyId(), name);
86  
87          long userGroupId = userGroup.getUserGroupId();
88  
89          UserGroupPermissionUtil.check(
90              getPermissionChecker(), userGroupId, ActionKeys.VIEW);
91  
92          return userGroup;
93      }
94  
95      public List<UserGroup> getUserUserGroups(long userId)
96          throws SystemException {
97  
98          return userGroupLocalService.getUserUserGroups(userId);
99      }
100 
101     public void unsetGroupUserGroups(long groupId, long[] userGroupIds)
102         throws PortalException, SystemException {
103 
104         GroupPermissionUtil.check(
105             getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
106 
107         userGroupLocalService.unsetGroupUserGroups(groupId, userGroupIds);
108     }
109 
110     public UserGroup updateUserGroup(
111             long userGroupId, String name, String description)
112         throws PortalException, SystemException {
113 
114         UserGroupPermissionUtil.check(
115             getPermissionChecker(), userGroupId, ActionKeys.UPDATE);
116 
117         return userGroupLocalService.updateUserGroup(
118             getUser().getCompanyId(), userGroupId, name, description);
119     }
120 
121 }