Class DefaultCategoryService<P extends Category>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.catalog.service.DefaultCategoryService<P>
All Implemented Interfaces:
CategoryService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

public class DefaultCategoryService<P extends Category> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements CategoryService<P>
Author:
Jeff Fischer, Samarth Dhruva (samarthd)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultCategoryService(CategoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, ProductService<Product> productService, CategoryProductService<CategoryProduct> categoryProductService, RSQLEvaluationService rsqlEvaluationService, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    checkRelatedProductMembershipInCategory(String categoryId, String productId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Checks whether a product is a member of the given category.
    boolean
    existsById(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Returns whether there is a category with the given context ID in the data store.
    protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen
     
    protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen
     
    protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen
     
    protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen
     
    protected com.broadleafcommerce.common.extension.cache.CacheStateManager
     
     
     
    protected CategoryRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
     
     
    cz.jirutka.rsql.parser.ast.Node
    mergeInFilter(cz.jirutka.rsql.parser.ast.Node filters, String fieldName, List<String> searchList)
     
    readAllByContextIds(Collection<String> categoryIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Return all of the categories with IDs in the supplied collection.
    org.springframework.data.domain.Page<P>
    readAllByContextIds(Collection<String> categoryIds, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Return all of the categories with IDs in the supplied list.
    readAllById(@NonNull Iterable<String> ids, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Retrieves of all the Categories that match the contextIds.
    org.springframework.data.domain.Page<P>
    readAllByName(boolean rootsOnly, String name, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Read all categories, filtered by name.
    readAllByNamesIn(Collection<String> names, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Read all categories, filtered by name.
    org.springframework.data.domain.Page<P>
    readAllByParentCategoryId(String parentCategoryId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Read all categories in the database that have the given category context ID set as their parent category.
    org.springframework.data.domain.Page<P>
    readAllByParentCategoryIdIn(List<String> parentCategoryIds, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
    readAllByUrls(@NonNull Iterable<String> urls, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Finds a categories by the given urls.
    readByExternalId(String externalId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find a category by its external ID
    readByExternalIdIn(Collection<String> externalIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find a list of categories by the supplied external IDs
    org.springframework.data.domain.Page<P>
    readByExternalIdIn(Collection<String> externalIds, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Find categories by their external IDs
    readByUrl(String url, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Finds a category by the given url.
    void
    setCacheByActiveCategoryIdKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveCategoryIdKeyGen)
     
    void
    setCacheByActiveCategoryKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveCategoryKeyGen)
     
    void
    setCacheByActiveCategoryUrlKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveCategoryUrlKeyGen)
     
    void
    setCacheByExternalCategoryId(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByExternalCategoryId)
     
    streamByParentCategoryId(String parentCategoryId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Read all categories in the database that have the given category context ID set as their parent category.

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService

    getRsqlHelper, readAll, readAll, readAll, readAll

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService

    convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

    create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

    readAll, readAll, readAll, readAll
  • Field Details

  • Constructor Details

    • DefaultCategoryService

      public DefaultCategoryService(CategoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, ProductService<Product> productService, CategoryProductService<CategoryProduct> categoryProductService, RSQLEvaluationService rsqlEvaluationService, @Nullable com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
  • Method Details

    • existsById

      public boolean existsById(@NonNull String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Returns whether there is a category with the given context ID in the data store.
      Specified by:
      existsById in interface CategoryService<P extends Category>
      Parameters:
      id - the ID to search for
      contextInfo - context information around sandboxing and multitenant state
      Returns:
      true if a category exists matching the given ID, false otherwise
    • readAllByContextIds

      public org.springframework.data.domain.Page<P> readAllByContextIds(@NonNull Collection<String> categoryIds, @NonNull org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryService
      Return all of the categories with IDs in the supplied list.
      Specified by:
      readAllByContextIds in interface CategoryService<P extends Category>
      Parameters:
      categoryIds - the category context IDs to search for
      page - the requested page of results from the database
      context - the context to perform the operation in
      Returns:
      the categories that matched with the IDs in the given list
    • readAllByContextIds

      public Stream<P> readAllByContextIds(@NonNull Collection<String> categoryIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Return all of the categories with IDs in the supplied collection.
      Specified by:
      readAllByContextIds in interface CategoryService<P extends Category>
      Parameters:
      categoryIds - the category context IDs to search for
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the categories that matched with the IDs in the given collection
    • readAllByName

      public org.springframework.data.domain.Page<P> readAllByName(boolean rootsOnly, @Nullable String name, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryService
      Read all categories, filtered by name. If rootsOnly is true, then results are also filtered to only include categories that have no specified parent category.
      Specified by:
      readAllByName in interface CategoryService<P extends Category>
      Parameters:
      rootsOnly - if true, restricts results to only include categories that have not specified a parent category
      name - the category name to filter by
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      page - the requested page of results from the database
      context - context information surrounding sandboxing and multitenant state
      Returns:
      all categories, filtered by name and whether they have specified a parent category
    • readAllByNamesIn

      public List<P> readAllByNamesIn(@NonNull Collection<String> names, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryService
      Read all categories, filtered by name. If rootsOnly is true, then results are also filtered to only include categories that have no specified parent category.
      Specified by:
      readAllByNamesIn in interface CategoryService<P extends Category>
      Parameters:
      names - the category names to filter by
      context - context context information surrounding sandboxing and multitenant state
      Returns:
      all categories, filtered by name and whether they have specified a parent category
    • mergeInFilter

      public cz.jirutka.rsql.parser.ast.Node mergeInFilter(cz.jirutka.rsql.parser.ast.Node filters, String fieldName, List<String> searchList)
    • readAllByParentCategoryId

      public org.springframework.data.domain.Page<P> readAllByParentCategoryId(@NonNull String parentCategoryId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Read all categories in the database that have the given category context ID set as their parent category.
      Specified by:
      readAllByParentCategoryId in interface CategoryService<P extends Category>
      Parameters:
      parentCategoryId - the category context ID whose children should be found
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      page - the requested page of results from the database
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      the children categories of the category identified by the given context ID
    • readAllByParentCategoryIdIn

      public org.springframework.data.domain.Page<P> readAllByParentCategoryIdIn(@NonNull List<String> parentCategoryIds, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Specified by:
      readAllByParentCategoryIdIn in interface CategoryService<P extends Category>
    • streamByParentCategoryId

      public Stream<P> streamByParentCategoryId(String parentCategoryId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Read all categories in the database that have the given category context ID set as their parent category.
      Specified by:
      streamByParentCategoryId in interface CategoryService<P extends Category>
      Parameters:
      parentCategoryId - the category context ID whose children should be found
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      the stream of children categories of the category identified by the given context ID
    • checkRelatedProductMembershipInCategory

      public boolean checkRelatedProductMembershipInCategory(@NonNull String categoryId, @NonNull String productId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Checks whether a product is a member of the given category. If the category is CategoryProductMembershipType.EXPLICIT, will check if there is a CategoryProduct between the supplied category and product. If the category is CategoryProductMembershipType.RULE_BASED, will evaluate the category's rule string against the product to see if the product satisfies the rule string.
      Specified by:
      checkRelatedProductMembershipInCategory in interface CategoryService<P extends Category>
      Parameters:
      categoryId - the context ID of the category to check membership with
      productId - the context ID of the product to check
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      true if the product is a member of the category, false otherwise
    • readByUrl

      @NonNull public Optional<P> readByUrl(@NonNull String url, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryService
      Finds a category by the given url.
      Specified by:
      readByUrl in interface CategoryService<P extends Category>
      Parameters:
      url - The url to search by
      Returns:
      The Category matching the url, or Optional.empty() if none found
    • readAllByUrls

      @NonNull public List<P> readAllByUrls(@NonNull @NonNull @NonNull Iterable<String> urls, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryService
      Finds a categories by the given urls.
      Specified by:
      readAllByUrls in interface CategoryService<P extends Category>
      Parameters:
      urls - The urls to search by
      Returns:
      The Category matching the urls
    • readAllById

      public List<P> readAllById(@NonNull @NonNull @NonNull Iterable<String> ids, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryService
      Retrieves of all the Categories that match the contextIds.
      Specified by:
      readAllById in interface CategoryService<P extends Category>
      Parameters:
      ids - IDs to match against
      context - the current context to look in
      Returns:
      All the Categories that match the contextIds.
    • readByExternalIdIn

      public List<P> readByExternalIdIn(Collection<String> externalIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Find a list of categories by the supplied external IDs
      Specified by:
      readByExternalIdIn in interface CategoryService<P extends Category>
      Parameters:
      externalIds - The external IDs to query for
      contextInfo - the context around sandboxing and multitenant state
      Returns:
      A list of categories
    • readByExternalIdIn

      public org.springframework.data.domain.Page<P> readByExternalIdIn(Collection<String> externalIds, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Find categories by their external IDs
      Specified by:
      readByExternalIdIn in interface CategoryService<P extends Category>
      Parameters:
      externalIds - The external IDs to query for
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      page - the requested page of results from the database
      contextInfo - the context around sandboxing and multitenant state
      Returns:
      A page of categories
    • readByExternalId

      public P readByExternalId(String externalId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryService
      Find a category by its external ID
      Specified by:
      readByExternalId in interface CategoryService<P extends Category>
      Parameters:
      externalId - The external ID
      contextInfo - the context around sandboxing and multitenant state
    • getRepositoryDomain

      @NonNull public String getRepositoryDomain()
      Specified by:
      getRepositoryDomain in interface CategoryService<P extends Category>
    • getRepository

      @NonNull protected CategoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Category>
    • getProductService

      @NonNull protected ProductService<Product> getProductService()
    • getCategoryProductService

      @NonNull protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • getRsqlEvaluationService

      @NonNull protected RSQLEvaluationService getRsqlEvaluationService()
    • getCacheStateManager

      @Nullable protected com.broadleafcommerce.common.extension.cache.CacheStateManager getCacheStateManager()
    • setCacheByActiveCategoryKeyGen

      @Autowired @Qualifier("catalogCacheByActiveCategory") public void setCacheByActiveCategoryKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveCategoryKeyGen)
      See Also:
    • getCacheByActiveCategoryKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getCacheByActiveCategoryKeyGen()
      See Also:
    • setCacheByActiveCategoryIdKeyGen

      @Autowired @Qualifier("catalogCacheByActiveCategoryId") public void setCacheByActiveCategoryIdKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveCategoryIdKeyGen)
      See Also:
    • getCacheByActiveCategoryIdKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getCacheByActiveCategoryIdKeyGen()
      See Also:
    • setCacheByActiveCategoryUrlKeyGen

      @Autowired @Qualifier("catalogCacheByActiveCategoryUrl") public void setCacheByActiveCategoryUrlKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveCategoryUrlKeyGen)
      See Also:
    • getCacheByActiveCategoryUrlKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getCacheByActiveCategoryUrlKeyGen()
      See Also:
    • setCacheByExternalCategoryId

      @Autowired @Qualifier("catalogCacheByCategoryExternalId") public void setCacheByExternalCategoryId(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByExternalCategoryId)
      See Also:
    • getCacheByExternalCategoryId

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getCacheByExternalCategoryId()
      See Also: