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.portlet.exportimport.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.repository.model.Folder;
019    import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.permission.GroupPermissionUtil;
022    import com.liferay.portlet.exportimport.lar.MissingReferences;
023    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
024    import com.liferay.portlet.exportimport.service.base.StagingServiceBaseImpl;
025    
026    import java.util.Map;
027    
028    /**
029     * @author Michael C. Han
030     */
031    public class StagingServiceImpl extends StagingServiceBaseImpl {
032    
033            @Override
034            public void cleanUpStagingRequest(long stagingRequestId)
035                    throws PortalException {
036    
037                    checkPermission(stagingRequestId);
038    
039                    stagingLocalService.cleanUpStagingRequest(stagingRequestId);
040            }
041    
042            @Override
043            public long createStagingRequest(long groupId, String checksum)
044                    throws PortalException {
045    
046                    GroupPermissionUtil.check(
047                            getPermissionChecker(), groupId, ActionKeys.EXPORT_IMPORT_LAYOUTS);
048    
049                    return stagingLocalService.createStagingRequest(
050                            getUserId(), groupId, checksum);
051            }
052    
053            /**
054             * @deprecated As of 7.0.0, with no direct replacement
055             */
056            @Deprecated
057            @Override
058            public MissingReferences publishStagingRequest(
059                            long stagingRequestId, boolean privateLayout,
060                            Map<String, String[]> parameterMap)
061                    throws PortalException {
062    
063                    checkPermission(stagingRequestId);
064    
065                    return stagingLocalService.publishStagingRequest(
066                            getUserId(), stagingRequestId, privateLayout, parameterMap);
067            }
068    
069            @Override
070            public MissingReferences publishStagingRequest(
071                            long stagingRequestId,
072                            ExportImportConfiguration exportImportConfiguration)
073                    throws PortalException {
074    
075                    checkPermission(stagingRequestId);
076    
077                    return stagingLocalService.publishStagingRequest(
078                            getUserId(), stagingRequestId, exportImportConfiguration);
079            }
080    
081            @Override
082            public void updateStagingRequest(
083                            long stagingRequestId, String fileName, byte[] bytes)
084                    throws PortalException {
085    
086                    checkPermission(stagingRequestId);
087    
088                    stagingLocalService.updateStagingRequest(
089                            getUserId(), stagingRequestId, fileName, bytes);
090            }
091    
092            /**
093             * @deprecated As of 7.0.0, replaced by {@link #publishStagingRequest(long,
094             *             boolean, Map)}
095             */
096            @Deprecated
097            @Override
098            public MissingReferences validateStagingRequest(
099                            long stagingRequestId, boolean privateLayout,
100                            Map<String, String[]> parameterMap)
101                    throws PortalException {
102    
103                    checkPermission(stagingRequestId);
104    
105                    return stagingLocalService.validateStagingRequest(
106                            getUserId(), stagingRequestId, privateLayout, parameterMap);
107            }
108    
109            protected void checkPermission(long stagingRequestId)
110                    throws PortalException {
111    
112                    Folder folder = PortletFileRepositoryUtil.getPortletFolder(
113                            stagingRequestId);
114    
115                    GroupPermissionUtil.check(
116                            getPermissionChecker(), folder.getGroupId(),
117                            ActionKeys.EXPORT_IMPORT_LAYOUTS);
118            }
119    
120    }