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.kernel.security.permission.ActionKeys;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.model.Website;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.service.base.WebsiteServiceBaseImpl;
023    import com.liferay.portal.service.permission.CommonPermissionUtil;
024    
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class WebsiteServiceImpl extends WebsiteServiceBaseImpl {
031    
032            @Override
033            public Website addWebsite(
034                            String className, long classPK, String url, long typeId,
035                            boolean primary, ServiceContext serviceContext)
036                    throws PortalException {
037    
038                    CommonPermissionUtil.check(
039                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
040    
041                    return websiteLocalService.addWebsite(
042                            getUserId(), className, classPK, url, typeId, primary,
043                            serviceContext);
044            }
045    
046            @Override
047            public void deleteWebsite(long websiteId) throws PortalException {
048                    Website website = websitePersistence.findByPrimaryKey(websiteId);
049    
050                    CommonPermissionUtil.check(
051                            getPermissionChecker(), website.getClassNameId(),
052                            website.getClassPK(), ActionKeys.UPDATE);
053    
054                    websiteLocalService.deleteWebsite(website);
055            }
056    
057            @Override
058            public Website getWebsite(long websiteId) throws PortalException {
059                    Website website = websitePersistence.findByPrimaryKey(websiteId);
060    
061                    CommonPermissionUtil.check(
062                            getPermissionChecker(), website.getClassNameId(),
063                            website.getClassPK(), ActionKeys.VIEW);
064    
065                    return website;
066            }
067    
068            @Override
069            public List<Website> getWebsites(String className, long classPK)
070                    throws PortalException {
071    
072                    CommonPermissionUtil.check(
073                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
074    
075                    User user = getUser();
076    
077                    return websiteLocalService.getWebsites(
078                            user.getCompanyId(), className, classPK);
079            }
080    
081            @Override
082            public Website updateWebsite(
083                            long websiteId, String url, long typeId, boolean primary)
084                    throws PortalException {
085    
086                    Website website = websitePersistence.findByPrimaryKey(websiteId);
087    
088                    CommonPermissionUtil.check(
089                            getPermissionChecker(), website.getClassNameId(),
090                            website.getClassPK(), ActionKeys.UPDATE);
091    
092                    return websiteLocalService.updateWebsite(
093                            websiteId, url, typeId, primary);
094            }
095    
096    }