Class AbstractCategoryRetriever
- java.lang.Object
-
- com.adobe.cq.commerce.core.components.models.retriever.AbstractRetriever
-
- com.adobe.cq.commerce.core.components.models.retriever.AbstractCategoryRetriever
-
public abstract class AbstractCategoryRetriever extends AbstractRetriever
-
-
Field Summary
Fields Modifier and Type Field Description protected com.adobe.cq.commerce.magento.graphql.CategoryInterface
category
Category instance.protected UrlProvider.CategoryIdentifierType
categoryIdentifierType
The type of the product identifier.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 String
mediaBaseUrl
Deprecated.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.-
Fields inherited from class com.adobe.cq.commerce.core.components.models.retriever.AbstractRetriever
client, query
-
-
Constructor Summary
Constructors Constructor Description AbstractCategoryRetriever(MagentoGraphqlClient client)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated 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
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.org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryArgumentsDefinition,com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition>
generateQueryArgs()
Deprecated.UsegenerateCategoryQueryArgs()
to use the GraphQLcategoryList
field.org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryArgumentsDefinition,com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition>
generateQueryArgs(String identifier)
Deprecated.UsegenerateCategoryQueryArgs(String)
to use the GraphQLcategoryList
field.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(UrlProvider.CategoryIdentifierType categoryIdentifierType, String identifier)
Set the identifier and the identifier type of the category that should be fetched.void
setIdentifier(String identifier)
Deprecated.UsesetIdentifier(CategoryIdentifierType, String)
instead.void
setPageSize(int pageSize)
Sets the page size for product pagination.-
Methods inherited from class com.adobe.cq.commerce.core.components.models.retriever.AbstractRetriever
setQuery
-
-
-
-
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.
-
category
protected com.adobe.cq.commerce.magento.graphql.CategoryInterface category
Category instance. Is only available after populate() was called.
-
mediaBaseUrl
@Deprecated protected String mediaBaseUrl
Deprecated.Media base url from the Magento store info. Is only available after populate() was called.
-
identifier
protected String identifier
Identifier of the category that should be fetched. Which kind of identifier is used is specified incategoryIdentifierType
-
categoryIdentifierType
protected UrlProvider.CategoryIdentifierType categoryIdentifierType
The type of the product identifier.
-
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
-
AbstractCategoryRetriever
public AbstractCategoryRetriever(MagentoGraphqlClient client)
-
-
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
@Deprecated public void setIdentifier(String identifier)
Deprecated.UsesetIdentifier(CategoryIdentifierType, String)
instead.Set the identifier of the product that should be fetched. Which kind of identifier is used (usually id) is implementation specific and should be checked in subclass implementations. Setting the identifier, removes any cached data.- Parameters:
identifier
- Category identifier
-
setIdentifier
public void setIdentifier(UrlProvider.CategoryIdentifierType categoryIdentifierType, String identifier)
Set the identifier and the identifier type of the category that should be fetched. Setting the identifier, removes any cached data.- Parameters:
categoryIdentifierType
- The category identifier type.identifier
- The category identifier.
-
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());
- Parameters:
categoryQueryHook
- Lambda that extends the category query
-
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"));
- 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 identifier, usually the category id- Returns:
- GraphQL query as string
-
generateQueryArgs
@Deprecated public org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryArgumentsDefinition,com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition> generateQueryArgs(String identifier)
Deprecated.UsegenerateCategoryQueryArgs(String)
to use the GraphQLcategoryList
field.Generates a pair of args for the category query for a given category identifier;- Parameters:
identifier
- Category identifier, usually the category id- Returns:
- GraphQL query as string
-
generateQueryArgs
@Deprecated public org.apache.commons.lang3.tuple.Pair<com.adobe.cq.commerce.magento.graphql.QueryQuery.CategoryArgumentsDefinition,com.adobe.cq.commerce.magento.graphql.CategoryTreeQueryDefinition> generateQueryArgs()
Deprecated.UsegenerateCategoryQueryArgs()
to use the GraphQLcategoryList
field.Generates a pair of args for the category query for the instance 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 identifier, usually the category id- 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 classAbstractRetriever
- Returns:
- GraphqlResponse object
-
populate
protected void populate()
Description copied from class:AbstractRetriever
Executes the query and parses the response.- Specified by:
populate
in classAbstractRetriever
-
-