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