001
014
015 package com.liferay.portlet.shopping.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.security.permission.ActionKeys;
019 import com.liferay.portal.service.ServiceContext;
020 import com.liferay.portlet.shopping.model.ShoppingCategory;
021 import com.liferay.portlet.shopping.service.base.ShoppingCategoryServiceBaseImpl;
022 import com.liferay.portlet.shopping.service.permission.ShoppingCategoryPermission;
023
024 import java.util.List;
025
026
029 public class ShoppingCategoryServiceImpl
030 extends ShoppingCategoryServiceBaseImpl {
031
032 @Override
033 public ShoppingCategory addCategory(
034 long parentCategoryId, String name, String description,
035 ServiceContext serviceContext)
036 throws PortalException {
037
038 ShoppingCategoryPermission.check(
039 getPermissionChecker(), serviceContext.getScopeGroupId(),
040 parentCategoryId, ActionKeys.ADD_CATEGORY);
041
042 return shoppingCategoryLocalService.addCategory(
043 getUserId(), parentCategoryId, name, description, serviceContext);
044 }
045
046 @Override
047 public void deleteCategory(long categoryId) throws PortalException {
048 ShoppingCategory category = shoppingCategoryLocalService.getCategory(
049 categoryId);
050
051 ShoppingCategoryPermission.check(
052 getPermissionChecker(), category, ActionKeys.DELETE);
053
054 shoppingCategoryLocalService.deleteCategory(categoryId);
055 }
056
057 @Override
058 public List<ShoppingCategory> getCategories(long groupId) {
059 return shoppingCategoryPersistence.filterFindByGroupId(groupId);
060 }
061
062 @Override
063 public List<ShoppingCategory> getCategories(
064 long groupId, long parentCategoryId, int start, int end) {
065
066 return shoppingCategoryPersistence.filterFindByG_P(
067 groupId, parentCategoryId, start, end);
068 }
069
070 @Override
071 public int getCategoriesCount(long groupId, long parentCategoryId) {
072 return shoppingCategoryPersistence.filterCountByG_P(
073 groupId, parentCategoryId);
074 }
075
076 @Override
077 public ShoppingCategory getCategory(long categoryId)
078 throws PortalException {
079
080 ShoppingCategory category = shoppingCategoryLocalService.getCategory(
081 categoryId);
082
083 ShoppingCategoryPermission.check(
084 getPermissionChecker(), category, ActionKeys.VIEW);
085
086 return category;
087 }
088
089 @Override
090 public void getSubcategoryIds(
091 List<Long> categoryIds, long groupId, long categoryId) {
092
093 List<ShoppingCategory> categories =
094 shoppingCategoryPersistence.filterFindByG_P(groupId, categoryId);
095
096 for (ShoppingCategory category : categories) {
097 categoryIds.add(category.getCategoryId());
098
099 getSubcategoryIds(
100 categoryIds, category.getGroupId(), category.getCategoryId());
101 }
102 }
103
104 @Override
105 public ShoppingCategory updateCategory(
106 long categoryId, long parentCategoryId, String name,
107 String description, boolean mergeWithParentCategory,
108 ServiceContext serviceContext)
109 throws PortalException {
110
111 ShoppingCategory category = shoppingCategoryLocalService.getCategory(
112 categoryId);
113
114 ShoppingCategoryPermission.check(
115 getPermissionChecker(), category, ActionKeys.UPDATE);
116
117 return shoppingCategoryLocalService.updateCategory(
118 categoryId, parentCategoryId, name, description,
119 mergeWithParentCategory, serviceContext);
120 }
121
122 }