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             */
051            @Override
052            public void updateLayoutSetPrototypeLinkEnabled(
053                            long groupId, boolean privateLayout,
054                            boolean layoutSetPrototypeLinkEnabled,
055                            String layoutSetPrototypeUuid)
056                    throws PortalException {
057    
058                    GroupPermissionUtil.check(
059                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
060    
061                    LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(
062                            groupId, privateLayout);
063    
064                    if (layoutSet.isLayoutSetPrototypeLinkEnabled() &&
065                            !layoutSetPrototypeLinkEnabled) {
066    
067                            PortalPermissionUtil.check(
068                                    getPermissionChecker(), ActionKeys.UNLINK_LAYOUT_SET_PROTOTYPE);
069                    }
070    
071                    layoutSetLocalService.updateLayoutSetPrototypeLinkEnabled(
072                            groupId, privateLayout, layoutSetPrototypeLinkEnabled,
073                            layoutSetPrototypeUuid);
074            }
075    
076            @Override
077            public void updateLogo(
078                            long groupId, boolean privateLayout, boolean logo, byte[] bytes)
079                    throws PortalException {
080    
081                    GroupPermissionUtil.check(
082                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
083    
084                    layoutSetLocalService.updateLogo(groupId, privateLayout, logo, bytes);
085            }
086    
087            @Override
088            public void updateLogo(
089                            long groupId, boolean privateLayout, boolean logo, File file)
090                    throws PortalException {
091    
092                    GroupPermissionUtil.check(
093                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
094    
095                    layoutSetLocalService.updateLogo(groupId, privateLayout, logo, file);
096            }
097    
098            @Override
099            public void updateLogo(
100                            long groupId, boolean privateLayout, boolean logo,
101                            InputStream inputStream)
102                    throws PortalException {
103    
104                    updateLogo(groupId, privateLayout, logo, inputStream, true);
105            }
106    
107            @Override
108            public void updateLogo(
109                            long groupId, boolean privateLayout, boolean logo,
110                            InputStream inputStream, boolean cleanUpStream)
111                    throws PortalException {
112    
113                    GroupPermissionUtil.check(
114                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
115    
116                    layoutSetLocalService.updateLogo(
117                            groupId, privateLayout, logo, inputStream, cleanUpStream);
118            }
119    
120            @Override
121            public LayoutSet updateLookAndFeel(
122                            long groupId, boolean privateLayout, String themeId,
123                            String colorSchemeId, String css, boolean wapTheme)
124                    throws PortalException {
125    
126                    GroupPermissionUtil.check(
127                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
128    
129                    pluginSettingLocalService.checkPermission(
130                            getUserId(), themeId, Plugin.TYPE_THEME);
131    
132                    return layoutSetLocalService.updateLookAndFeel(
133                            groupId, privateLayout, themeId, colorSchemeId, css, wapTheme);
134            }
135    
136            @Override
137            public LayoutSet updateSettings(
138                            long groupId, boolean privateLayout, String settings)
139                    throws PortalException {
140    
141                    GroupPermissionUtil.check(
142                            getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
143    
144                    return layoutSetLocalService.updateSettings(
145                            groupId, privateLayout, settings);
146            }
147    
148            @Override
149            public LayoutSet updateVirtualHost(
150                            long groupId, boolean privateLayout, String virtualHost)
151                    throws PortalException {
152    
153                    GroupPermissionUtil.check(
154                            getPermissionChecker(), groupId, ActionKeys.UPDATE);
155    
156                    return layoutSetLocalService.updateVirtualHost(
157                            groupId, privateLayout, virtualHost);
158            }
159    
160    }