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