1   /**
2    * Copyright (c) 2000-2007 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.kernel.security.permission.ActionKeys;
28  import com.liferay.portal.model.Group;
29  import com.liferay.portal.service.GroupLocalServiceUtil;
30  import com.liferay.portal.service.GroupService;
31  import com.liferay.portal.service.permission.GroupPermissionUtil;
32  import com.liferay.portal.service.permission.PortalPermissionUtil;
33  import com.liferay.portal.service.permission.RolePermissionUtil;
34  import com.liferay.util.MapUtil;
35  
36  import java.util.LinkedHashMap;
37  import java.util.List;
38  
39  /**
40   * <a href="GroupServiceImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class GroupServiceImpl extends PrincipalBean implements GroupService {
46  
47      public Group addGroup(
48              String name, String description, String type, String friendlyURL,
49              boolean active)
50          throws PortalException, SystemException {
51  
52          PortalPermissionUtil.check(
53              getPermissionChecker(), ActionKeys.ADD_COMMUNITY);
54  
55          return GroupLocalServiceUtil.addGroup(
56              getUserId(), null, 0, name, description, type, friendlyURL, active);
57      }
58  
59      public Group addGroup(
60              long liveGroupId, String name, String description, String type,
61              String friendlyURL, boolean active)
62          throws PortalException, SystemException {
63  
64          GroupPermissionUtil.check(
65              getPermissionChecker(), liveGroupId, ActionKeys.UPDATE);
66  
67          return GroupLocalServiceUtil.addGroup(
68              getUserId(), null, 0, liveGroupId, name, description, type,
69              friendlyURL, active);
70      }
71  
72      public void addRoleGroups(long roleId, long[] groupIds)
73          throws PortalException, SystemException {
74  
75          RolePermissionUtil.check(
76              getPermissionChecker(), roleId, ActionKeys.UPDATE);
77  
78          GroupLocalServiceUtil.addRoleGroups(roleId, groupIds);
79      }
80  
81      public void deleteGroup(long groupId)
82          throws PortalException, SystemException {
83  
84          GroupPermissionUtil.check(
85              getPermissionChecker(), groupId, ActionKeys.DELETE);
86  
87          GroupLocalServiceUtil.deleteGroup(groupId);
88      }
89  
90      public Group getGroup(long groupId)
91          throws PortalException, SystemException {
92  
93          return GroupLocalServiceUtil.getGroup(groupId);
94      }
95  
96      public Group getGroup(long companyId, String name)
97          throws PortalException, SystemException {
98  
99          return GroupLocalServiceUtil.getGroup(companyId, name);
100     }
101 
102     public List getOrganizationsGroups(List organizations)
103         throws PortalException, SystemException {
104 
105         return GroupLocalServiceUtil.getOrganizationsGroups(organizations);
106     }
107 
108     public List getUserGroupsGroups(List userGroups)
109         throws PortalException, SystemException {
110 
111         return GroupLocalServiceUtil.getUserGroupsGroups(userGroups);
112     }
113 
114     public boolean hasUserGroup(long userId, long groupId)
115         throws SystemException {
116 
117         return GroupLocalServiceUtil.hasUserGroup(userId, groupId);
118     }
119 
120     public List search(
121             long companyId, String name, String description, String[] params,
122             int begin, int end)
123         throws SystemException {
124 
125         LinkedHashMap paramsObj = MapUtil.toLinkedHashMap(params);
126 
127         return GroupLocalServiceUtil.search(
128             companyId, name, description, paramsObj, begin, end);
129     }
130 
131     public int searchCount(
132             long companyId, String name, String description, String[] params)
133         throws SystemException {
134 
135         LinkedHashMap paramsObj = MapUtil.toLinkedHashMap(params);
136 
137         return GroupLocalServiceUtil.searchCount(
138             companyId, name, description, paramsObj);
139     }
140 
141     public void setRoleGroups(long roleId, long[] groupIds)
142         throws PortalException, SystemException {
143 
144         RolePermissionUtil.check(
145             getPermissionChecker(), roleId, ActionKeys.UPDATE);
146 
147         GroupLocalServiceUtil.setRoleGroups(roleId, groupIds);
148     }
149 
150     public void unsetRoleGroups(long roleId, long[] groupIds)
151         throws PortalException, SystemException {
152 
153         RolePermissionUtil.check(
154             getPermissionChecker(), roleId, ActionKeys.UPDATE);
155 
156         GroupLocalServiceUtil.unsetRoleGroups(roleId, groupIds);
157     }
158 
159     public Group updateGroup(
160             long groupId, String name, String description, String type,
161             String friendlyURL, boolean active)
162         throws PortalException, SystemException {
163 
164         GroupPermissionUtil.check(
165             getPermissionChecker(), groupId, ActionKeys.UPDATE);
166 
167         return GroupLocalServiceUtil.updateGroup(
168             groupId, name, description, type, friendlyURL, active);
169     }
170 
171     public Group updateGroup(long groupId, String typeSettings)
172         throws PortalException, SystemException {
173 
174         GroupPermissionUtil.check(
175             getPermissionChecker(), groupId, ActionKeys.UPDATE);
176 
177         return GroupLocalServiceUtil.updateGroup(groupId, typeSettings);
178     }
179 
180 }