001    /**
002     * Copyright (c) 2000-2010 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.portlet.shopping.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.shopping.model.ShoppingCategory;
022    import com.liferay.portlet.shopping.service.base.ShoppingCategoryServiceBaseImpl;
023    import com.liferay.portlet.shopping.service.permission.ShoppingCategoryPermission;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class ShoppingCategoryServiceImpl
029            extends ShoppingCategoryServiceBaseImpl {
030    
031            public ShoppingCategory addCategory(
032                            long parentCategoryId, String name, String description,
033                            ServiceContext serviceContext)
034                    throws PortalException, SystemException {
035    
036                    ShoppingCategoryPermission.check(
037                            getPermissionChecker(), serviceContext.getScopeGroupId(),
038                            parentCategoryId, ActionKeys.ADD_CATEGORY);
039    
040                    return shoppingCategoryLocalService.addCategory(
041                            getUserId(), parentCategoryId, name, description, serviceContext);
042            }
043    
044            public void deleteCategory(long categoryId)
045                    throws PortalException, SystemException {
046    
047                    ShoppingCategory category = shoppingCategoryLocalService.getCategory(
048                            categoryId);
049    
050                    ShoppingCategoryPermission.check(
051                            getPermissionChecker(), category, ActionKeys.DELETE);
052    
053                    shoppingCategoryLocalService.deleteCategory(categoryId);
054            }
055    
056            public ShoppingCategory getCategory(long categoryId)
057                    throws PortalException, SystemException {
058    
059                    ShoppingCategory category = shoppingCategoryLocalService.getCategory(
060                            categoryId);
061    
062                    ShoppingCategoryPermission.check(
063                            getPermissionChecker(), category, ActionKeys.VIEW);
064    
065                    return category;
066            }
067    
068            public ShoppingCategory updateCategory(
069                            long categoryId, long parentCategoryId, String name,
070                            String description, boolean mergeWithParentCategory,
071                            ServiceContext serviceContext)
072                    throws PortalException, SystemException {
073    
074                    ShoppingCategory category = shoppingCategoryLocalService.getCategory(
075                            categoryId);
076    
077                    ShoppingCategoryPermission.check(
078                            getPermissionChecker(), category, ActionKeys.UPDATE);
079    
080                    return shoppingCategoryLocalService.updateCategory(
081                            categoryId, parentCategoryId, name, description,
082                            mergeWithParentCategory, serviceContext);
083            }
084    
085    }