@Test public void testResolveMainPanelRendererLabelCategoryNoTemplateNoProductsSubCats() throws Exception { final ShopService shopService = context.mock(ShopService.class, "shopService"); final CategoryService categoryService = context.mock(CategoryService.class, "categoryService"); final ShopSearchSupportService shopSearchSupportService = context.mock(ShopSearchSupportService.class, "shopSearchSupportService"); final ProductService productService = context.mock(ProductService.class, "productService"); final SearchQueryFactory searchQueryFactory = context.mock(SearchQueryFactory.class, "ftQueryFactory"); final NavigationContext hasProducts = context.mock(NavigationContext.class, "hasProducts"); CentralViewResolverCategoryImpl resolver = new CentralViewResolverCategoryImpl(shopService, categoryService, shopSearchSupportService, productService, searchQueryFactory); context.checking(new Expectations() {{ oneOf(shopService).getShopCategoryTemplate(11L, 10L); will(returnValue(" ")); oneOf(shopSearchSupportService).getSearchCategoriesIds(10L, 11L); will(returnValue(new Pair<>(Collections.singletonList(10L), false))); oneOf(searchQueryFactory).getFilteredNavigationQueryChain(11L, 11L, "en", Collections.singletonList(10L), false, null); will(returnValue(hasProducts)); oneOf(productService).getProductQty(hasProducts); will(returnValue(0)); oneOf(categoryService).isCategoryHasChildren(10L); will(returnValue(true)); }}); try { ApplicationDirector.setShoppingCart(CART_11); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.CATEGORY_ID, "10"); }}); assertNotNull(resolved); assertEquals(CentralViewLabel.SUBCATEGORIES_LIST, resolved.getFirst()); assertEquals(CentralViewLabel.SUBCATEGORIES_LIST, resolved.getSecond()); } finally { ApplicationDirector.clear(); } context.assertIsSatisfied(); }
@Override public Pair<String, String> resolveMainPanelRendererLabel(final Map parameters) { if (parameters.containsKey(WebParametersKeys.CATEGORY_ID)) { final long categoryId = NumberUtils.toLong(HttpUtil.getSingleValue(parameters.get(WebParametersKeys.CATEGORY_ID))); if (categoryId > 0L) { final ShoppingCart cart = ApplicationDirector.getShoppingCart(); final long shopId = cart.getShoppingContext().getShopId(); final long browsingShopId = cart.getShoppingContext().getCustomerShopId(); final String lang = cart.getCurrentLocale(); final String template = shopService.getShopCategoryTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(template)) { if (CentralViewLabel.PRODUCTS_LIST.equals(template)) { return DEFAULT_PL; } else if (CentralViewLabel.SUBCATEGORIES_LIST.equals(template)) { return DEFAULT_SC; } return new Pair<>(template, CentralViewLabel.CATEGORY); } final Pair<List<Long>, Boolean> catIds = determineSearchCategories(categoryId, browsingShopId); if (CollectionUtils.isEmpty(catIds.getFirst())) { return DEFAULT; } final NavigationContext hasProducts = searchQueryFactory.getFilteredNavigationQueryChain(shopId, browsingShopId, lang, catIds.getFirst(), catIds.getSecond(), null); if (productService.getProductQty(hasProducts) > 0) { final String searchTemplate = shopService.getShopCategorySearchTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(searchTemplate)) { return new Pair<>(searchTemplate, CentralViewLabel.PRODUCTS_LIST); } return DEFAULT_PL; } else if (categoryService.isCategoryHasChildren(categoryId)) { return DEFAULT_SC; } else { return DEFAULT; } } } return null; }
CentralViewResolverCategoryImpl implements CentralViewResolver { @Override public Pair<String, String> resolveMainPanelRendererLabel(final Map parameters) { if (parameters.containsKey(WebParametersKeys.CATEGORY_ID)) { final long categoryId = NumberUtils.toLong(HttpUtil.getSingleValue(parameters.get(WebParametersKeys.CATEGORY_ID))); if (categoryId > 0L) { final ShoppingCart cart = ApplicationDirector.getShoppingCart(); final long shopId = cart.getShoppingContext().getShopId(); final long browsingShopId = cart.getShoppingContext().getCustomerShopId(); final String lang = cart.getCurrentLocale(); final String template = shopService.getShopCategoryTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(template)) { if (CentralViewLabel.PRODUCTS_LIST.equals(template)) { return DEFAULT_PL; } else if (CentralViewLabel.SUBCATEGORIES_LIST.equals(template)) { return DEFAULT_SC; } return new Pair<>(template, CentralViewLabel.CATEGORY); } final Pair<List<Long>, Boolean> catIds = determineSearchCategories(categoryId, browsingShopId); if (CollectionUtils.isEmpty(catIds.getFirst())) { return DEFAULT; } final NavigationContext hasProducts = searchQueryFactory.getFilteredNavigationQueryChain(shopId, browsingShopId, lang, catIds.getFirst(), catIds.getSecond(), null); if (productService.getProductQty(hasProducts) > 0) { final String searchTemplate = shopService.getShopCategorySearchTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(searchTemplate)) { return new Pair<>(searchTemplate, CentralViewLabel.PRODUCTS_LIST); } return DEFAULT_PL; } else if (categoryService.isCategoryHasChildren(categoryId)) { return DEFAULT_SC; } else { return DEFAULT; } } } return null; } }
CentralViewResolverCategoryImpl implements CentralViewResolver { @Override public Pair<String, String> resolveMainPanelRendererLabel(final Map parameters) { if (parameters.containsKey(WebParametersKeys.CATEGORY_ID)) { final long categoryId = NumberUtils.toLong(HttpUtil.getSingleValue(parameters.get(WebParametersKeys.CATEGORY_ID))); if (categoryId > 0L) { final ShoppingCart cart = ApplicationDirector.getShoppingCart(); final long shopId = cart.getShoppingContext().getShopId(); final long browsingShopId = cart.getShoppingContext().getCustomerShopId(); final String lang = cart.getCurrentLocale(); final String template = shopService.getShopCategoryTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(template)) { if (CentralViewLabel.PRODUCTS_LIST.equals(template)) { return DEFAULT_PL; } else if (CentralViewLabel.SUBCATEGORIES_LIST.equals(template)) { return DEFAULT_SC; } return new Pair<>(template, CentralViewLabel.CATEGORY); } final Pair<List<Long>, Boolean> catIds = determineSearchCategories(categoryId, browsingShopId); if (CollectionUtils.isEmpty(catIds.getFirst())) { return DEFAULT; } final NavigationContext hasProducts = searchQueryFactory.getFilteredNavigationQueryChain(shopId, browsingShopId, lang, catIds.getFirst(), catIds.getSecond(), null); if (productService.getProductQty(hasProducts) > 0) { final String searchTemplate = shopService.getShopCategorySearchTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(searchTemplate)) { return new Pair<>(searchTemplate, CentralViewLabel.PRODUCTS_LIST); } return DEFAULT_PL; } else if (categoryService.isCategoryHasChildren(categoryId)) { return DEFAULT_SC; } else { return DEFAULT; } } } return null; } CentralViewResolverCategoryImpl(final ShopService shopService,
                                           final CategoryService categoryService,
                                           final ShopSearchSupportService shopSearchSupportService,
                                           final ProductService productService,
                                           final SearchQueryFactory searchQueryFactory); }
CentralViewResolverCategoryImpl implements CentralViewResolver { @Override public Pair<String, String> resolveMainPanelRendererLabel(final Map parameters) { if (parameters.containsKey(WebParametersKeys.CATEGORY_ID)) { final long categoryId = NumberUtils.toLong(HttpUtil.getSingleValue(parameters.get(WebParametersKeys.CATEGORY_ID))); if (categoryId > 0L) { final ShoppingCart cart = ApplicationDirector.getShoppingCart(); final long shopId = cart.getShoppingContext().getShopId(); final long browsingShopId = cart.getShoppingContext().getCustomerShopId(); final String lang = cart.getCurrentLocale(); final String template = shopService.getShopCategoryTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(template)) { if (CentralViewLabel.PRODUCTS_LIST.equals(template)) { return DEFAULT_PL; } else if (CentralViewLabel.SUBCATEGORIES_LIST.equals(template)) { return DEFAULT_SC; } return new Pair<>(template, CentralViewLabel.CATEGORY); } final Pair<List<Long>, Boolean> catIds = determineSearchCategories(categoryId, browsingShopId); if (CollectionUtils.isEmpty(catIds.getFirst())) { return DEFAULT; } final NavigationContext hasProducts = searchQueryFactory.getFilteredNavigationQueryChain(shopId, browsingShopId, lang, catIds.getFirst(), catIds.getSecond(), null); if (productService.getProductQty(hasProducts) > 0) { final String searchTemplate = shopService.getShopCategorySearchTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(searchTemplate)) { return new Pair<>(searchTemplate, CentralViewLabel.PRODUCTS_LIST); } return DEFAULT_PL; } else if (categoryService.isCategoryHasChildren(categoryId)) { return DEFAULT_SC; } else { return DEFAULT; } } } return null; } CentralViewResolverCategoryImpl(final ShopService shopService,
                                           final CategoryService categoryService,
                                           final ShopSearchSupportService shopSearchSupportService,
                                           final ProductService productService,
                                           final SearchQueryFactory searchQueryFactory); @Override Pair<String, String> resolveMainPanelRendererLabel(final Map parameters); }
CentralViewResolverCategoryImpl implements CentralViewResolver { @Override public Pair<String, String> resolveMainPanelRendererLabel(final Map parameters) { if (parameters.containsKey(WebParametersKeys.CATEGORY_ID)) { final long categoryId = NumberUtils.toLong(HttpUtil.getSingleValue(parameters.get(WebParametersKeys.CATEGORY_ID))); if (categoryId > 0L) { final ShoppingCart cart = ApplicationDirector.getShoppingCart(); final long shopId = cart.getShoppingContext().getShopId(); final long browsingShopId = cart.getShoppingContext().getCustomerShopId(); final String lang = cart.getCurrentLocale(); final String template = shopService.getShopCategoryTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(template)) { if (CentralViewLabel.PRODUCTS_LIST.equals(template)) { return DEFAULT_PL; } else if (CentralViewLabel.SUBCATEGORIES_LIST.equals(template)) { return DEFAULT_SC; } return new Pair<>(template, CentralViewLabel.CATEGORY); } final Pair<List<Long>, Boolean> catIds = determineSearchCategories(categoryId, browsingShopId); if (CollectionUtils.isEmpty(catIds.getFirst())) { return DEFAULT; } final NavigationContext hasProducts = searchQueryFactory.getFilteredNavigationQueryChain(shopId, browsingShopId, lang, catIds.getFirst(), catIds.getSecond(), null); if (productService.getProductQty(hasProducts) > 0) { final String searchTemplate = shopService.getShopCategorySearchTemplate(browsingShopId, categoryId); if (StringUtils.isNotBlank(searchTemplate)) { return new Pair<>(searchTemplate, CentralViewLabel.PRODUCTS_LIST); } return DEFAULT_PL; } else if (categoryService.isCategoryHasChildren(categoryId)) { return DEFAULT_SC; } else { return DEFAULT; } } } return null; } CentralViewResolverCategoryImpl(final ShopService shopService,
                                           final CategoryService categoryService,
                                           final ShopSearchSupportService shopSearchSupportService,
                                           final ProductService productService,
                                           final SearchQueryFactory searchQueryFactory); @Override Pair<String, String> resolveMainPanelRendererLabel(final Map parameters);  }