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.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    }