PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/apps/shopping/shopping-service/src/main/java/com/liferay/shopping/service/impl/ShoppingCategoryServiceImpl.java

http://github.com/liferay/liferay-portal
Java | 147 lines | 99 code | 32 blank | 16 comment | 1 complexity | 1944caafe526f038c7d50db883db8722 MD5 | raw file
Possible License(s): LGPL-2.0
  1. /**
  2. * Copyright (c) 2000-present 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. package com.liferay.shopping.service.impl;
  15. import com.liferay.portal.kernel.dao.orm.QueryDefinition;
  16. import com.liferay.portal.kernel.exception.PortalException;
  17. import com.liferay.portal.kernel.security.permission.ActionKeys;
  18. import com.liferay.portal.kernel.service.ServiceContext;
  19. import com.liferay.portal.kernel.util.OrderByComparator;
  20. import com.liferay.portal.kernel.workflow.WorkflowConstants;
  21. import com.liferay.portal.spring.extender.service.ServiceReference;
  22. import com.liferay.shopping.model.ShoppingCategory;
  23. import com.liferay.shopping.service.base.ShoppingCategoryServiceBaseImpl;
  24. import com.liferay.shopping.service.permission.ShoppingCategoryPermission;
  25. import java.util.List;
  26. /**
  27. * @author Brian Wing Shun Chan
  28. */
  29. public class ShoppingCategoryServiceImpl
  30. extends ShoppingCategoryServiceBaseImpl {
  31. @Override
  32. public ShoppingCategory addCategory(
  33. long parentCategoryId, String name, String description,
  34. ServiceContext serviceContext)
  35. throws PortalException {
  36. shoppingCategoryPermission.check(
  37. getPermissionChecker(), serviceContext.getScopeGroupId(),
  38. parentCategoryId, ActionKeys.ADD_CATEGORY);
  39. return shoppingCategoryLocalService.addCategory(
  40. getUserId(), parentCategoryId, name, description, serviceContext);
  41. }
  42. @Override
  43. public void deleteCategory(long categoryId) throws PortalException {
  44. ShoppingCategory category = shoppingCategoryLocalService.getCategory(
  45. categoryId);
  46. shoppingCategoryPermission.check(
  47. getPermissionChecker(), category, ActionKeys.DELETE);
  48. shoppingCategoryLocalService.deleteCategory(categoryId);
  49. }
  50. @Override
  51. public List<ShoppingCategory> getCategories(long groupId) {
  52. return shoppingCategoryPersistence.filterFindByGroupId(groupId);
  53. }
  54. @Override
  55. public List<ShoppingCategory> getCategories(
  56. long groupId, long parentCategoryId, int start, int end) {
  57. return shoppingCategoryPersistence.filterFindByG_P(
  58. groupId, parentCategoryId, start, end);
  59. }
  60. @Override
  61. public List<Object> getCategoriesAndItems(
  62. long groupId, long categoryId, int start, int end,
  63. OrderByComparator<?> obc) {
  64. QueryDefinition<?> queryDefinition = new QueryDefinition<>(
  65. WorkflowConstants.STATUS_ANY, start, end,
  66. (OrderByComparator<Object>)obc);
  67. return shoppingCategoryFinder.filterFindC_I_ByG_C(
  68. groupId, categoryId, queryDefinition);
  69. }
  70. @Override
  71. public int getCategoriesAndItemsCount(long groupId, long categoryId) {
  72. return shoppingCategoryFinder.countC_I_ByG_C(groupId, categoryId);
  73. }
  74. @Override
  75. public int getCategoriesCount(long groupId, long parentCategoryId) {
  76. return shoppingCategoryPersistence.filterCountByG_P(
  77. groupId, parentCategoryId);
  78. }
  79. @Override
  80. public ShoppingCategory getCategory(long categoryId)
  81. throws PortalException {
  82. ShoppingCategory category = shoppingCategoryLocalService.getCategory(
  83. categoryId);
  84. shoppingCategoryPermission.check(
  85. getPermissionChecker(), category, ActionKeys.VIEW);
  86. return category;
  87. }
  88. @Override
  89. public void getSubcategoryIds(
  90. List<Long> categoryIds, long groupId, long categoryId) {
  91. List<ShoppingCategory> categories =
  92. shoppingCategoryPersistence.filterFindByG_P(groupId, categoryId);
  93. for (ShoppingCategory category : categories) {
  94. categoryIds.add(category.getCategoryId());
  95. getSubcategoryIds(
  96. categoryIds, category.getGroupId(), category.getCategoryId());
  97. }
  98. }
  99. @Override
  100. public ShoppingCategory updateCategory(
  101. long categoryId, long parentCategoryId, String name,
  102. String description, boolean mergeWithParentCategory,
  103. ServiceContext serviceContext)
  104. throws PortalException {
  105. ShoppingCategory category = shoppingCategoryLocalService.getCategory(
  106. categoryId);
  107. shoppingCategoryPermission.check(
  108. getPermissionChecker(), category, ActionKeys.UPDATE);
  109. return shoppingCategoryLocalService.updateCategory(
  110. categoryId, parentCategoryId, name, description,
  111. mergeWithParentCategory, serviceContext);
  112. }
  113. @ServiceReference(type = ShoppingCategoryPermission.class)
  114. protected ShoppingCategoryPermission shoppingCategoryPermission;
  115. }