001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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.service.base.UserGroupGroupRoleServiceBaseImpl;
020    import com.liferay.portal.service.permission.UserGroupRolePermissionUtil;
021    
022    /**
023     * @author Brett Swaim
024     * @author Akos Thurzo
025     */
026    public class UserGroupGroupRoleServiceImpl
027            extends UserGroupGroupRoleServiceBaseImpl {
028    
029            @Override
030            public void addUserGroupGroupRoles(
031                            long userGroupId, long groupId, long[] roleIds)
032                    throws PortalException, SystemException {
033    
034                    checkPermission(groupId, roleIds);
035    
036                    userGroupGroupRoleLocalService.addUserGroupGroupRoles(
037                            userGroupId, groupId, roleIds);
038            }
039    
040            @Override
041            public void addUserGroupGroupRoles(
042                            long[] userGroupIds, long groupId, long roleId)
043                    throws PortalException, SystemException {
044    
045                    checkPermission(groupId, new long[] {roleId});
046    
047                    userGroupGroupRoleLocalService.addUserGroupGroupRoles(
048                            userGroupIds, groupId, roleId);
049            }
050    
051            @Override
052            public void deleteUserGroupGroupRoles(
053                            long userGroupId, long groupId, long[] roleIds)
054                    throws PortalException, SystemException {
055    
056                    checkPermission(groupId, roleIds);
057    
058                    userGroupGroupRoleLocalService.deleteUserGroupGroupRoles(
059                            userGroupId, groupId, roleIds);
060            }
061    
062            @Override
063            public void deleteUserGroupGroupRoles(
064                            long[] userGroupIds, long groupId, long roleId)
065                    throws PortalException, SystemException {
066    
067                    checkPermission(groupId, new long[] {roleId});
068    
069                    userGroupGroupRoleLocalService.deleteUserGroupGroupRoles(
070                            userGroupIds, groupId, roleId);
071            }
072    
073            protected void checkPermission(long groupId, long[] roleIds)
074                    throws PortalException, SystemException {
075    
076                    for (long roleId : roleIds) {
077                            UserGroupRolePermissionUtil.check(
078                                    getPermissionChecker(), groupId, roleId);
079                    }
080            }
081    
082    }