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