001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            public Website addWebsite(
033                            String className, long classPK, String url, int typeId,
034                            boolean primary)
035                    throws PortalException, SystemException {
036    
037                    CommonPermissionUtil.check(
038                            getPermissionChecker(), className, classPK, ActionKeys.UPDATE);
039    
040                    return websiteLocalService.addWebsite(
041                            getUserId(), className, classPK, url, typeId, primary);
042            }
043    
044            public void deleteWebsite(long websiteId)
045                    throws PortalException, SystemException {
046    
047                    Website website = websitePersistence.findByPrimaryKey(websiteId);
048    
049                    CommonPermissionUtil.check(
050                            getPermissionChecker(), website.getClassNameId(),
051                            website.getClassPK(), ActionKeys.UPDATE);
052    
053                    websiteLocalService.deleteWebsite(websiteId);
054            }
055    
056            public Website getWebsite(long websiteId)
057                    throws PortalException, SystemException {
058    
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            public List<Website> getWebsites(String className, long classPK)
069                    throws PortalException, SystemException {
070    
071                    CommonPermissionUtil.check(
072                            getPermissionChecker(), className, classPK, ActionKeys.VIEW);
073    
074                    User user = getUser();
075    
076                    return websiteLocalService.getWebsites(
077                            user.getCompanyId(), className, classPK);
078            }
079    
080            public Website updateWebsite(
081                            long websiteId, String url, int typeId, boolean primary)
082                    throws PortalException, SystemException {
083    
084                    Website website = websitePersistence.findByPrimaryKey(websiteId);
085    
086                    CommonPermissionUtil.check(
087                            getPermissionChecker(), website.getClassNameId(),
088                            website.getClassPK(), ActionKeys.UPDATE);
089    
090                    return websiteLocalService.updateWebsite(
091                            websiteId, url, typeId, primary);
092            }
093    
094    }