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.LayoutSet;
019    import com.liferay.portal.model.Plugin;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.base.LayoutSetServiceBaseImpl;
022    import com.liferay.portal.service.permission.GroupPermissionUtil;
023    import com.liferay.portal.service.permission.PortalPermissionUtil;
024    
025    import java.io.File;
026    import java.io.InputStream;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class LayoutSetServiceImpl extends LayoutSetServiceBaseImpl {
032    
033            /**
034             * Updates the state of the layout set prototype link.
035             *
036             * <p>
037             * <strong>Important:</strong> Setting
038             * <code>layoutSetPrototypeLinkEnabled</code> to <code>true</code> and
039             * <code>layoutSetPrototypeUuid</code> to <code>null</code> when the layout
040             * set prototype's current uuid is <code>null</code> will result in an
041             * <code>IllegalStateException</code>.
042             * </p>
043             *
044             * @param  groupId the primary key of the group
045             * @param  privateLayout whether the layout set is private to the group
046             * @param  layoutSetPrototypeLinkEnabled whether the layout set prototype is
047             *         link enabled
048             * @param  layoutSetPrototypeUuid the uuid of the layout set prototype to
049             *         link with
050             * @throws PortalException if a portal exception occurred
051             */
052            @Override
053            public void updateLayoutSetPrototypeLinkEnabled(
054                            long groupId, boolean privateLayout,
055                            boolean layoutSetPrototypeLinkEnabled,
056                            String layoutSetPrototypeUuid)
057                    throws PortalException {
058    
059                    GroupPermissionUtil.check(
060                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
061    
062                    LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(
063                            groupId, privateLayout);
064    
065                    if (layoutSet.isLayoutSetPrototypeLinkEnabled() &&
066                            !layoutSetPrototypeLinkEnabled) {
067    
068                            PortalPermissionUtil.check(
069                                    getPermissionChecker(), ActionKeys.UNLINK_LAYOUT_SET_PROTOTYPE);
070                    }
071    
072                    layoutSetLocalService.updateLayoutSetPrototypeLinkEnabled(
073                            groupId, privateLayout, layoutSetPrototypeLinkEnabled,
074                            layoutSetPrototypeUuid);
075            }
076    
077            @Override
078            public void updateLogo(
079                            long groupId, boolean privateLayout, boolean logo, byte[] bytes)
080                    throws PortalException {
081    
082                    GroupPermissionUtil.check(
083                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
084    
085                    layoutSetLocalService.updateLogo(groupId, privateLayout, logo, bytes);
086            }
087    
088            @Override
089            public void updateLogo(
090                            long groupId, boolean privateLayout, boolean logo, File file)
091                    throws PortalException {
092    
093                    GroupPermissionUtil.check(
094                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
095    
096                    layoutSetLocalService.updateLogo(groupId, privateLayout, logo, file);
097            }
098    
099            @Override
100            public void updateLogo(
101                            long groupId, boolean privateLayout, boolean logo,
102                            InputStream inputStream)
103                    throws PortalException {
104    
105                    updateLogo(groupId, privateLayout, logo, inputStream, true);
106            }
107    
108            @Override
109            public void updateLogo(
110                            long groupId, boolean privateLayout, boolean logo,
111                            InputStream inputStream, boolean cleanUpStream)
112                    throws PortalException {
113    
114                    GroupPermissionUtil.check(
115                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
116    
117                    layoutSetLocalService.updateLogo(
118                            groupId, privateLayout, logo, inputStream, cleanUpStream);
119            }
120    
121            @Override
122            public LayoutSet updateLookAndFeel(
123                            long groupId, boolean privateLayout, String themeId,
124                            String colorSchemeId, String css, boolean wapTheme)
125                    throws PortalException {
126    
127                    GroupPermissionUtil.check(
128                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
129    
130                    pluginSettingLocalService.checkPermission(
131                            getUserId(), themeId, Plugin.TYPE_THEME);
132    
133                    return layoutSetLocalService.updateLookAndFeel(
134                            groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
135            }
136    
137            @Override
138            public LayoutSet updateSettings(
139                            long groupId, boolean privateLayout, String settings)
140                    throws PortalException {
141    
142                    GroupPermissionUtil.check(
143                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
144    
145                    return layoutSetLocalService.updateSettings(
146                            groupId, privateLayout, settings);
147            }
148    
149            @Override
150            public LayoutSet updateVirtualHost(
151                            long groupId, boolean privateLayout, String virtualHost)
152                    throws PortalException {
153    
154                    GroupPermissionUtil.check(
155                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
156    
157                    return layoutSetLocalService.updateVirtualHost(
158                            groupId, privateLayout, virtualHost);
159            }
160    
161    }