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.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.model.LayoutSetBranch;
021    import com.liferay.portal.kernel.security.permission.ActionKeys;
022    import com.liferay.portal.kernel.service.ServiceContext;
023    import com.liferay.portal.kernel.service.permission.GroupPermissionUtil;
024    import com.liferay.portal.kernel.service.permission.LayoutSetBranchPermissionUtil;
025    import com.liferay.portal.service.base.LayoutSetBranchServiceBaseImpl;
026    
027    import java.util.ArrayList;
028    import java.util.List;
029    
030    /**
031     * @author Raymond Augé
032     * @author Brian Wing Shun Chan
033     */
034    public class LayoutSetBranchServiceImpl extends LayoutSetBranchServiceBaseImpl {
035    
036            @Override
037            public LayoutSetBranch addLayoutSetBranch(
038                            long groupId, boolean privateLayout, String name,
039                            String description, boolean master, long copyLayoutSetBranchId,
040                            ServiceContext serviceContext)
041                    throws PortalException {
042    
043                    GroupPermissionUtil.check(
044                            getPermissionChecker(), groupId, ActionKeys.ADD_LAYOUT_SET_BRANCH);
045    
046                    return layoutSetBranchLocalService.addLayoutSetBranch(
047                            getUserId(), groupId, privateLayout, name, description, master,
048                            copyLayoutSetBranchId, serviceContext);
049            }
050    
051            @Override
052            public void deleteLayoutSetBranch(long layoutSetBranchId)
053                    throws PortalException {
054    
055                    LayoutSetBranchPermissionUtil.check(
056                            getPermissionChecker(), layoutSetBranchId, ActionKeys.DELETE);
057    
058                    layoutSetBranchLocalService.deleteLayoutSetBranch(layoutSetBranchId);
059            }
060    
061            @Override
062            public List<LayoutSetBranch> getLayoutSetBranches(
063                    long groupId, boolean privateLayout) {
064    
065                    try {
066                            if (GroupPermissionUtil.contains(
067                                            getPermissionChecker(), groupId, ActionKeys.VIEW_STAGING)) {
068    
069                                    return layoutSetBranchLocalService.getLayoutSetBranches(
070                                            groupId, privateLayout);
071                            }
072                    }
073                    catch (PortalException pe) {
074                            if (_log.isDebugEnabled()) {
075                                    _log.debug(
076                                            "Unable to get layout set branches for group " + groupId +
077                                                    " with " + (privateLayout ? "private" : "public") +
078                                                            " layouts",
079                                            pe);
080                            }
081                    }
082    
083                    return new ArrayList<>();
084            }
085    
086            @Override
087            public LayoutSetBranch mergeLayoutSetBranch(
088                            long layoutSetBranchId, long mergeLayoutSetBranchId,
089                            ServiceContext serviceContext)
090                    throws PortalException {
091    
092                    LayoutSetBranchPermissionUtil.check(
093                            getPermissionChecker(), layoutSetBranchId, ActionKeys.UPDATE);
094    
095                    return layoutSetBranchLocalService.mergeLayoutSetBranch(
096                            layoutSetBranchId, mergeLayoutSetBranchId, serviceContext);
097            }
098    
099            @Override
100            public LayoutSetBranch updateLayoutSetBranch(
101                            long groupId, long layoutSetBranchId, String name,
102                            String description, ServiceContext serviceContext)
103                    throws PortalException {
104    
105                    LayoutSetBranchPermissionUtil.check(
106                            getPermissionChecker(), layoutSetBranchId, ActionKeys.UPDATE);
107    
108                    return layoutSetBranchLocalService.updateLayoutSetBranch(
109                            layoutSetBranchId, name, description, serviceContext);
110            }
111    
112            private static final Log _log = LogFactoryUtil.getLog(
113                    LayoutSetBranchServiceImpl.class);
114    
115    }