@Test public void testGetShopCategoryParentId() throws Exception { assertEquals(Long.valueOf(411L), shopService.getShopCategoryParentId(70L, 313L, false)); assertEquals(Long.valueOf(411L), shopService.getShopCategoryParentId(70L, 313L, true)); assertNull(shopService.getShopCategoryParentId(70L, 312L, false)); assertEquals(Long.valueOf(401L), shopService.getShopCategoryParentId(70L, 312L, true)); assertEquals(Long.valueOf(312L), shopService.getShopCategoryParentId(80L, 313L, false)); assertEquals(Long.valueOf(312L), shopService.getShopCategoryParentId(80L, 313L, true)); assertEquals(Long.valueOf(311L), shopService.getShopCategoryParentId(80L, 312L, false)); assertEquals(Long.valueOf(311L), shopService.getShopCategoryParentId(80L, 312L, true)); assertNull(shopService.getShopCategoryParentId(50L, 313L, false)); assertNull(shopService.getShopCategoryParentId(50L, 313L, true)); assertNull(shopService.getShopCategoryParentId(50L, 312L, false)); assertNull(shopService.getShopCategoryParentId(50L, 312L, true)); }
@Override public Long getShopCategoryParentId(final long shopId, final long categoryId, final boolean includeDirectLinks) { final Set<Long> shopCatIds = getShopCategoriesIds(shopId); if (shopCatIds.contains(categoryId)) { final Category category = categoryService.getById(categoryId); if (category != null && !category.isRoot()) { if (includeDirectLinks) { final List<Long> directLinks = categoryService.getCategoryLinks(category.getCategoryId()); if (!directLinks.isEmpty()) { for (final Long linkId : directLinks) { if (shopCatIds.contains(linkId)) { final Category proxyCat = categoryService.getById(linkId); if (proxyCat != null && shopCatIds.contains(proxyCat.getParentId())) { return proxyCat.getParentId(); } } } } } final List<Long> parentLinks = categoryService.getCategoryLinks(category.getParentId()); if (!parentLinks.isEmpty()) { for (final Long linkId : parentLinks) { if (shopCatIds.contains(linkId)) { return linkId; } } } if (shopCatIds.contains(category.getParentId())) { return category.getParentId(); } } } return null; }
ShopServiceImpl extends BaseGenericServiceImpl<Shop> implements ShopService { @Override public Long getShopCategoryParentId(final long shopId, final long categoryId, final boolean includeDirectLinks) { final Set<Long> shopCatIds = getShopCategoriesIds(shopId); if (shopCatIds.contains(categoryId)) { final Category category = categoryService.getById(categoryId); if (category != null && !category.isRoot()) { if (includeDirectLinks) { final List<Long> directLinks = categoryService.getCategoryLinks(category.getCategoryId()); if (!directLinks.isEmpty()) { for (final Long linkId : directLinks) { if (shopCatIds.contains(linkId)) { final Category proxyCat = categoryService.getById(linkId); if (proxyCat != null && shopCatIds.contains(proxyCat.getParentId())) { return proxyCat.getParentId(); } } } } } final List<Long> parentLinks = categoryService.getCategoryLinks(category.getParentId()); if (!parentLinks.isEmpty()) { for (final Long linkId : parentLinks) { if (shopCatIds.contains(linkId)) { return linkId; } } } if (shopCatIds.contains(category.getParentId())) { return category.getParentId(); } } } return null; } }
ShopServiceImpl extends BaseGenericServiceImpl<Shop> implements ShopService { @Override public Long getShopCategoryParentId(final long shopId, final long categoryId, final boolean includeDirectLinks) { final Set<Long> shopCatIds = getShopCategoriesIds(shopId); if (shopCatIds.contains(categoryId)) { final Category category = categoryService.getById(categoryId); if (category != null && !category.isRoot()) { if (includeDirectLinks) { final List<Long> directLinks = categoryService.getCategoryLinks(category.getCategoryId()); if (!directLinks.isEmpty()) { for (final Long linkId : directLinks) { if (shopCatIds.contains(linkId)) { final Category proxyCat = categoryService.getById(linkId); if (proxyCat != null && shopCatIds.contains(proxyCat.getParentId())) { return proxyCat.getParentId(); } } } } } final List<Long> parentLinks = categoryService.getCategoryLinks(category.getParentId()); if (!parentLinks.isEmpty()) { for (final Long linkId : parentLinks) { if (shopCatIds.contains(linkId)) { return linkId; } } } if (shopCatIds.contains(category.getParentId())) { return category.getParentId(); } } } return null; } ShopServiceImpl(final GenericDAO<Shop, Long> shopDao,
                           final CategoryService categoryService,
                           final ContentService contentService,
                           final AttributeService attributeService,
                           final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); }
ShopServiceImpl extends BaseGenericServiceImpl<Shop> implements ShopService { @Override public Long getShopCategoryParentId(final long shopId, final long categoryId, final boolean includeDirectLinks) { final Set<Long> shopCatIds = getShopCategoriesIds(shopId); if (shopCatIds.contains(categoryId)) { final Category category = categoryService.getById(categoryId); if (category != null && !category.isRoot()) { if (includeDirectLinks) { final List<Long> directLinks = categoryService.getCategoryLinks(category.getCategoryId()); if (!directLinks.isEmpty()) { for (final Long linkId : directLinks) { if (shopCatIds.contains(linkId)) { final Category proxyCat = categoryService.getById(linkId); if (proxyCat != null && shopCatIds.contains(proxyCat.getParentId())) { return proxyCat.getParentId(); } } } } } final List<Long> parentLinks = categoryService.getCategoryLinks(category.getParentId()); if (!parentLinks.isEmpty()) { for (final Long linkId : parentLinks) { if (shopCatIds.contains(linkId)) { return linkId; } } } if (shopCatIds.contains(category.getParentId())) { return category.getParentId(); } } } return null; } ShopServiceImpl(final GenericDAO<Shop, Long> shopDao,
                           final CategoryService categoryService,
                           final ContentService contentService,
                           final AttributeService attributeService,
                           final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); @Override Shop getShopByOrderGuid(final String orderGuid); @Override Shop getShopByCode(final String shopCode); @Override List<Shop> getNonSubShops(); @Override Map<Long, Set<Long>> getAllShopsAndSubs(); @Override List<Shop> getSubShopsByMaster(final long masterId); @Override Shop getSubShopByNameAndMaster(final String shopName, final long masterId); @Override Shop getShopByOrderNum(final String orderNum); @Override Shop getById(final long shopId); @Override List<Shop> getAll(); @Override Shop getShopByDomainName(final String serverName); @Override Set<Long> getShopsCategoriesIds(final Collection<Long> shopId); @Override Set<Long> getShopCategoriesIds(final long shopId); @Override Set<Long> getShopsContentIds(final Collection<Long> shopId); @Override Set<Long> getShopContentIds(final long shopId); @Override Set<Long> getShopsAllCategoriesIds(final Collection<Long> shopId); @Override Set<Long> getShopAllCategoriesIds(final long shopId); Set<Long> transform(final Collection<Category> categories); @Override List<String> findAllSupportedCurrenciesByShops(); @Override Set<Category> getTopLevelCategories(final Long shopId); @Override Set<Category> findAllByShopId(final long shopId); @Override Category getDefaultNavigationCategory(final long shopId); @Override Long getShopCategoryParentId(final long shopId, final long categoryId, final boolean includeDirectLinks); @Override String getShopCategoryTemplate(final long shopId, final long categoryId); @Override String getShopCategorySearchTemplate(final long shopId, final long categoryId); @Override Long getShopCategoryProductTypeId(final long shopId, final long categoryId); @Override Long findShopIdByCode(final String code); @Override void updateAttributeValue(final long shopId, final String attributeKey, final String attributeValue); @Override Shop create(final Shop instance); ShopService getSelf(); }
ShopServiceImpl extends BaseGenericServiceImpl<Shop> implements ShopService { @Override public Long getShopCategoryParentId(final long shopId, final long categoryId, final boolean includeDirectLinks) { final Set<Long> shopCatIds = getShopCategoriesIds(shopId); if (shopCatIds.contains(categoryId)) { final Category category = categoryService.getById(categoryId); if (category != null && !category.isRoot()) { if (includeDirectLinks) { final List<Long> directLinks = categoryService.getCategoryLinks(category.getCategoryId()); if (!directLinks.isEmpty()) { for (final Long linkId : directLinks) { if (shopCatIds.contains(linkId)) { final Category proxyCat = categoryService.getById(linkId); if (proxyCat != null && shopCatIds.contains(proxyCat.getParentId())) { return proxyCat.getParentId(); } } } } } final List<Long> parentLinks = categoryService.getCategoryLinks(category.getParentId()); if (!parentLinks.isEmpty()) { for (final Long linkId : parentLinks) { if (shopCatIds.contains(linkId)) { return linkId; } } } if (shopCatIds.contains(category.getParentId())) { return category.getParentId(); } } } return null; } ShopServiceImpl(final GenericDAO<Shop, Long> shopDao,
                           final CategoryService categoryService,
                           final ContentService contentService,
                           final AttributeService attributeService,
                           final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); @Override Shop getShopByOrderGuid(final String orderGuid); @Override Shop getShopByCode(final String shopCode); @Override List<Shop> getNonSubShops(); @Override Map<Long, Set<Long>> getAllShopsAndSubs(); @Override List<Shop> getSubShopsByMaster(final long masterId); @Override Shop getSubShopByNameAndMaster(final String shopName, final long masterId); @Override Shop getShopByOrderNum(final String orderNum); @Override Shop getById(final long shopId); @Override List<Shop> getAll(); @Override Shop getShopByDomainName(final String serverName); @Override Set<Long> getShopsCategoriesIds(final Collection<Long> shopId); @Override Set<Long> getShopCategoriesIds(final long shopId); @Override Set<Long> getShopsContentIds(final Collection<Long> shopId); @Override Set<Long> getShopContentIds(final long shopId); @Override Set<Long> getShopsAllCategoriesIds(final Collection<Long> shopId); @Override Set<Long> getShopAllCategoriesIds(final long shopId); Set<Long> transform(final Collection<Category> categories); @Override List<String> findAllSupportedCurrenciesByShops(); @Override Set<Category> getTopLevelCategories(final Long shopId); @Override Set<Category> findAllByShopId(final long shopId); @Override Category getDefaultNavigationCategory(final long shopId); @Override Long getShopCategoryParentId(final long shopId, final long categoryId, final boolean includeDirectLinks); @Override String getShopCategoryTemplate(final long shopId, final long categoryId); @Override String getShopCategorySearchTemplate(final long shopId, final long categoryId); @Override Long getShopCategoryProductTypeId(final long shopId, final long categoryId); @Override Long findShopIdByCode(final String code); @Override void updateAttributeValue(final long shopId, final String attributeKey, final String attributeValue); @Override Shop create(final Shop instance); ShopService getSelf();  }