From fa8572bf67a0cdc4e1a466ec51401f75b59d3ccc Mon Sep 17 00:00:00 2001 From: Levente Santha Date: Thu, 30 Jul 2020 16:13:36 +0300 Subject: [PATCH 1/4] CIF-1549 - Catalog option 'Show landing page' / commerce tab does not show up under page properties * fixed commerce tab in catalog page properties * improved unit tests added IT --- .../PageTypeRenderConditionServlet.java | 18 +++- .../PageTypeRenderConditionServletTest.java | 36 ++++++++ .../resources/context/jcr-page-filter.json | 8 ++ .../it/http/CatalogPagePropertiesIT.java | 91 +++++++++++++++++++ .../page/v1/page/_cq_dialog/.content.xml | 3 + 5 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java diff --git a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java index 9e30f9a74c..dca618d630 100644 --- a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java +++ b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java @@ -14,6 +14,8 @@ package com.adobe.cq.commerce.core.components.internal.servlets; +import java.util.Arrays; + import javax.annotation.Nonnull; import javax.servlet.Servlet; @@ -32,8 +34,9 @@ import com.day.cq.wcm.api.PageManager; /** - * {@code PageTypeRenderConditionServlet} implements a {@code granite:rendercondition} used to decide if the product picker - * and category picker should be displayed in the page properties dialog of custom product pages and custom category pages. + * {@code PageTypeRenderConditionServlet} implements a {@code granite:rendercondition} used which evaluates to true for catalog pages, + * custom category pages and custom product pages. + * It requires the {@code pageType} parameter which should have one of the values: {@code catalog}, {@code category}, {@code product}. */ @Component( service = { Servlet.class }, @@ -51,6 +54,8 @@ public class PageTypeRenderConditionServlet extends SlingSafeMethodsServlet { private static final String PAGE_TYPE_PROPERTY = "pageType"; private static final String PAGE_TYPE_PRODUCT = "product"; private static final String PAGE_TYPE_CATEGORY = "category"; + private static final String PAGE_TYPE_CATALOG = "catalog"; + private static final String CATALOG_PAGE_RESOURCE_TYPE = "core/cif/components/structure/catalogpage/v1/catalogpage"; @Override protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) { @@ -64,6 +69,11 @@ private boolean checkPageType(SlingHttpServletRequest slingRequest, String pageT return false; } + if (!Arrays.asList(new String[] { PAGE_TYPE_CATALOG, PAGE_TYPE_CATEGORY, PAGE_TYPE_PRODUCT }).contains(pageType)) { + LOGGER.error("{} property has invalid value at {}: {}", PAGE_TYPE_PROPERTY, slingRequest.getResource().getPath(), pageType); + return false; + } + // the caller is a page properties dialog if (!StringUtils.contains(slingRequest.getPathInfo(), PAGE_PROPERTIES)) { return false; @@ -77,6 +87,10 @@ private boolean checkPageType(SlingHttpServletRequest slingRequest, String pageT return false; } + if (PAGE_TYPE_CATALOG.equals(pageType)) { + return page.hasContent() && page.getContentResource().isResourceType(CATALOG_PAGE_RESOURCE_TYPE); + } + Page parentPage = page.getParent(); if (parentPage == null) { return false; diff --git a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServletTest.java b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServletTest.java index 4582c7be2a..7ff55acb7c 100644 --- a/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServletTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServletTest.java @@ -81,6 +81,30 @@ public void testCategoryPage() { Assert.assertTrue(condition.check()); } + @Test + public void testCatalogPage() { + request.getResource().getValueMap().put("pageType", "catalog"); + request.setQueryString("item=/content/catalog-page"); + request.setPathInfo("/mnt/overlay/wcm/core/content/sites/properties.html"); + + servlet.doGet(request, null); + + SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName()); + Assert.assertTrue(condition.check()); + } + + @Test + public void testNotCatalogPage() { + request.getResource().getValueMap().put("pageType", "catalog"); + request.setQueryString("item=/content/category-page/sub-page"); + request.setPathInfo("/mnt/overlay/wcm/core/content/sites/properties.html"); + + servlet.doGet(request, null); + + SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName()); + Assert.assertFalse(condition.check()); + } + @Test public void testNotProductPage() { request.getResource().getValueMap().put("pageType", "product"); @@ -127,4 +151,16 @@ public void testNoPageType() { SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName()); Assert.assertFalse(condition.check()); } + + @Test + public void testInvalidPageType() { + request.getResource().getValueMap().put("pageType", "something"); + request.setQueryString("item=/content/product-page/sub-page"); + request.setPathInfo("/mnt/overlay/wcm/core/content/sites/properties.html"); + + servlet.doGet(request, null); + + SimpleRenderCondition condition = (SimpleRenderCondition) request.getAttribute(RenderCondition.class.getName()); + Assert.assertFalse(condition.check()); + } } diff --git a/bundles/core/src/test/resources/context/jcr-page-filter.json b/bundles/core/src/test/resources/context/jcr-page-filter.json index 5bcdaaa264..bd3b4ea1e6 100644 --- a/bundles/core/src/test/resources/context/jcr-page-filter.json +++ b/bundles/core/src/test/resources/context/jcr-page-filter.json @@ -33,5 +33,13 @@ "cq:template": "/conf/venia/settings/wcm/templates/anything-else" } } + }, + + "catalog-page": { + "jcr:primaryType": "cq:Page", + "jcr:content": { + "jcr:primaryType":"cq:PageContent", + "sling:resourceType": "core/cif/components/structure/catalogpage/v1/catalogpage" + } } } \ No newline at end of file diff --git a/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java b/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java new file mode 100644 index 0000000000..b8f42127e1 --- /dev/null +++ b/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * + * Copyright 2020 Adobe. All rights reserved. + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + * OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + * + ******************************************************************************/ + +package com.adobe.cq.commerce.it.http; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.NameValuePair; +import org.apache.http.message.BasicNameValuePair; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.select.Elements; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; + +import com.adobe.cq.testing.client.CQClient; +import com.adobe.cq.testing.client.CommerceClient; +import com.adobe.cq.testing.junit.rules.CQAuthorClassRule; + +import static org.apache.http.HttpStatus.SC_OK; + +public class CatalogPagePropertiesIT { + private static final String PAGE_PROPERTIES_URL = "/mnt/overlay/wcm/core/content/sites/properties.html"; + private static final String CATALOG_PAGE_RESOURCE_TYPE = "core/cif/components/structure/catalogpage/v1/catalogpage"; + private final String CATALOG_PAGE_PATH = "/content" + "/test-catalog-page"; + + @ClassRule + public static final CQAuthorClassRule cqBaseClassRule = new CQAuthorClassRule(); + private static CQClient adminAuthor; + + @BeforeClass + public static void init() { + adminAuthor = cqBaseClassRule.authorRule.getAdminClient(CommerceClient.class); + } + + @Before + public void setUp() throws Exception { + // Create catalog page + adminAuthor.createNode(CATALOG_PAGE_PATH, "cq:Page"); + adminAuthor.createNode(CATALOG_PAGE_PATH + "/jcr:content", "cq:PageContent"); + List props = new ArrayList<>(); + props.add(new BasicNameValuePair("sling:resourceType", CATALOG_PAGE_RESOURCE_TYPE)); + props.add(new BasicNameValuePair("jcr:title", "Test Catalog Page")); + adminAuthor.setPageProperties(CATALOG_PAGE_PATH, props, SC_OK); + } + + @Test + public void testCatalogPageProperties() throws Exception { + SlingHttpResponse response = adminAuthor.doGet(PAGE_PROPERTIES_URL + "?item=" + CATALOG_PAGE_PATH, SC_OK); + Document doc = Jsoup.parse(response.getContent()); + + // Check commerce tab exits + Elements elements = doc.select("coral-tab:contains(Commerce)"); + Assert.assertEquals(1, elements.size()); + + // Check label + elements = doc.select("coral-panel h3:contains(Catalog Page)"); + Assert.assertEquals(1, elements.size()); + + // Check checkbox for show catalog page + elements = doc.select("coral-panel coral-checkbox coral-checkbox-label:contains(Show catalog page)"); + Assert.assertEquals(1, elements.size()); + + // Check category picker + elements = doc.select("foundation-autocomplete[name=./magentoRootCategoryId"); + Assert.assertEquals(1, elements.size()); + } + + @After + public void tearDown() throws Exception { + // delete catalog page + adminAuthor.deletePath(CATALOG_PAGE_PATH, SC_OK); + } +} diff --git a/ui.apps/src/main/content/jcr_root/apps/core/cif/components/structure/page/v1/page/_cq_dialog/.content.xml b/ui.apps/src/main/content/jcr_root/apps/core/cif/components/structure/page/v1/page/_cq_dialog/.content.xml index 52a2519fd6..57cda81852 100644 --- a/ui.apps/src/main/content/jcr_root/apps/core/cif/components/structure/page/v1/page/_cq_dialog/.content.xml +++ b/ui.apps/src/main/content/jcr_root/apps/core/cif/components/structure/page/v1/page/_cq_dialog/.content.xml @@ -27,6 +27,9 @@ + From 3b98fb25502fe14b749f86a40c6ccae18a054f46 Mon Sep 17 00:00:00 2001 From: Levente Santha Date: Thu, 30 Jul 2020 16:38:15 +0300 Subject: [PATCH 2/4] CIF-1549 - Catalog option 'Show landing page' / commerce tab does not show up under page properties * fixing IT failure --- .../com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java b/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java index b8f42127e1..a127b7feab 100644 --- a/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java +++ b/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java @@ -79,7 +79,7 @@ public void testCatalogPageProperties() throws Exception { Assert.assertEquals(1, elements.size()); // Check category picker - elements = doc.select("foundation-autocomplete[name=./magentoRootCategoryId"); + elements = doc.select("section label:contains(Root category ID)"); Assert.assertEquals(1, elements.size()); } From 4cb3b45f688f4479e0fb6445e90328a231f30d5c Mon Sep 17 00:00:00 2001 From: Levente Santha Date: Thu, 30 Jul 2020 16:52:24 +0300 Subject: [PATCH 3/4] CIF-1549 - Catalog option 'Show landing page' / commerce tab does not show up under page properties * fixing IT failure --- .../adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java b/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java index a127b7feab..8f4f169420 100644 --- a/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java +++ b/it/http/src/test/java/com/adobe/cq/commerce/it/http/CatalogPagePropertiesIT.java @@ -77,10 +77,6 @@ public void testCatalogPageProperties() throws Exception { // Check checkbox for show catalog page elements = doc.select("coral-panel coral-checkbox coral-checkbox-label:contains(Show catalog page)"); Assert.assertEquals(1, elements.size()); - - // Check category picker - elements = doc.select("section label:contains(Root category ID)"); - Assert.assertEquals(1, elements.size()); } @After From 0d7081838bb16a7b8f33675b7c5809c0e1443e92 Mon Sep 17 00:00:00 2001 From: Levente Santha Date: Thu, 30 Jul 2020 17:19:03 +0300 Subject: [PATCH 4/4] CIF-1549 - Catalog option 'Show landing page' / commerce tab does not show up under page properties * fixed name of constants --- .../servlets/PageTypeRenderConditionServlet.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java index dca618d630..a6d8eb4cdf 100644 --- a/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java +++ b/bundles/core/src/main/java/com/adobe/cq/commerce/core/components/internal/servlets/PageTypeRenderConditionServlet.java @@ -52,9 +52,9 @@ public class PageTypeRenderConditionServlet extends SlingSafeMethodsServlet { private static final Logger LOGGER = LoggerFactory.getLogger(PageTypeRenderConditionServlet.class); private static final String PAGE_PROPERTIES = "wcm/core/content/sites/properties"; private static final String PAGE_TYPE_PROPERTY = "pageType"; - private static final String PAGE_TYPE_PRODUCT = "product"; - private static final String PAGE_TYPE_CATEGORY = "category"; - private static final String PAGE_TYPE_CATALOG = "catalog"; + private static final String PRODUCT_PAGE_TYPE = "product"; + private static final String CATEGORY_PAGE_TYPE = "category"; + private static final String CATALOG_PAGE_TYPE = "catalog"; private static final String CATALOG_PAGE_RESOURCE_TYPE = "core/cif/components/structure/catalogpage/v1/catalogpage"; @Override @@ -69,7 +69,7 @@ private boolean checkPageType(SlingHttpServletRequest slingRequest, String pageT return false; } - if (!Arrays.asList(new String[] { PAGE_TYPE_CATALOG, PAGE_TYPE_CATEGORY, PAGE_TYPE_PRODUCT }).contains(pageType)) { + if (!Arrays.asList(new String[] { CATALOG_PAGE_TYPE, CATEGORY_PAGE_TYPE, PRODUCT_PAGE_TYPE }).contains(pageType)) { LOGGER.error("{} property has invalid value at {}: {}", PAGE_TYPE_PROPERTY, slingRequest.getResource().getPath(), pageType); return false; } @@ -87,7 +87,7 @@ private boolean checkPageType(SlingHttpServletRequest slingRequest, String pageT return false; } - if (PAGE_TYPE_CATALOG.equals(pageType)) { + if (CATALOG_PAGE_TYPE.equals(pageType)) { return page.hasContent() && page.getContentResource().isResourceType(CATALOG_PAGE_RESOURCE_TYPE); } @@ -97,10 +97,10 @@ private boolean checkPageType(SlingHttpServletRequest slingRequest, String pageT } // perform the appropriate checks according to the pageType property - if (PAGE_TYPE_PRODUCT.equals(pageType)) { + if (PRODUCT_PAGE_TYPE.equals(pageType)) { Page productPage = SiteNavigation.getProductPage(page); return productPage != null && productPage.getPath().equals(parentPage.getPath()); - } else if (PAGE_TYPE_CATEGORY.equals(pageType)) { + } else if (CATEGORY_PAGE_TYPE.equals(pageType)) { Page categoryPage = SiteNavigation.getCategoryPage(page); return categoryPage != null && categoryPage.getPath().equals(parentPage.getPath()); }