001    /**
002     * Copyright (c) 2000-2010 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.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    }