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