001    /**
002     * Copyright (c) 2000-present 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.model.MembershipRequest;
019    import com.liferay.portal.kernel.security.permission.ActionKeys;
020    import com.liferay.portal.kernel.service.ServiceContext;
021    import com.liferay.portal.kernel.service.permission.GroupPermissionUtil;
022    import com.liferay.portal.service.base.MembershipRequestServiceBaseImpl;
023    
024    /**
025     * @author Jorge Ferrer
026     */
027    public class MembershipRequestServiceImpl
028            extends MembershipRequestServiceBaseImpl {
029    
030            @Override
031            public MembershipRequest addMembershipRequest(
032                            long groupId, String comments, ServiceContext serviceContext)
033                    throws PortalException {
034    
035                    return membershipRequestLocalService.addMembershipRequest(
036                            getUserId(), groupId, comments, serviceContext);
037            }
038    
039            @Override
040            public void deleteMembershipRequests(long groupId, long statusId)
041                    throws PortalException {
042    
043                    GroupPermissionUtil.check(
044                            getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
045    
046                    membershipRequestLocalService.deleteMembershipRequests(
047                            groupId, statusId);
048            }
049    
050            @Override
051            public MembershipRequest getMembershipRequest(long membershipRequestId)
052                    throws PortalException {
053    
054                    MembershipRequest membershipRequest =
055                            membershipRequestLocalService.getMembershipRequest(
056                                    membershipRequestId);
057    
058                    GroupPermissionUtil.check(
059                            getPermissionChecker(), membershipRequest.getGroupId(),
060                            ActionKeys.ASSIGN_MEMBERS);
061    
062                    return membershipRequest;
063            }
064    
065            @Override
066            public void updateStatus(
067                            long membershipRequestId, String reviewComments, long statusId,
068                            ServiceContext serviceContext)
069                    throws PortalException {
070    
071                    MembershipRequest membershipRequest =
072                            membershipRequestPersistence.findByPrimaryKey(membershipRequestId);
073    
074                    GroupPermissionUtil.check(
075                            getPermissionChecker(), membershipRequest.getGroupId(),
076                            ActionKeys.ASSIGN_MEMBERS);
077    
078                    membershipRequestLocalService.updateStatus(
079                            getUserId(), membershipRequestId, reviewComments, statusId, true,
080                            serviceContext);
081            }
082    
083    }