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