001
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 import java.util.List;
026
027
030 public class ShoppingCategoryServiceImpl
031 extends ShoppingCategoryServiceBaseImpl {
032
033 @Override
034 public ShoppingCategory addCategory(
035 long parentCategoryId, String name, String description,
036 ServiceContext serviceContext)
037 throws PortalException, SystemException {
038
039 ShoppingCategoryPermission.check(
040 getPermissionChecker(), serviceContext.getScopeGroupId(),
041 parentCategoryId, ActionKeys.ADD_CATEGORY);
042
043 return shoppingCategoryLocalService.addCategory(
044 getUserId(), parentCategoryId, name, description, serviceContext);
045 }
046
047 @Override
048 public void deleteCategory(long categoryId)
049 throws PortalException, SystemException {
050
051 ShoppingCategory category = shoppingCategoryLocalService.getCategory(
052 categoryId);
053
054 ShoppingCategoryPermission.check(
055 getPermissionChecker(), category, ActionKeys.DELETE);
056
057 shoppingCategoryLocalService.deleteCategory(categoryId);
058 }
059
060 @Override
061 public List<ShoppingCategory> getCategories(long groupId)
062 throws SystemException {
063
064 return shoppingCategoryPersistence.filterFindByGroupId(groupId);
065 }
066
067 @Override
068 public List<ShoppingCategory> getCategories(
069 long groupId, long parentCategoryId, int start, int end)
070 throws SystemException {
071
072 return shoppingCategoryPersistence.filterFindByG_P(
073 groupId, parentCategoryId, start, end);
074 }
075
076 @Override
077 public int getCategoriesCount(long groupId, long parentCategoryId)
078 throws SystemException {
079
080 return shoppingCategoryPersistence.filterCountByG_P(
081 groupId, parentCategoryId);
082 }
083
084 @Override
085 public ShoppingCategory getCategory(long categoryId)
086 throws PortalException, SystemException {
087
088 ShoppingCategory category = shoppingCategoryLocalService.getCategory(
089 categoryId);
090
091 ShoppingCategoryPermission.check(
092 getPermissionChecker(), category, ActionKeys.VIEW);
093
094 return category;
095 }
096
097 @Override
098 public void getSubcategoryIds(
099 List<Long> categoryIds, long groupId, long categoryId)
100 throws SystemException {
101
102 List<ShoppingCategory> categories =
103 shoppingCategoryPersistence.filterFindByG_P(groupId, categoryId);
104
105 for (ShoppingCategory category : categories) {
106 categoryIds.add(category.getCategoryId());
107
108 getSubcategoryIds(
109 categoryIds, category.getGroupId(), category.getCategoryId());
110 }
111 }
112
113 @Override
114 public ShoppingCategory updateCategory(
115 long categoryId, long parentCategoryId, String name,
116 String description, boolean mergeWithParentCategory,
117 ServiceContext serviceContext)
118 throws PortalException, SystemException {
119
120 ShoppingCategory category = shoppingCategoryLocalService.getCategory(
121 categoryId);
122
123 ShoppingCategoryPermission.check(
124 getPermissionChecker(), category, ActionKeys.UPDATE);
125
126 return shoppingCategoryLocalService.updateCategory(
127 categoryId, parentCategoryId, name, description,
128 mergeWithParentCategory, serviceContext);
129 }
130
131 }