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.lar.MissingReferences;
019    import com.liferay.portal.kernel.repository.model.Folder;
020    import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.service.base.StagingServiceBaseImpl;
023    import com.liferay.portal.service.permission.GroupPermissionUtil;
024    
025    import java.util.Map;
026    
027    /**
028     * @author Michael C. Han
029     */
030    public class StagingServiceImpl extends StagingServiceBaseImpl {
031    
032            @Override
033            public void cleanUpStagingRequest(long stagingRequestId)
034                    throws PortalException {
035    
036                    checkPermission(stagingRequestId);
037    
038                    stagingLocalService.cleanUpStagingRequest(stagingRequestId);
039            }
040    
041            @Override
042            public long createStagingRequest(long groupId, String checksum)
043                    throws PortalException {
044    
045                    GroupPermissionUtil.check(
046                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
047    
048                    return stagingLocalService.createStagingRequest(
049                            getUserId(), groupId, checksum);
050            }
051    
052            @Override
053            public void publishStagingRequest(
054                            long stagingRequestId, boolean privateLayout,
055                            Map<String, String[]> parameterMap)
056                    throws PortalException {
057    
058                    checkPermission(stagingRequestId);
059    
060                    stagingLocalService.publishStagingRequest(
061                            getUserId(), stagingRequestId, privateLayout, parameterMap);
062            }
063    
064            @Override
065            public void updateStagingRequest(
066                            long stagingRequestId, String fileName, byte[] bytes)
067                    throws PortalException {
068    
069                    checkPermission(stagingRequestId);
070    
071                    stagingLocalService.updateStagingRequest(
072                            getUserId(), stagingRequestId, fileName, bytes);
073            }
074    
075            @Override
076            public MissingReferences validateStagingRequest(
077                            long stagingRequestId, boolean privateLayout,
078                            Map<String, String[]> parameterMap)
079                    throws PortalException {
080    
081                    checkPermission(stagingRequestId);
082    
083                    return stagingLocalService.validateStagingRequest(
084                            getUserId(), stagingRequestId, privateLayout, parameterMap);
085            }
086    
087            protected void checkPermission(long stagingRequestId)
088                    throws PortalException {
089    
090                    Folder folder = PortletFileRepositoryUtil.getPortletFolder(
091                            stagingRequestId);
092    
093                    GroupPermissionUtil.check(
094                            getPermissionChecker(), folder.getGroupId(),
095                            ActionKeys.EXPORT_IMPORT_LAYOUTS);
096            }
097    
098    }