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.model.LayoutBranch;
019    import com.liferay.portal.model.LayoutRevision;
020    import com.liferay.portal.model.LayoutSetBranch;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.security.permission.PermissionChecker;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portal.service.base.LayoutBranchServiceBaseImpl;
025    import com.liferay.portal.service.permission.GroupPermissionUtil;
026    import com.liferay.portal.service.permission.LayoutBranchPermissionUtil;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     * @author Julio Camarero
031     */
032    public class LayoutBranchServiceImpl extends LayoutBranchServiceBaseImpl {
033    
034            @Override
035            public LayoutBranch addLayoutBranch(
036                            long layoutRevisionId, String name, String description,
037                            boolean master, ServiceContext serviceContext)
038                    throws PortalException {
039    
040                    PermissionChecker permissionChecker = getPermissionChecker();
041    
042                    GroupPermissionUtil.check(
043                            permissionChecker, serviceContext.getScopeGroupId(),
044                            ActionKeys.ADD_LAYOUT_BRANCH);
045    
046                    LayoutRevision layoutRevision =
047                            layoutRevisionPersistence.findByPrimaryKey(layoutRevisionId);
048    
049                    LayoutSetBranch layoutSetBranch =
050                            layoutSetBranchPersistence.findByPrimaryKey(
051                                    layoutRevision.getLayoutSetBranchId());
052    
053                    GroupPermissionUtil.check(
054                            permissionChecker, layoutSetBranch.getGroupId(),
055                            ActionKeys.ADD_LAYOUT_BRANCH);
056    
057                    return layoutBranchLocalService.addLayoutBranch(
058                            layoutRevisionId, name, description, false, serviceContext);
059            }
060    
061            @Override
062            public void deleteLayoutBranch(long layoutBranchId) throws PortalException {
063                    LayoutBranchPermissionUtil.check(
064                            getPermissionChecker(), layoutBranchId, ActionKeys.DELETE);
065    
066                    layoutBranchLocalService.deleteLayoutBranch(layoutBranchId);
067            }
068    
069            @Override
070            public LayoutBranch updateLayoutBranch(
071                            long layoutBranchId, String name, String description,
072                            ServiceContext serviceContext)
073                    throws PortalException {
074    
075                    LayoutBranchPermissionUtil.check(
076                            getPermissionChecker(), layoutBranchId, ActionKeys.UPDATE);
077    
078                    return layoutBranchLocalService.updateLayoutBranch(
079                            layoutBranchId, name, description, serviceContext);
080            }
081    
082    }