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