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.kernel.util.MapUtil;
28  import com.liferay.portal.model.Group;
29  import com.liferay.portal.model.Organization;
30  import com.liferay.portal.model.UserGroup;
31  import com.liferay.portal.security.permission.ActionKeys;
32  import com.liferay.portal.service.base.GroupServiceBaseImpl;
33  import com.liferay.portal.service.permission.GroupPermissionUtil;
34  import com.liferay.portal.service.permission.PortalPermissionUtil;
35  import com.liferay.portal.service.permission.RolePermissionUtil;
36  
37  import java.util.LinkedHashMap;
38  import java.util.List;
39  
40  /**
41   * <a href="GroupServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   */
45  public class GroupServiceImpl extends GroupServiceBaseImpl {
46  
47      public Group addGroup(
48              String name, String description, int type, String friendlyURL,
49              boolean active)
50          throws PortalException, SystemException {
51  
52          PortalPermissionUtil.check(
53              getPermissionChecker(), ActionKeys.ADD_COMMUNITY);
54  
55          return groupLocalService.addGroup(
56              getUserId(), null, 0, name, description, type, friendlyURL, active);
57      }
58  
59      public Group addGroup(
60              long liveGroupId, String name, String description, int type,
61              String friendlyURL, boolean active)
62          throws PortalException, SystemException {
63  
64          GroupPermissionUtil.check(
65              getPermissionChecker(), liveGroupId, ActionKeys.UPDATE);
66  
67          return groupLocalService.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          groupLocalService.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          groupLocalService.deleteGroup(groupId);
88      }
89  
90      public Group getGroup(long groupId)
91          throws PortalException, SystemException {
92  
93          return groupLocalService.getGroup(groupId);
94      }
95  
96      public Group getGroup(long companyId, String name)
97          throws PortalException, SystemException {
98  
99          return groupLocalService.getGroup(companyId, name);
100     }
101 
102     public List<Group> getOrganizationsGroups(
103         List<Organization> organizations) {
104 
105         return groupLocalService.getOrganizationsGroups(organizations);
106     }
107 
108     public List<Group> getUserGroupsGroups(List<UserGroup> userGroups) {
109         return groupLocalService.getUserGroupsGroups(userGroups);
110     }
111 
112     public boolean hasUserGroup(long userId, long groupId)
113         throws SystemException {
114 
115         return groupLocalService.hasUserGroup(userId, groupId);
116     }
117 
118     public List<Group> search(
119             long companyId, String name, String description, String[] params,
120             int start, int end)
121         throws SystemException {
122 
123         LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
124             params);
125 
126         return groupLocalService.search(
127             companyId, name, description, paramsObj, start, end);
128     }
129 
130     public int searchCount(
131             long companyId, String name, String description, String[] params)
132         throws SystemException {
133 
134         LinkedHashMap<String, Object> paramsObj = MapUtil.toLinkedHashMap(
135             params);
136 
137         return groupLocalService.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         groupLocalService.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         groupLocalService.unsetRoleGroups(roleId, groupIds);
157     }
158 
159     public Group updateFriendlyURL(long groupId, String friendlyURL)
160         throws PortalException, SystemException {
161 
162         GroupPermissionUtil.check(
163             getPermissionChecker(), groupId, ActionKeys.UPDATE);
164 
165         return groupLocalService.updateFriendlyURL(groupId, friendlyURL);
166     }
167 
168     public Group updateGroup(
169             long groupId, String name, String description, int type,
170             String friendlyURL, boolean active)
171         throws PortalException, SystemException {
172 
173         GroupPermissionUtil.check(
174             getPermissionChecker(), groupId, ActionKeys.UPDATE);
175 
176         return groupLocalService.updateGroup(
177             groupId, name, description, type, friendlyURL, active);
178     }
179 
180     public Group updateGroup(long groupId, String typeSettings)
181         throws PortalException, SystemException {
182 
183         GroupPermissionUtil.check(
184             getPermissionChecker(), groupId, ActionKeys.UPDATE);
185 
186         return groupLocalService.updateGroup(groupId, typeSettings);
187     }
188 
189     public Group updateWorkflow(
190             long groupId, boolean workflowEnabled, int workflowStages,
191             String workflowRoleNames)
192         throws PortalException, SystemException {
193 
194         GroupPermissionUtil.check(
195             getPermissionChecker(), groupId, ActionKeys.MANAGE_STAGING);
196 
197         return groupLocalService.updateWorkflow(
198             groupId, workflowEnabled, workflowStages, workflowRoleNames);
199     }
200 
201 }