001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.model.UserGroup;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.service.base.UserGroupServiceBaseImpl;
023    import com.liferay.portal.service.permission.GroupPermissionUtil;
024    import com.liferay.portal.service.permission.PortalPermissionUtil;
025    import com.liferay.portal.service.permission.TeamPermissionUtil;
026    import com.liferay.portal.service.permission.UserGroupPermissionUtil;
027    
028    import java.util.List;
029    
030    /**
031     * The implementation of the user group remote service.
032     *
033     * @author Charles May
034     */
035    public class UserGroupServiceImpl extends UserGroupServiceBaseImpl {
036    
037            /**
038             * Adds the user groups to the group.
039             *
040             * @param  groupId the primary key of the group
041             * @param  userGroupIds the primary keys of the user groups
042             * @throws PortalException if a group or user group with the primary key
043             *         could not be found, or if the user did not have permission to
044             *         assign group members
045             * @throws SystemException if a system exception occurred
046             */
047            public void addGroupUserGroups(long groupId, long[] userGroupIds)
048                    throws PortalException, SystemException {
049    
050                    GroupPermissionUtil.check(
051                            getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
052    
053                    userGroupLocalService.addGroupUserGroups(groupId, userGroupIds);
054            }
055    
056            /**
057             * Adds the user groups to the team
058             *
059             * @param  teamId the primary key of the team
060             * @param  userGroupIds the primary keys of the user groups
061             * @throws PortalException if a team or user group with the primary key
062             *         could not be found, or if the user did not have permission to
063             *         assign team members
064             * @throws SystemException if a system exception occurred
065             */
066            public void addTeamUserGroups(long teamId, long[] userGroupIds)
067                    throws PortalException, SystemException {
068    
069                    TeamPermissionUtil.check(
070                            getPermissionChecker(), teamId, ActionKeys.ASSIGN_MEMBERS);
071    
072                    userGroupLocalService.addTeamUserGroups(teamId, userGroupIds);
073            }
074    
075            /**
076             * Adds a user group.
077             *
078             * <p>
079             * This method handles the creation and bookkeeping of the user group,
080             * including its resources, metadata, and internal data structures.
081             * </p>
082             *
083             * @param  name the user group's name
084             * @param  description the user group's description
085             * @param  publicLayoutSetPrototypeId the primary key of the user group's
086             *         public layout set
087             * @param  privateLayoutSetPrototypeId the primary key of the user group's
088             *         private layout set
089             * @return the user group
090             * @throws PortalException if the user group's information was invalid or
091             *         if the user did not have permission to add the user group
092             * @throws SystemException if a system exception occurred
093             */
094            public UserGroup addUserGroup(
095                            String name, String description, long publicLayoutSetPrototypeId,
096                            long privateLayoutSetPrototypeId)
097                    throws PortalException, SystemException {
098    
099                    PortalPermissionUtil.check(
100                            getPermissionChecker(), ActionKeys.ADD_USER_GROUP);
101    
102                    User user = getUser();
103    
104                    return userGroupLocalService.addUserGroup(
105                            user.getUserId(), user.getCompanyId(), name, description,
106                            publicLayoutSetPrototypeId, privateLayoutSetPrototypeId);
107            }
108    
109            /**
110             * Deletes the user group.
111             *
112             * @param  userGroupId the primary key of the user group
113             * @throws PortalException if a user group with the primary key could not
114             *         be found, if the user did not have permission to delete the user
115             *         group, or if the user group had a workflow in approved status
116             * @throws SystemException if a system exception occurred
117             */
118            public void deleteUserGroup(long userGroupId)
119                    throws PortalException, SystemException {
120    
121                    UserGroupPermissionUtil.check(
122                            getPermissionChecker(), userGroupId, ActionKeys.DELETE);
123    
124                    userGroupLocalService.deleteUserGroup(userGroupId);
125            }
126    
127            /**
128             * Returns the user group with the primary key.
129             *
130             * @param  userGroupId the primary key of the user group
131             * @return Returns the user group with the primary key
132             * @throws PortalException if a user group with the primary key could not
133             *         be found or if the user did not have permission to view the user
134             *         group
135             * @throws SystemException if a system exception occurred
136             */
137            public UserGroup getUserGroup(long userGroupId)
138                    throws PortalException, SystemException {
139    
140                    UserGroupPermissionUtil.check(
141                            getPermissionChecker(), userGroupId, ActionKeys.VIEW);
142    
143                    return userGroupLocalService.getUserGroup(userGroupId);
144            }
145    
146            /**
147             * Returns the user group with the name.
148             *
149             * @param  name the user group's name
150             * @return Returns the user group with the name
151             * @throws PortalException if a user group with the name could not be found
152             *         or if the user did not have permission to view the user group
153             * @throws SystemException if a system exception occurred
154             */
155            public UserGroup getUserGroup(String name)
156                    throws PortalException, SystemException {
157    
158                    User user = getUser();
159    
160                    UserGroup userGroup = userGroupLocalService.getUserGroup(
161                            user.getCompanyId(), name);
162    
163                    long userGroupId = userGroup.getUserGroupId();
164    
165                    UserGroupPermissionUtil.check(
166                            getPermissionChecker(), userGroupId, ActionKeys.VIEW);
167    
168                    return userGroup;
169            }
170    
171            /**
172             * Returns all the user groups to which the user belongs.
173             *
174             * @param  userId the primary key of the user
175             * @return the user groups to which the user belongs
176             * @throws SystemException if a system exception occurred
177             */
178            public List<UserGroup> getUserUserGroups(long userId)
179                    throws SystemException {
180    
181                    return userGroupLocalService.getUserUserGroups(userId);
182            }
183    
184            /**
185             * Removes the user groups from the group.
186             *
187             * @param  groupId the primary key of the group
188             * @param  userGroupIds the primary keys of the user groups
189             * @throws PortalException if the user did not have permission to assign
190             *         group members
191             * @throws SystemException if a system exception occurred
192             */
193            public void unsetGroupUserGroups(long groupId, long[] userGroupIds)
194                    throws PortalException, SystemException {
195    
196                    GroupPermissionUtil.check(
197                            getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
198    
199                    userGroupLocalService.unsetGroupUserGroups(groupId, userGroupIds);
200            }
201    
202            /**
203             * Removes the user groups from the team.
204             *
205             * @param  teamId the primary key of the team
206             * @param  userGroupIds the primary keys of the user groups
207             * @throws PortalException if the user did not have permission to assign
208             *         team members
209             * @throws SystemException if a system exception occurred
210             */
211            public void unsetTeamUserGroups(long teamId, long[] userGroupIds)
212                    throws PortalException, SystemException {
213    
214                    TeamPermissionUtil.check(
215                            getPermissionChecker(), teamId, ActionKeys.ASSIGN_MEMBERS);
216    
217                    userGroupLocalService.unsetTeamUserGroups(teamId, userGroupIds);
218            }
219    
220            /**
221             * Updates the user group.
222             *
223             * @param  userGroupId the primary key of the user group
224             * @param  name the user group's name
225             * @param  description the the user group's description
226             * @param  publicLayoutSetPrototypeId the primary key of the user group's
227             *         public layout set
228             * @param  privateLayoutSetPrototypeId the primary key of the user group's
229             *         private layout set
230             * @return the user group
231             * @throws PortalException if a user group with the primary key was not
232             *         found, if the new information was invalid, or if the user did
233             *         not have permission to update the user group information
234             * @throws SystemException if a system exception occurred
235             */
236            public UserGroup updateUserGroup(
237                            long userGroupId, String name, String description,
238                            long publicLayoutSetPrototypeId, long privateLayoutSetPrototypeId)
239                    throws PortalException, SystemException {
240    
241                    UserGroupPermissionUtil.check(
242                            getPermissionChecker(), userGroupId, ActionKeys.UPDATE);
243    
244                    User user = getUser();
245    
246                    return userGroupLocalService.updateUserGroup(
247                            user.getCompanyId(), userGroupId, name, description,
248                            publicLayoutSetPrototypeId, privateLayoutSetPrototypeId);
249            }
250    
251    }