1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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   */
43  public class UserGroupServiceImpl extends UserGroupServiceBaseImpl {
44  
45      public void addGroupUserGroups(long groupId, long[] userGroupIds)
46          throws PortalException, SystemException {
47  
48          GroupPermissionUtil.check(
49              getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
50  
51          userGroupLocalService.addGroupUserGroups(groupId, userGroupIds);
52      }
53  
54      public UserGroup addUserGroup(String name, String description)
55          throws PortalException, SystemException {
56  
57          PortalPermissionUtil.check(
58              getPermissionChecker(), ActionKeys.ADD_USER_GROUP);
59  
60          User user = getUser();
61  
62          return userGroupLocalService.addUserGroup(
63              user.getUserId(), user.getCompanyId(), name, description);
64      }
65  
66      public void deleteUserGroup(long userGroupId)
67          throws PortalException, SystemException {
68  
69          UserGroupPermissionUtil.check(
70              getPermissionChecker(), userGroupId, ActionKeys.DELETE);
71  
72          userGroupLocalService.deleteUserGroup(userGroupId);
73      }
74  
75      public UserGroup getUserGroup(long userGroupId)
76          throws PortalException, SystemException {
77  
78          UserGroupPermissionUtil.check(
79              getPermissionChecker(), userGroupId, ActionKeys.VIEW);
80  
81          return userGroupLocalService.getUserGroup(userGroupId);
82      }
83  
84      public UserGroup getUserGroup(String name)
85          throws PortalException, SystemException {
86  
87          UserGroup userGroup = userGroupLocalService.getUserGroup(
88              getUser().getCompanyId(), name);
89  
90          long userGroupId = userGroup.getUserGroupId();
91  
92          UserGroupPermissionUtil.check(
93              getPermissionChecker(), userGroupId, ActionKeys.VIEW);
94  
95          return userGroup;
96      }
97  
98      public List<UserGroup> getUserUserGroups(long userId)
99          throws SystemException {
100 
101         return userGroupLocalService.getUserUserGroups(userId);
102     }
103 
104     public void unsetGroupUserGroups(long groupId, long[] userGroupIds)
105         throws PortalException, SystemException {
106 
107         GroupPermissionUtil.check(
108             getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
109 
110         userGroupLocalService.unsetGroupUserGroups(groupId, userGroupIds);
111     }
112 
113     public UserGroup updateUserGroup(
114             long userGroupId, String name, String description)
115         throws PortalException, SystemException {
116 
117         UserGroupPermissionUtil.check(
118             getPermissionChecker(), userGroupId, ActionKeys.UPDATE);
119 
120         return userGroupLocalService.updateUserGroup(
121             getUser().getCompanyId(), userGroupId, name, description);
122     }
123 
124 }