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