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.User;
020    import com.liferay.portal.model.Website;
021    import com.liferay.portal.security.permission.ActionKeys;
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, int typeId,
035                            boolean primary)
036                    throws PortalException, SystemException {
037    
038                    CommonPermissionUtil.check(
039                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
040    
041                    return websiteLocalService.addWebsite(
042                            getUserId(), className, classPK, url, typeId, primary);
043            }
044    
045            @Override
046            public void deleteWebsite(long websiteId)
047                    throws PortalException, SystemException {
048    
049                    Website website = websitePersistence.findByPrimaryKey(websiteId);
050    
051                    CommonPermissionUtil.check(
052                            getPermissionChecker(), website.getClassNameId(),
053                            website.getClassPK(), ActionKeys.UPDATE);
054    
055                    websiteLocalService.deleteWebsite(websiteId);
056            }
057    
058            @Override
059            public Website getWebsite(long websiteId)
060                    throws PortalException, SystemException {
061    
062                    Website website = websitePersistence.findByPrimaryKey(websiteId);
063    
064                    CommonPermissionUtil.check(
065                            getPermissionChecker(), website.getClassNameId(),
066                            website.getClassPK(), ActionKeys.VIEW);
067    
068                    return website;
069            }
070    
071            @Override
072            public List<Website> getWebsites(String className, long classPK)
073                    throws PortalException, SystemException {
074    
075                    CommonPermissionUtil.check(
076                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
077    
078                    User user = getUser();
079    
080                    return websiteLocalService.getWebsites(
081                            user.getCompanyId(), className, classPK);
082            }
083    
084            @Override
085            public Website updateWebsite(
086                            long websiteId, String url, int typeId, boolean primary)
087                    throws PortalException, SystemException {
088    
089                    Website website = websitePersistence.findByPrimaryKey(websiteId);
090    
091                    CommonPermissionUtil.check(
092                            getPermissionChecker(), website.getClassNameId(),
093                            website.getClassPK(), ActionKeys.UPDATE);
094    
095                    return websiteLocalService.updateWebsite(
096                            websiteId, url, typeId, primary);
097            }
098    
099    }