1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.model.User;
20  import com.liferay.portal.model.UserGroup;
21  import com.liferay.portal.security.permission.ActionKeys;
22  import com.liferay.portal.service.base.UserGroupServiceBaseImpl;
23  import com.liferay.portal.service.permission.GroupPermissionUtil;
24  import com.liferay.portal.service.permission.PortalPermissionUtil;
25  import com.liferay.portal.service.permission.UserGroupPermissionUtil;
26  
27  import java.util.List;
28  
29  /**
30   * <a href="UserGroupServiceImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Charles May
33   */
34  public class UserGroupServiceImpl extends UserGroupServiceBaseImpl {
35  
36      public void addGroupUserGroups(long groupId, long[] userGroupIds)
37          throws PortalException, SystemException {
38  
39          GroupPermissionUtil.check(
40              getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
41  
42          userGroupLocalService.addGroupUserGroups(groupId, userGroupIds);
43      }
44  
45      public UserGroup addUserGroup(String name, String description)
46          throws PortalException, SystemException {
47  
48          PortalPermissionUtil.check(
49              getPermissionChecker(), ActionKeys.ADD_USER_GROUP);
50  
51          User user = getUser();
52  
53          return userGroupLocalService.addUserGroup(
54              user.getUserId(), user.getCompanyId(), name, description);
55      }
56  
57      public void deleteUserGroup(long userGroupId)
58          throws PortalException, SystemException {
59  
60          UserGroupPermissionUtil.check(
61              getPermissionChecker(), userGroupId, ActionKeys.DELETE);
62  
63          userGroupLocalService.deleteUserGroup(userGroupId);
64      }
65  
66      public UserGroup getUserGroup(long userGroupId)
67          throws PortalException, SystemException {
68  
69          UserGroupPermissionUtil.check(
70              getPermissionChecker(), userGroupId, ActionKeys.VIEW);
71  
72          return userGroupLocalService.getUserGroup(userGroupId);
73      }
74  
75      public UserGroup getUserGroup(String name)
76          throws PortalException, SystemException {
77  
78          UserGroup userGroup = userGroupLocalService.getUserGroup(
79              getUser().getCompanyId(), name);
80  
81          long userGroupId = userGroup.getUserGroupId();
82  
83          UserGroupPermissionUtil.check(
84              getPermissionChecker(), userGroupId, ActionKeys.VIEW);
85  
86          return userGroup;
87      }
88  
89      public List<UserGroup> getUserUserGroups(long userId)
90          throws SystemException {
91  
92          return userGroupLocalService.getUserUserGroups(userId);
93      }
94  
95      public void unsetGroupUserGroups(long groupId, long[] userGroupIds)
96          throws PortalException, SystemException {
97  
98          GroupPermissionUtil.check(
99              getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
100 
101         userGroupLocalService.unsetGroupUserGroups(groupId, userGroupIds);
102     }
103 
104     public UserGroup updateUserGroup(
105             long userGroupId, String name, String description)
106         throws PortalException, SystemException {
107 
108         UserGroupPermissionUtil.check(
109             getPermissionChecker(), userGroupId, ActionKeys.UPDATE);
110 
111         return userGroupLocalService.updateUserGroup(
112             getUser().getCompanyId(), userGroupId, name, description);
113     }
114 
115 }