1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.shopping.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.service.ServiceContext;
21  import com.liferay.portlet.shopping.model.ShoppingCategory;
22  import com.liferay.portlet.shopping.service.base.ShoppingCategoryServiceBaseImpl;
23  import com.liferay.portlet.shopping.service.permission.ShoppingCategoryPermission;
24  
25  /**
26   * <a href="ShoppingCategoryServiceImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class ShoppingCategoryServiceImpl
31      extends ShoppingCategoryServiceBaseImpl {
32  
33      public ShoppingCategory addCategory(
34              long parentCategoryId, String name, String description,
35              ServiceContext serviceContext)
36          throws PortalException, SystemException {
37  
38          ShoppingCategoryPermission.check(
39              getPermissionChecker(), serviceContext.getScopeGroupId(),
40              parentCategoryId, ActionKeys.ADD_CATEGORY);
41  
42          return shoppingCategoryLocalService.addCategory(
43              getUserId(), parentCategoryId, name, description, serviceContext);
44      }
45  
46      public void deleteCategory(long categoryId)
47          throws PortalException, SystemException {
48  
49          ShoppingCategory category = shoppingCategoryLocalService.getCategory(
50              categoryId);
51  
52          ShoppingCategoryPermission.check(
53              getPermissionChecker(), category, ActionKeys.DELETE);
54  
55          shoppingCategoryLocalService.deleteCategory(categoryId);
56      }
57  
58      public ShoppingCategory getCategory(long categoryId)
59          throws PortalException, SystemException {
60  
61          ShoppingCategory category = shoppingCategoryLocalService.getCategory(
62              categoryId);
63  
64          ShoppingCategoryPermission.check(
65              getPermissionChecker(), category, ActionKeys.VIEW);
66  
67          return category;
68      }
69  
70      public ShoppingCategory updateCategory(
71              long categoryId, long parentCategoryId, String name,
72              String description, boolean mergeWithParentCategory,
73              ServiceContext serviceContext)
74          throws PortalException, SystemException {
75  
76          ShoppingCategory category = shoppingCategoryLocalService.getCategory(
77              categoryId);
78  
79          ShoppingCategoryPermission.check(
80              getPermissionChecker(), category, ActionKeys.UPDATE);
81  
82          return shoppingCategoryLocalService.updateCategory(
83              categoryId, parentCategoryId, name, description,
84              mergeWithParentCategory, serviceContext);
85      }
86  
87  }