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