Class AbstractCategoryRetriever

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Optional<com.adobe.cq.commerce.magento.graphql.CategoryInterface> category
      Category instance.
      protected Function<com.adobe.cq.commerce.magento.graphql.CategoryFilterInput,​com.adobe.cq.commerce.magento.graphql.CategoryFilterInput> categoryFilterHook
      Lambda that allows to replace or extend the category filters.
      protected Consumer<com.adobe.cq.commerce.magento.graphql.CategoryTreeQuery> categoryQueryHook
      Lambda that extends the category query.
      protected int currentPage
      Current page for pagination of products in a category.
      protected String identifier
      Identifier of the category that should be fetched.
      protected int pageSize
      Page size for pagination of products in a category.
      protected Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook
      Lambda that extends the product query.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected com.adobe.cq.commerce.graphql.client.GraphqlResponse<com.adobe.cq.commerce.magento.graphql.Query,​com.adobe.cq.commerce.magento.graphql.gson.Error> executeQuery()
      Execute the GraphQL query with the GraphQL client.
      void extendCategoryFilterWith​(Function<com.adobe.cq.commerce.magento.graphql.CategoryFilterInput,​com.adobe.cq.commerce.magento.graphql.CategoryFilterInput> categoryFilterHook)
      Extends or replaces the category filter with a custom instance defined by a lambda hook.
      void extendCategoryQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.CategoryTreeQuery> categoryQueryHook)
      Extend the category query part of the category GraphQL query with a partial query provided by a lambda hook that sets additional fields.
      void extendProductQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook)
      Extend the product query part of the category GraphQL query with a partial query provided by a lambda hook that sets additional fields.
      com.adobe.cq.commerce.magento.graphql.CategoryInterface fetchCategory()
      Executes the GraphQL query and returns a category.
      protected abstract com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition generateCategoryQuery()
      Generates the partial CategoryTree query part of the GraphQL category query.
      org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryListArgumentsDefinition,​com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition> generateCategoryQueryArgs()
      Generates a pair of args for the category query for the instance identifier;
      org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryListArgumentsDefinition,​com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition> generateCategoryQueryArgs​(String identifier)
      Generates a pair of args for the category query for a given category identifier;
      String generateQuery​(String identifier)
      Generates a complete category GraphQL query with a selection of the given category identifier.
      Consumer<com.adobe.cq.commerce.magento.graphql.CategoryTreeQuery> getCategoryQueryHook()  
      Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> getProductQueryHook()  
      protected void populate()
      Executes the query and parses the response.
      void setCurrentPage​(int currentPage)
      Sets the current page for product pagination.
      void setIdentifier​(String identifier)
      Set the identifier and the identifier type of the category that should be fetched.
      void setPageSize​(int pageSize)
      Sets the page size for product pagination.
    • Field Detail

      • categoryQueryHook

        protected Consumer<com.adobe.cq.commerce.magento.graphql.CategoryTreeQuery> categoryQueryHook
        Lambda that extends the category query.
      • productQueryHook

        protected Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook
        Lambda that extends the product query.
      • categoryFilterHook

        protected Function<com.adobe.cq.commerce.magento.graphql.CategoryFilterInput,​com.adobe.cq.commerce.magento.graphql.CategoryFilterInput> categoryFilterHook
        Lambda that allows to replace or extend the category filters.
      • category

        protected Optional<com.adobe.cq.commerce.magento.graphql.CategoryInterface> category
        Category instance. Is only available after populate() was called.
      • identifier

        protected String identifier
        Identifier of the category that should be fetched. Categories are identfied by UID.
      • currentPage

        protected int currentPage
        Current page for pagination of products in a category.
      • pageSize

        protected int pageSize
        Page size for pagination of products in a category.
    • Constructor Detail

    • Method Detail

      • fetchCategory

        public com.adobe.cq.commerce.magento.graphql.CategoryInterface fetchCategory()
        Executes the GraphQL query and returns a category. For subsequent calls of this method, a cached category is returned.
        Returns:
        Category
      • setCurrentPage

        public void setCurrentPage​(int currentPage)
        Sets the current page for product pagination.
        Parameters:
        currentPage - The current AEM page.
      • setPageSize

        public void setPageSize​(int pageSize)
        Sets the page size for product pagination.
        Parameters:
        pageSize - The page size.
      • setIdentifier

        public void setIdentifier​(String identifier)
        Set the identifier and the identifier type of the category that should be fetched. Setting the identifier, removes any cached data.
        Parameters:
        identifier - The category UID.
      • extendCategoryQueryWith

        public void extendCategoryQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.CategoryTreeQuery> categoryQueryHook)
        Extend the category query part of the category GraphQL query with a partial query provided by a lambda hook that sets additional fields. Example:
         
         categoryRetriever.extendCategoryQueryWith(p -> p
             .level());
         
         
        If called multiple times, each hook will be "appended" to the previously registered hook(s).
        Parameters:
        categoryQueryHook - Lambda that extends the category query
      • extendCategoryFilterWith

        public void extendCategoryFilterWith​(Function<com.adobe.cq.commerce.magento.graphql.CategoryFilterInput,​com.adobe.cq.commerce.magento.graphql.CategoryFilterInput> categoryFilterHook)
        Extends or replaces the category filter with a custom instance defined by a lambda hook. Example 1 (Extend):
         
         categoryRetriever.extendCategoryFilterWith(f -> f
             .setCustomFilter("my-attribute", new FilterEqualTypeInput()
                 .setEq("my-value")));
         
         
        Example 2 (Replace):
         
         categoryRetriever.extendCategoryFilterWith(f -> new CategoryFilterInput()
             .setCategoryUid(new FilterEqualTypeInput()
                 .setEq("custom-uid"))
             .setCustomFilter("my-attribute", new FilterEqualTypeInput()
                 .setEq("my-value")));
         
         
        Parameters:
        categoryFilterHook - Lambda that extends or replaces the category filter.
      • getCategoryQueryHook

        public Consumer<com.adobe.cq.commerce.magento.graphql.CategoryTreeQuery> getCategoryQueryHook()
        Returns:
        The extended category query part if it was set with extendCategoryQueryWith(Consumer)
      • extendProductQueryWith

        public void extendProductQueryWith​(Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> productQueryHook)
        Extend the product query part of the category GraphQL query with a partial query provided by a lambda hook that sets additional fields. Example:
         
         categoryRetriever.extendProductQueryWith(p -> p
             .createdAt()
             .addCustomSimpleField("is_returnable"));
         
         
        If called multiple times, each hook will be "appended" to the previously registered hook(s).
        Parameters:
        productQueryHook - Lambda that extends the product query
      • getProductQueryHook

        public Consumer<com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery> getProductQueryHook()
        Returns:
        The extended product query part if it was set with extendProductQueryWith(Consumer)
      • generateCategoryQuery

        protected abstract com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition generateCategoryQuery()
        Generates the partial CategoryTree query part of the GraphQL category query.
        Returns:
        CategoryTree query definition
      • generateQuery

        public String generateQuery​(String identifier)
        Generates a complete category GraphQL query with a selection of the given category identifier.
        Parameters:
        identifier - Category uid identifier
        Returns:
        GraphQL query as string
      • generateCategoryQueryArgs

        public org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryListArgumentsDefinition,​com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition> generateCategoryQueryArgs​(String identifier)
        Generates a pair of args for the category query for a given category identifier;
        Parameters:
        identifier - Category uid identifier
        Returns:
        GraphQL query as string
      • generateCategoryQueryArgs

        public org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryListArgumentsDefinition,​com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition> generateCategoryQueryArgs()
        Generates a pair of args for the category query for the instance identifier;
        Returns:
        GraphQL query as string
      • executeQuery

        protected com.adobe.cq.commerce.graphql.client.GraphqlResponse<com.adobe.cq.commerce.magento.graphql.Query,​com.adobe.cq.commerce.magento.graphql.gson.Error> executeQuery()
        Execute the GraphQL query with the GraphQL client.
        Specified by:
        executeQuery in class AbstractRetriever
        Returns:
        GraphqlResponse object