@Test public void testIsCategoryHasSubcategory() { CategoryService categoryService = (CategoryService) ctx().getBean(ServiceSpringKeys.CATEGORY_SERVICE); assertTrue(categoryService.isCategoryHasSubcategory(300, 304)); assertTrue(categoryService.isCategoryHasSubcategory(301, 304)); assertFalse(categoryService.isCategoryHasSubcategory(301, 312)); assertFalse(categoryService.isCategoryHasSubcategory(50, 312)); assertFalse(categoryService.isCategoryHasSubcategory(50, 98)); assertFalse(categoryService.isCategoryHasSubcategory(300, 98)); assertFalse(categoryService.isCategoryHasSubcategory(304, 300)); assertFalse(categoryService.isCategoryHasSubcategory(411, 313)); }
@Override public boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId) { final Category start = proxy().getById(subCategoryId); if (start != null) { if (subCategoryId == topCategoryId) { return true; } else { final List<Category> list = new ArrayList<>(); list.add(start); addParent(list, topCategoryId); return list.get(list.size() - 1).getCategoryId() == topCategoryId; } } return false; }
CategoryServiceImpl extends BaseGenericServiceImpl<Category> implements CategoryService { @Override public boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId) { final Category start = proxy().getById(subCategoryId); if (start != null) { if (subCategoryId == topCategoryId) { return true; } else { final List<Category> list = new ArrayList<>(); list.add(start); addParent(list, topCategoryId); return list.get(list.size() - 1).getCategoryId() == topCategoryId; } } return false; } }
CategoryServiceImpl extends BaseGenericServiceImpl<Category> implements CategoryService { @Override public boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId) { final Category start = proxy().getById(subCategoryId); if (start != null) { if (subCategoryId == topCategoryId) { return true; } else { final List<Category> list = new ArrayList<>(); list.add(start); addParent(list, topCategoryId); return list.get(list.size() - 1).getCategoryId() == topCategoryId; } } return false; } CategoryServiceImpl(final GenericDAO<Category, Long> categoryDao,
                               final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); }
CategoryServiceImpl extends BaseGenericServiceImpl<Category> implements CategoryService { @Override public boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId) { final Category start = proxy().getById(subCategoryId); if (start != null) { if (subCategoryId == topCategoryId) { return true; } else { final List<Category> list = new ArrayList<>(); list.add(start); addParent(list, topCategoryId); return list.get(list.size() - 1).getCategoryId() == topCategoryId; } } return false; } CategoryServiceImpl(final GenericDAO<Category, Long> categoryDao,
                               final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); @Override Category getRootCategory(); @Override List<Long> getCategoryLinks(final long categoryId); @Override String getCategoryTemplate(final long categoryId); @Override String getCategorySearchTemplate(final long categoryId); @Override Long getCategoryProductTypeId(final long categoryId); @Override boolean isCategoryHasChildren(final long categoryId); @Override List<Category> getChildCategories(final long categoryId); @Override List<Category> findChildCategoriesWithAvailability(final long categoryId, final boolean withAvailability); @Override Set<Category> getChildCategoriesRecursive(final long categoryId); @Override Set<Long> getAllCategoryIds(final Collection<String> guids); @Override List<Long> getChildCategoriesRecursiveIds(final long categoryId); @Override List<Long> getChildCategoriesRecursiveIdsAndLinkIds(final long categoryId); @Override List<Category> findCategories(final int start, final int offset, final String sort, final boolean sortDescending, final Map<String, List> filter); @Override int findCategoryCount(final Map<String, List> filter); @Override List<Long> getCategoryIdAndLinkId(final long categoryId); @Override boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId); @Override Category getById(final long pk); @Override Long findCategoryIdBySeoUri(final String seoUri); @Override Long findCategoryIdByGUID(final String guid); @Override String findSeoUriByCategoryId(final Long categoryId); @Override Category findCategoryIdBySeoUriOrGuid(final String seoUriOrGuid); @Override List<Category> findByProductId(final long productId); CategoryService getSelf(); }
CategoryServiceImpl extends BaseGenericServiceImpl<Category> implements CategoryService { @Override public boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId) { final Category start = proxy().getById(subCategoryId); if (start != null) { if (subCategoryId == topCategoryId) { return true; } else { final List<Category> list = new ArrayList<>(); list.add(start); addParent(list, topCategoryId); return list.get(list.size() - 1).getCategoryId() == topCategoryId; } } return false; } CategoryServiceImpl(final GenericDAO<Category, Long> categoryDao,
                               final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); @Override Category getRootCategory(); @Override List<Long> getCategoryLinks(final long categoryId); @Override String getCategoryTemplate(final long categoryId); @Override String getCategorySearchTemplate(final long categoryId); @Override Long getCategoryProductTypeId(final long categoryId); @Override boolean isCategoryHasChildren(final long categoryId); @Override List<Category> getChildCategories(final long categoryId); @Override List<Category> findChildCategoriesWithAvailability(final long categoryId, final boolean withAvailability); @Override Set<Category> getChildCategoriesRecursive(final long categoryId); @Override Set<Long> getAllCategoryIds(final Collection<String> guids); @Override List<Long> getChildCategoriesRecursiveIds(final long categoryId); @Override List<Long> getChildCategoriesRecursiveIdsAndLinkIds(final long categoryId); @Override List<Category> findCategories(final int start, final int offset, final String sort, final boolean sortDescending, final Map<String, List> filter); @Override int findCategoryCount(final Map<String, List> filter); @Override List<Long> getCategoryIdAndLinkId(final long categoryId); @Override boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId); @Override Category getById(final long pk); @Override Long findCategoryIdBySeoUri(final String seoUri); @Override Long findCategoryIdByGUID(final String guid); @Override String findSeoUriByCategoryId(final Long categoryId); @Override Category findCategoryIdBySeoUriOrGuid(final String seoUriOrGuid); @Override List<Category> findByProductId(final long productId); CategoryService getSelf();  }