com.day.cq.wcm.api.Page Java Examples

The following examples show how to use com.day.cq.wcm.api.Page. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CatalogSearchSupport.java    From commerce-cif-connector with Apache License 2.0 7 votes vote down vote up
/**
 * Searches for the {@link #PN_CATALOG_PATH} property at the specified path or its parent pages.
 *
 * @param path a path in the content repository
 * @return the value of the {@link #PN_CATALOG_PATH} property or {@code null} if not found
 */
public String findCatalogPath(String path) {
    if (StringUtils.isBlank(path)) {
        return null;
    }
    Page parentPage = resolver.adaptTo(PageManager.class).getContainingPage(path);
    if (parentPage == null) {
        return null;
    }

    ConfigurationBuilder configBuilder = parentPage.getContentResource().adaptTo(ConfigurationBuilder.class);
    if (configBuilder != null) {
        ValueMap properties = configBuilder.name(CLOUDCONFIGS_BUCKET_NAME + "/" + COMMERCE_CONFIG_NAME).asValueMap();
        if (properties.containsKey(PN_CATALOG_PATH)) {
            return properties.get(PN_CATALOG_PATH, String.class);
        }
    }

    InheritanceValueMap inheritedProperties = new HierarchyNodeInheritanceValueMap(parentPage.getContentResource());
    return inheritedProperties.getInherited(PN_CATALOG_PATH, String.class);
}
 
Example #2
Source File: AEMDataLayerConfig.java    From AEM-DataLayer with Apache License 2.0 7 votes vote down vote up
/**
 * Retrieves the DataLayer config for the page or none if it is not
 * configured for that page or any inherited page.
 * 
 * @param page
 *            the page for which to get the data layer configuration
 * @return the DataLayer configuration
 */
public static AEMDataLayerConfig getDataLayerConfig(Page page) {
	if (page != null) {
		log.trace("Finding Digital Data config for {}", page.getPath());
		InheritanceValueMap properties = new HierarchyNodeInheritanceValueMap(page.getContentResource());
		String[] cloudServices = properties.getInherited(DataLayerConstants.PN_CLOUD_SERVICE_CONFIGS, new String[0]);
		for (String cloudService : cloudServices) {
			if (cloudService.startsWith(DataLayerConstants.AEM_DATALAYER_CONFIG_PATH)) {
				Page cloudServicePage = page.getPageManager().getContainingPage(cloudService);
				if (cloudServicePage != null) {
					return cloudServicePage.getContentResource().adaptTo(AEMDataLayerConfig.class);
				} else {
					log.warn("DataLayer cloud service not found at {}", cloudService);
				}
			}
		}
		log.debug("No Digital Data config found for {}", page.getPath());
	}
	return null;

}
 
Example #3
Source File: ProductTeaserImplTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyProductTeaserNoGraphqlCLient() {
    Page page = context.currentPage(PAGE);
    context.currentResource(PRODUCTTEASER_NOCLIENT);
    Resource teaserResource = Mockito.spy(context.resourceResolver().getResource(PRODUCTTEASER_NOCLIENT));
    Mockito.when(teaserResource.adaptTo(GraphqlClient.class)).thenReturn(null);

    // This sets the page attribute injected in the models with @Inject or @ScriptVariable
    SlingBindings slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
    slingBindings.setResource(teaserResource);
    slingBindings.put(WCMBindingsConstants.NAME_CURRENT_PAGE, page);
    slingBindings.put(WCMBindingsConstants.NAME_PROPERTIES, teaserResource.getValueMap());

    ProductTeaserImpl productTeaserNoClient = context.request().adaptTo(ProductTeaserImpl.class);

    Assert.assertNull(productTeaserNoClient.getProductRetriever());
    Assert.assertNull(productTeaserNoClient.getUrl());
}
 
Example #4
Source File: SiteNavigation.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
/**
 * Builds and returns a product page URL based on the given page, slug, and variant sku.
 * This method might return the URL of a specific subpage configured for that particular page.
 * 
 * @param page The page used to build the URL.
 * @param slug The slug of the product.
 * @param variantSku An optional sku of the variant that will be "selected" on the product page, can be null.
 * @return The product page URL.
 * @deprecated Use {@link UrlProvider#toProductUrl(SlingHttpServletRequest, Page, Map)}
 */
@Deprecated
public String toProductUrl(Page page, String slug, String variantSku) {
    Resource pageResource = page.adaptTo(Resource.class);
    boolean deepLink = !WCMMode.DISABLED.equals(WCMMode.fromRequest(request));
    if (deepLink) {
        Resource subPageResource = UrlProviderImpl.toSpecificPage(pageResource, slug);
        if (subPageResource != null) {
            pageResource = subPageResource;
        }
    }

    if (StringUtils.isNotBlank(variantSku)) {
        return String.format("%s.%s.html%s%s", pageResource.getPath(), slug, COMBINED_SKU_SEPARATOR, variantSku);
    } else {
        return String.format("%s.%s.html", pageResource.getPath(), slug);
    }
}
 
Example #5
Source File: RelatedProductsImplTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
private void assertProducts() {
    List<ProductListItem> items = relatedProducts.getProducts();
    Assert.assertFalse(items.isEmpty());
    NumberFormat priceFormatter = NumberFormat.getCurrencyInstance(Locale.US);

    for (int i = 0; i < items.size(); i++) {
        ProductListItem item = items.get(i);
        ProductInterface product = products.get(i);

        Assert.assertEquals(product.getName(), item.getTitle());
        Assert.assertEquals(product.getSku(), item.getSKU());
        Assert.assertEquals(product.getUrlKey(), item.getSlug());

        Page productPage = context.pageManager().getPage(PRODUCT_PAGE);
        SiteNavigation siteNavigation = new SiteNavigation(context.request());
        Assert.assertEquals(siteNavigation.toPageUrl(productPage, product.getUrlKey()), item.getURL());

        Money amount = product.getPriceRange().getMinimumPrice().getFinalPrice();
        Assert.assertEquals(amount.getValue(), item.getPrice(), 0);
        Assert.assertEquals(amount.getCurrency().toString(), item.getCurrency());
        priceFormatter.setCurrency(Currency.getInstance(amount.getCurrency().toString()));
        Assert.assertEquals(priceFormatter.format(amount.getValue()), item.getFormattedPrice());

        Assert.assertEquals(product.getThumbnail().getUrl(), item.getImageURL());
    }
}
 
Example #6
Source File: GraphQLCategoryProviderTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetChildCategories() throws IOException {
    Page page = spy(context.currentPage("/content/pageA"));
    Resource pageContent = spy(page.getContentResource());
    when(page.getContentResource()).thenReturn(pageContent);

    when(pageContent.adaptTo(GraphqlClient.class)).thenReturn(graphqlClient);
    when(pageContent.adaptTo(ComponentsConfiguration.class)).thenReturn(MOCK_CONFIGURATION_OBJECT);

    GraphQLCategoryProvider categoryProvider = new GraphQLCategoryProvider(page
        .getContentResource(), null);

    // Test null categoryId
    Assert.assertTrue(categoryProvider.getChildCategories(null, 5).isEmpty());

    // Test category children found
    List<CategoryTree> categories = categoryProvider.getChildCategories(2, 5);
    Assert.assertEquals(6, categories.size());
}
 
Example #7
Source File: NavigationImplTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
private void initCatalogPage(boolean catalogRoot, boolean showMainCategories, boolean useCaConfig) {
    Page catalogPage = mock(Page.class);
    Resource catalogPageContent = mock(Resource.class);
    when(catalogPageContent.isResourceType(RT_CATALOG_PAGE)).thenReturn(catalogRoot);
    Map<String, Object> catalogPageProperties = new HashMap<>();
    catalogPageProperties.put(PN_SHOW_MAIN_CATEGORIES, showMainCategories);

    if (!useCaConfig) {
        catalogPageProperties.put(PN_MAGENTO_ROOT_CATEGORY_ID, 4);
    }
    when(catalogPageContent.adaptTo(ComponentsConfiguration.class)).thenReturn(new ComponentsConfiguration(new ValueMapDecorator(
        ImmutableMap.of(PN_MAGENTO_ROOT_CATEGORY_ID, 4))));
    when(catalogPageContent.getValueMap()).thenReturn(new ValueMapDecorator(catalogPageProperties));
    when(catalogPage.getContentResource()).thenReturn(catalogPageContent);
    when(catalogPage.getPath()).thenReturn("/content/catalog");
    when(catalogPageContent.getPath()).thenReturn("/content/catalog/jcr:content");
    ResourceResolver mockResourceResolver = mock(ResourceResolver.class);
    when(mockResourceResolver.getResource(any(String.class))).thenReturn(null);
    when(catalogPageContent.getResourceResolver()).thenReturn(mockResourceResolver);
    when(pageManager.getPage(CATALOG_PAGE_PATH)).thenReturn(catalogPage);

    ValueMap configProperties = new ValueMapDecorator(ImmutableMap.of(PN_MAGENTO_ROOT_CATEGORY_ID, 4));

    when(catalogPage.adaptTo(ComponentsConfiguration.class)).thenReturn(new ComponentsConfiguration(configProperties));
}
 
Example #8
Source File: ProductGridItem.java    From AEM-DataLayer with Apache License 2.0 6 votes vote down vote up
@Override
public void updateDataLayer(DataLayer dataLayer) {

	com.perficient.aem.datalayer.api.Product product = new com.perficient.aem.datalayer.api.Product();
	ProductInfo productInfo = product.getProductInfo();
	productInfo.setDescription(productData.getDescription());
	productInfo.setProductID(productData.getPath());
	productInfo.setProductImage(dataLayer.getConfig().getUrlPrefix() + productData.getImageUrl());
	productInfo.setProductName(productData.getTitle());
	productInfo.setProductThumbnail(dataLayer.getConfig().getUrlPrefix() + productData.getThumbnailUrl());
	Page page = dataLayer.getAEMPage();
	productInfo.setProductURL(DataLayerUtil.getSiteUrl(page, dataLayer.getConfig()));
	productInfo.setSku(productData.getSKU());
	product.setProductInfo(productInfo);
	product.addAttribute("displayType", "productgrid/item");
	dataLayer.addProduct(product);

	Component component = new Component();
	component.getComponentInfo().setComponentID(resource.getPath());
	component.addAttribute("type", "productgrid/item");
	component.addAttribute("productID", productData.getPath());
	dataLayer.addComponent(component);
}
 
Example #9
Source File: MagentoGraphqlClientTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
@Test
public void testMagentoStorePropertyWithConfigBuilder() {
    /*
     * The content for this test looks slightly different than it does in AEM:
     * In AEM there the tree structure is /conf/<config>/settings/cloudconfigs/commerce/jcr:content
     * In our test content it's /conf/<config>/settings/cloudconfigs/commerce
     * The reason is that AEM has a specific CaConfig API implementation that reads the configuration
     * data from the jcr:content node of the configuration page, something which we cannot reproduce in
     * a unit test scenario.
     */
    Page pageWithConfig = Mockito.spy(context.pageManager().getPage("/content/pageG"));
    Resource pageResource = Mockito.spy(pageWithConfig.adaptTo(Resource.class));
    when(pageWithConfig.adaptTo(Resource.class)).thenReturn(pageResource);
    when(pageResource.adaptTo(GraphqlClient.class)).thenReturn(graphqlClient);
    when(pageResource.adaptTo(ComponentsConfiguration.class)).thenReturn(MOCK_CONFIGURATION_OBJECT);

    MagentoGraphqlClient client = MagentoGraphqlClient.create(pageWithConfig
        .adaptTo(Resource.class), pageWithConfig);
    Assert.assertNotNull("GraphQL client created successfully", client);
    executeAndCheck(true, client);
}
 
Example #10
Source File: ProductComponent.java    From AEM-DataLayer with Apache License 2.0 6 votes vote down vote up
@Override
public void updateDataLayer(DataLayer dataLayer) {

	com.perficient.aem.datalayer.api.Product product = new com.perficient.aem.datalayer.api.Product();
	ProductInfo productInfo = product.getProductInfo();
	productInfo.setDescription(productData.getDescription());
	productInfo.setProductID(productData.getPath());
	productInfo.setProductImage(dataLayer.getConfig().getUrlPrefix() + productData.getImageUrl());
	productInfo.setProductName(productData.getTitle());
	productInfo.setProductThumbnail(dataLayer.getConfig().getUrlPrefix() + productData.getThumbnailUrl());
	Page page = resource.getResourceResolver().adaptTo(PageManager.class).getContainingPage(resource);
	productInfo.setProductURL(DataLayerUtil.getSiteUrl(page, dataLayer.getConfig()));
	productInfo.setSku(productData.getSKU());
	product.setProductInfo(productInfo);
	dataLayer.addProduct(product);
	
	Component component = new Component();
	component.getComponentInfo().setComponentID(resource.getPath());
	component.addAttribute("type", "product");
	dataLayer.addComponent(component);
}
 
Example #11
Source File: ContentResourceShouldBeNullCheckedCheck.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
private void correctlyNullCheckedContentResource(Resource resource1, Resource resource2) {
  Page page1 = resource1.adaptTo(Page.class);
  Page page2 = resource2.adaptTo(Page.class);
  Resource contentResource1 = page1.getContentResource();
  Resource contentResource2 = page2.getContentResource();
  Iterable<Resource> children = null;
  if (contentResource1 != null) {
    children = contentResource1.getChildren();
    if (contentResource2 != null) {
      children = contentResource1.getChildren();
    }
    children = contentResource1.getChildren();
  } else if (contentResource2 != null) {
    children = contentResource2.getChildren();
  }
}
 
Example #12
Source File: ProductCarouselImplTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    Page page = context.currentPage(PAGE);
    context.currentResource(PRODUCTCAROUSEL);
    carouselResource = Mockito.spy(context.resourceResolver().getResource(PRODUCTCAROUSEL));

    Query rootQuery = Utils.getQueryFromResource("graphql/magento-graphql-productcarousel-result.json");
    products = rootQuery.getProducts().getItems();

    GraphqlClient graphqlClient = Utils.setupGraphqlClientWithHttpResponseFrom("graphql/magento-graphql-productcarousel-result.json");
    Mockito.when(carouselResource.adaptTo(ComponentsConfiguration.class)).thenReturn(MOCK_CONFIGURATION_OBJECT);
    context.registerAdapter(Resource.class, GraphqlClient.class, (Function<Resource, GraphqlClient>) input -> input.getValueMap().get(
        "cq:graphqlClient") != null ? graphqlClient : null);

    // This sets the page attribute injected in the models with @Inject or @ScriptVariable
    SlingBindings slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
    slingBindings.setResource(carouselResource);
    slingBindings.put(WCMBindingsConstants.NAME_CURRENT_PAGE, page);

    productSkuArray = (String[]) carouselResource.getValueMap().get("product"); // The HTL script uses an alias here
    slingBindings.put("productSkuList", productSkuArray);

    productCarousel = context.request().adaptTo(ProductCarouselImpl.class);
}
 
Example #13
Source File: ProductTeaserImplTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
@Test
public void testVirtualProduct() throws IOException {
    Page page = context.currentPage(PAGE);
    context.currentResource(PRODUCTTEASER_VIRTUAL);
    Resource teaserResource = Mockito.spy(context.resourceResolver().getResource(PRODUCTTEASER_VIRTUAL));
    Mockito.when(teaserResource.adaptTo(ComponentsConfiguration.class)).thenReturn(MOCK_CONFIGURATION_OBJECT);

    GraphqlClient graphqlClient = Utils.setupGraphqlClientWithHttpResponseFrom("graphql/magento-graphql-virtualproduct-result.json");
    context.registerAdapter(Resource.class, GraphqlClient.class, (Function<Resource, GraphqlClient>) input -> input.getValueMap().get(
        "cq:graphqlClient", String.class) != null ? graphqlClient : null);

    SlingBindings slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
    slingBindings.setResource(teaserResource);
    slingBindings.put(WCMBindingsConstants.NAME_CURRENT_PAGE, page);
    slingBindings.put(WCMBindingsConstants.NAME_PROPERTIES, teaserResource.getValueMap());

    productTeaser = context.request().adaptTo(ProductTeaserImpl.class);
    Assert.assertTrue(productTeaser.isVirtualProduct());
}
 
Example #14
Source File: NavigationImpl.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
private void addItems(PageManager pageManager, AbstractNavigationItem parent,
    com.adobe.cq.wcm.core.components.models.NavigationItem currentWcmItem, List<NavigationItem> itemList) {
    Page page = pageManager.getPage(currentWcmItem.getPath());
    if (shouldExpandCatalogRoot(page)) {
        expandCatalogRoot(page, itemList);
    } else {
        NavigationItem item;
        if (isCatalogRoot(page)) {
            item = new CatalogPageNavigationItem(null, page, currentWcmItem);
        } else {
            String title = currentWcmItem.getTitle();
            String url = currentWcmItem.getURL();
            boolean active = currentWcmItem.isActive();
            item = new PageNavigationItem(parent, title, url, active, currentWcmItem);
        }
        itemList.add(item);
    }
}
 
Example #15
Source File: ProductTeaserImplTest.java    From aem-core-cif-components with Apache License 2.0 6 votes vote down vote up
public void verifyProduct(String resourcePath) throws Exception {
    setUp(resourcePath, true);

    Assert.assertEquals(product.getName(), productTeaser.getName());
    Page productPage = context.pageManager().getPage(PRODUCT_PAGE);

    // There is a dedicated specific subpage for that product
    Assert.assertTrue(productTeaser.getUrl().startsWith(PRODUCT_SPECIFIC_PAGE));
    SiteNavigation siteNavigation = new SiteNavigation(context.request());
    Assert.assertEquals(siteNavigation.toPageUrl(productPage, product.getUrlKey()), productTeaser.getUrl());

    NumberFormat priceFormatter = NumberFormat.getCurrencyInstance(Locale.US);
    Money amount = product.getPriceRange().getMinimumPrice().getFinalPrice();
    priceFormatter.setCurrency(Currency.getInstance(amount.getCurrency().toString()));
    Assert.assertEquals(priceFormatter.format(amount.getValue()), productTeaser.getFormattedPrice());

    Assert.assertEquals(product.getImage().getUrl(), productTeaser.getImage());
}
 
Example #16
Source File: GraphqlProductViewHandlerTest.java    From commerce-cif-connector with Apache License 2.0 6 votes vote down vote up
@Test
public void testCategoryConstraintSearchQuery() throws RepositoryException {
    Mockito.when(servletRequest.getHeader("Referer")).thenReturn("editor.html/test/page.html");
    PageManager pageManager = Mockito.mock(PageManager.class);
    Mockito.when(resourceResolver.adaptTo(PageManager.class)).thenReturn(pageManager);
    Page page = Mockito.mock(Page.class);
    Mockito.when(pageManager.getContainingPage("/test/page")).thenReturn(page);
    Resource contentResource = Mockito.mock(Resource.class);
    Mockito.when(page.getContentResource()).thenReturn(contentResource);
    ModifiableValueMapDecorator valueMap = new ModifiableValueMapDecorator(new HashMap<>());
    Mockito.when(contentResource.getValueMap()).thenReturn(valueMap);
    valueMap.put(PN_CATALOG_PATH, "/catalog/path");
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resourceResolver.getResource("/catalog/path")).thenReturn(resource);
    ModifiableValueMapDecorator properties = new ModifiableValueMapDecorator(new HashMap<>());
    Mockito.when(resource.getValueMap()).thenReturn(properties);
    properties.put("cq:commerceType", "category");
    properties.put("cifId", "1");

    ViewQuery viewQuery = viewHandler.createQuery(servletRequest, null, "query=trail");
    PredicateGroup predicateGroup = ((GraphqlProductViewHandler.GQLViewQuery) viewQuery).predicateGroup;
    Assert.assertNotNull(predicateGroup.getByName("3_" + CATEGORY_ID_PARAMETER));
    Assert.assertEquals(predicateGroup.getByName("3_" + CATEGORY_ID_PARAMETER).get(CATEGORY_ID_PARAMETER), "1");
    Assert.assertNotNull(predicateGroup.getByName("4_" + CATEGORY_PATH_PARAMETER));
    Assert.assertEquals(predicateGroup.getByName("4_" + CATEGORY_PATH_PARAMETER).get(CATEGORY_PATH_PARAMETER), "/catalog/path");
}
 
Example #17
Source File: IsProductListPageServlet.java    From commerce-cif-connector with Apache License 2.0 6 votes vote down vote up
private boolean isProductListPage(String path, ResourceResolver resourceResolver) {
    if (StringUtils.isBlank(path)) {
        return false;
    }

    Resource resource = resourceResolver.resolve(path);
    if (resource instanceof NonExistingResource) {
        return false;
    }

    Page page = resourceResolver.adaptTo(PageManager.class).getPage(resource.getPath());
    if (page == null) {
        return false;
    }

    Resource pageContent = page.getContentResource();
    if (pageContent == null) {
        return false;
    }

    boolean val = containsComponent(PRODUCT_LIST_RT, pageContent);

    return val;
}
 
Example #18
Source File: ProductListItemImpl.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
public ProductListItemImpl(String sku, String slug, String name, Price price, String imageURL, Page productPage,
                           String activeVariantSku, SlingHttpServletRequest request, UrlProvider urlProvider) {
    this.sku = sku;
    this.slug = slug;
    this.name = name;
    this.imageURL = imageURL;
    this.price = price;
    this.productPage = productPage;
    this.activeVariantSku = activeVariantSku;
    this.request = request;
    this.urlProvider = urlProvider;
}
 
Example #19
Source File: SiteNavigationTest.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNavigationRootPage() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(SiteNavigation.PN_NAV_ROOT, true);
    Page navRootPage = mockPage(properties);
    Page page0 = mockPage(null);
    Page page1 = mockPage(null);
    when(page0.getParent()).thenReturn(page1);
    when(page1.getParent()).thenReturn(navRootPage);
    Page page2 = mockPage(null);
    Page page3 = mockPage(null);
    when(page2.getParent()).thenReturn(page3);

    // returns null for null
    Assert.assertNull(SiteNavigation.getNavigationRootPage(null));

    // returns navigation root for navigation root
    Assert.assertSame(navRootPage, SiteNavigation.getNavigationRootPage(navRootPage));

    // returns navigation root for navigation root child
    Assert.assertSame(navRootPage, SiteNavigation.getNavigationRootPage(page1));

    // returns navigation root for child of navigation root child
    Assert.assertSame(navRootPage, SiteNavigation.getNavigationRootPage(page0));

    // returns null for page with no parent
    Assert.assertNull(SiteNavigation.getNavigationRootPage(page3));

    // returns null for page with no navigation root parent
    Assert.assertNull(SiteNavigation.getNavigationRootPage(page2));
}
 
Example #20
Source File: NavigationImpl.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
private boolean isCatalogRoot(Page page) {
    if (!isCatalogPage(page)) {
        return false;
    }

    Boolean showMainCategories = page.getContentResource().getValueMap().get(PN_SHOW_MAIN_CATEGORIES, Boolean.TRUE);
    return !showMainCategories;
}
 
Example #21
Source File: ProductCollectionImplTest.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
private SlingBindings getSlingBindings(String resourcePath) {
    Page page = context.currentPage(PAGE);
    Resource productCollectionResource = context.resourceResolver().getResource(resourcePath);
    SlingBindings slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
    slingBindings.setResource(productCollectionResource);
    slingBindings.put(WCMBindingsConstants.NAME_CURRENT_PAGE, page);
    slingBindings.put(WCMBindingsConstants.NAME_PROPERTIES, productCollectionResource.getValueMap());
    return slingBindings;
}
 
Example #22
Source File: PageManagerImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(Page page, boolean shallow, boolean autoSave) throws WCMException {
    if (page == null) return;

    if (!shallow) delete(page.adaptTo(Resource.class), false, autoSave);
    else delete(page.getContentResource(), true, autoSave);
}
 
Example #23
Source File: CommerceTeaserActionItem.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
public CommerceTeaserActionItem(String title, String selector, Page page, SlingHttpServletRequest request, UrlProvider urlProvider,
                                boolean isProduct) {
    this.title = title;
    this.selector = selector;
    this.page = page;
    this.request = request;
    this.urlProvider = urlProvider;
    this.isProduct = isProduct;
}
 
Example #24
Source File: ProductTeaserImplTest.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyProductVariant() throws Exception {
    setUp(PRODUCTTEASER_VARIANT, false);

    // Find the selected variant
    ConfigurableProduct cp = (ConfigurableProduct) product;
    String selection = teaserResource.getValueMap().get("selection", String.class);
    String variantSku = SiteNavigation.toProductSkus(selection).getRight();
    SimpleProduct variant = cp.getVariants()
        .stream()
        .map(v -> v.getProduct())
        .filter(sp -> variantSku.equals(sp.getSku()))
        .findFirst()
        .orElse(null);

    Assert.assertEquals(variant.getName(), productTeaser.getName());
    Page productPage = context.pageManager().getPage(PRODUCT_PAGE);
    SiteNavigation siteNavigation = new SiteNavigation(context.request());
    Assert.assertEquals(siteNavigation.toProductUrl(productPage, product.getUrlKey(), variantSku), productTeaser.getUrl());

    NumberFormat priceFormatter = NumberFormat.getCurrencyInstance(Locale.US);
    Money amount = variant.getPriceRange().getMinimumPrice().getFinalPrice();
    priceFormatter.setCurrency(Currency.getInstance(amount.getCurrency().toString()));
    Assert.assertEquals(priceFormatter.format(amount.getValue()), productTeaser.getFormattedPrice());

    Assert.assertEquals(variant.getImage().getUrl(), productTeaser.getImage());
}
 
Example #25
Source File: GraphQLCategoryProviderTest.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
@Test
public void testMissingMagentoGraphqlClient() throws IOException {
    Page page = Mockito.spy(context.currentPage("/content/pageA"));
    GraphQLCategoryProvider categoryProvider = new GraphQLCategoryProvider(page
        .getContentResource(), null);
    Assert.assertNull(Whitebox.getInternalState(categoryProvider, "magentoGraphqlClient"));
    Assert.assertTrue(categoryProvider.getChildCategories(10, 10).isEmpty());
}
 
Example #26
Source File: CommerceTeaserImpl.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
void populateActions() {
    Resource actionsNode = resource.getChild(CommerceTeaser.NN_ACTIONS);
    if (actionsNode != null) {
        for (Resource action : actionsNode.getChildren()) {

            ValueMap properties = action.getValueMap();
            String title = properties.get(PN_ACTION_TEXT, String.class);
            String productSlug = properties.get(PN_ACTION_PRODUCT_SLUG, String.class);
            String categoryId = properties.get(PN_ACTION_CATEGORY_ID, String.class);
            String selector = null;
            Page page;
            boolean isProduct = false;

            if (categoryId != null) {
                page = categoryPage;
                selector = categoryId;
            } else if (productSlug != null) {
                page = productPage;
                selector = productSlug;
                isProduct = true;
            } else {
                page = currentPage;

            }
            actions.add(new CommerceTeaserActionItem(title, selector, page, request, urlProvider, isProduct));
        }
    }
}
 
Example #27
Source File: NavigationImpl.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
CategoryNavigationItem(AbstractNavigationItem parent, String title, String url, boolean active, CategoryTree category,
                       SlingHttpServletRequest request, Page categoryPage) {
    super(parent, title, url, active);
    this.category = category;
    this.request = request;
    this.categoryPage = categoryPage;
}
 
Example #28
Source File: NavigationImpl.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
private Integer readPageConfiguration(Page page, String propertyName) {
    InheritanceValueMap properties = new HierarchyNodeInheritanceValueMap(page.getContentResource());
    return properties.getInherited(propertyName, Integer.class);
}
 
Example #29
Source File: NavigationImpl.java    From aem-core-cif-components with Apache License 2.0 5 votes vote down vote up
private void expandCatalogRoot(Page catalogPage, List<NavigationItem> pages) {
    Page categoryPage = SiteNavigation.getCategoryPage(currentPage);
    if (categoryPage == null) {
        return;
    }

    Integer rootCategoryId = readPageConfiguration(catalogPage, PN_MAGENTO_ROOT_CATEGORY_ID);
    if (rootCategoryId == null) {
        ComponentsConfiguration properties = catalogPage.getContentResource().adaptTo(ComponentsConfiguration.class);
        rootCategoryId = properties.get(PN_MAGENTO_ROOT_CATEGORY_ID, Integer.class);
    }

    if (rootCategoryId == null) {
        LOGGER.warn("Magento root category ID property (" + PN_MAGENTO_ROOT_CATEGORY_ID + ") not found");
        return;
    }

    List<CategoryTree> children = graphQLCategoryProvider.getChildCategories(rootCategoryId, structureDepth);
    if (children == null || children.isEmpty()) {
        LOGGER.warn("Magento top categories not found");
        return;
    }

    children = children.stream().filter(c -> c != null && c.getName() != null).collect(Collectors.toList());
    children.sort(Comparator.comparing(CategoryTree::getPosition));

    for (CategoryTree child : children) {
        Map<String, String> params = new ParamsBuilder()
            .id(child.getId().toString())
            .urlKey(child.getUrlKey())
            .urlPath(child.getUrlPath())
            .map();

        String url = urlProvider.toCategoryUrl(request, categoryPage, params);
        boolean active = request.getRequestURI().equals(url);
        CategoryNavigationItem navigationItem = new CategoryNavigationItem(null, child.getName(), url, active, child, request,
            categoryPage);
        pages.add(navigationItem);
    }
}
 
Example #30
Source File: ContentResourceShouldBeNullCheckedCheck.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
private ValueMap checkForNullWithCommonsObjectUtilsAllNotNull(Resource resource) {
  ValueMap result = new ValueMapDecorator(new HashMap<>());
  Page page = resource.adaptTo(Page.class);
  Resource pageResource = page.getContentResource("test");
  if (ObjectUtils.allNotNull(pageResource)) {
    result = pageResource.getValueMap();
  }
  return result;
}