Class DefaultCategoryProductService<P extends CategoryProduct>

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

public class DefaultCategoryProductService<P extends CategoryProduct> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements CategoryProductService<P>
Author:
Samarth Dhruva (samarthd)
  • Field Summary

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

    Constructors
    Constructor
    Description
    DefaultCategoryProductService(CategoryProductRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected P
    choosePrimary(P primaryCategoryProduct1, P primaryCategoryProduct2)
    A simple BinaryOperator that takes two category products that were found to be primaries for the same product and chooses one.
    long
    countNonProductionRecordsByProductIdsInTenant(@NonNull Collection<String> productIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Returns the count of non-production records that match the given productContextIds and the given tenant context.
    protected CategoryRef
     
    boolean
    existsByJoinedIds(String productId, String categoryId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Returns whether there is a category-product relationship for the given product and category 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.CacheStateManager
     
    protected String
    getMessage(String name, String defaultMessage, Locale locale, Object[] args)
    Retrieves a message from a message source.
    protected org.springframework.context.MessageSource
     
     
    protected CategoryProductRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
    org.springframework.data.domain.Page<P>
    readAllByCategoryIdAndIsSorted(String categoryId, boolean isSorted, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds all CategoryProducts for the given Category.id and CategoryProduct.sorted values.
    org.springframework.data.domain.Page<P>
    readAllByCategoryIdAndProductIdsAndIsSorted(String categoryId, @NonNull List<String> productIds, boolean isSorted, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds all CategoryProducts for the given Category.id, Product.id, and CategoryProduct.sorted values.
    readAllByCategoryIdIn(@NonNull Collection<String> categoryIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads a list of CategoryProducts by ID.
    readAllByProductIdIn(Collection<String> productIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads all of the category products which are associated with any of the given productIds.
    org.springframework.data.domain.Page<P>
    readByCategoryContextId(String categoryContextId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all of the CategoryProduct relationships in the database associated with the given category context ID.
    org.springframework.data.domain.Page<P>
    readByCategoryContextIdAndProductIds(String categoryContextId, List<String> productIds, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all CategoryProduct relationships in the database associated with the given category context ID and Product IDs.
    org.springframework.data.domain.Page<P>
    readByCategoryIdIn(@NonNull Collection<String> categoryIds, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads a page of CategoryProducts by ID.
    readByIdAndCategoryId(String id, String categoryId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds the CategoryProduct which has the given ID and parent category ID.
    readByJoinedIds(String productId, String categoryId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Query for a CategoryProduct that joins a given product and category.
    org.springframework.data.domain.Page<P>
    readByProductContextId(String productContextId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all of the CategoryProduct relationships in the database associated with the given product context ID.
    org.springframework.data.domain.Page<P>
    readPageForCategory(@NonNull Category category, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, Boolean isSorted, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds a page of CategoryProducts for the given Category and additional inputs.
    readPrimaryByProductIdIn(@NonNull Collection<String> productIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all CategoryProducts whose product ID is in one of the given values and whose CategoryProduct.primary is true.
    void
    setCacheByCategoryProductCategoryKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByCategoryProductCategoryKeyGen)
     
    void
    setCacheByCategoryProductKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByCategoryProductKeyGen)
     
    void
    setMessageSource(org.springframework.context.MessageSource messageSource)
     
    void
     

    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

    • DefaultCategoryProductService

      public DefaultCategoryProductService(CategoryProductRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, @Nullable com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager)
  • Method Details

    • existsByJoinedIds

      public boolean existsByJoinedIds(String productId, String categoryId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Returns whether there is a category-product relationship for the given product and category in the data store.
      Specified by:
      existsByJoinedIds in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      productId - the product context ID
      categoryId - the category context ID
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      true if a relationship was found between the product and category, false otherwise
    • readByCategoryContextId

      @NonNull public org.springframework.data.domain.Page<P> readByCategoryContextId(@NonNull String categoryContextId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Reads all of the CategoryProduct relationships in the database associated with the given category context ID.
      Specified by:
      readByCategoryContextId in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      categoryContextId - the category context ID to find the relationships 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 to query within
      Returns:
      the CategoryProduct relationships in the database that match the given category context ID
    • readByCategoryContextIdAndProductIds

      public org.springframework.data.domain.Page<P> readByCategoryContextIdAndProductIds(String categoryContextId, @NonNull List<String> productIds, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Reads all CategoryProduct relationships in the database associated with the given category context ID and Product IDs.
      Specified by:
      readByCategoryContextIdAndProductIds in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      categoryContextId - the category context ID to find the relationships for
      productIds - the list of Product.ids to retrieve
      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 to query within
      Returns:
      the CategoryProduct relationships in the database that match the given category context ID
    • readByProductContextId

      @NonNull public org.springframework.data.domain.Page<P> readByProductContextId(@NonNull String productContextId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Reads all of the CategoryProduct relationships in the database associated with the given product context ID.
      Specified by:
      readByProductContextId in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      productContextId - the product context ID to find the relationships 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 to query within
      Returns:
      the CategoryProduct relationships in the database that match the given category context ID
    • readAllByProductIdIn

      public List<P> readAllByProductIdIn(Collection<String> productIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryProductService
      Reads all of the category products which are associated with any of the given productIds.
      Specified by:
      readAllByProductIdIn in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      productIds - a collection of product IDs which the results must be associated with
      context - context information surrounding sandboxing and multitenant state
      Returns:
      all of the category products which are associated with any of the given productIds
    • readAllByCategoryIdAndIsSorted

      @NonNull public org.springframework.data.domain.Page<P> readAllByCategoryIdAndIsSorted(@NonNull String categoryId, boolean isSorted, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Finds all CategoryProducts for the given Category.id and CategoryProduct.sorted values.
      Specified by:
      readAllByCategoryIdAndIsSorted in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      categoryId - parent Category.id
      isSorted - Whether to return CategoryProducts where CategoryProduct.sorted is true, else false.
      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 to query within
      Returns:
      the CategoryProducts with the given categoryId and sorting values
    • readAllByCategoryIdAndProductIdsAndIsSorted

      @NonNull public org.springframework.data.domain.Page<P> readAllByCategoryIdAndProductIdsAndIsSorted(@NonNull String categoryId, @NonNull @NonNull @NonNull List<String> productIds, boolean isSorted, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Finds all CategoryProducts for the given Category.id, Product.id, and CategoryProduct.sorted values.
      Specified by:
      readAllByCategoryIdAndProductIdsAndIsSorted in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      categoryId - parent Category.id
      productIds - the list of Product.ids to retrieve
      isSorted - Whether to return CategoryProducts where CategoryProduct.sorted is true, else false.
      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 to query within
      Returns:
      the CategoryProducts with the given categoryId and sorting values
    • readByJoinedIds

      @NonNull public Optional<P> readByJoinedIds(@NonNull String productId, @NonNull String categoryId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Query for a CategoryProduct that joins a given product and category.
      Specified by:
      readByJoinedIds in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      productId - the product context ID
      categoryId - the category context ID
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      an Optional that is either empty or contains the CategoryProduct that was found
    • readByIdAndCategoryId

      @NonNull public P readByIdAndCategoryId(@NonNull String id, @NonNull String categoryId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Finds the CategoryProduct which has the given ID and parent category ID.
      Specified by:
      readByIdAndCategoryId in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      id - the context ID of the CategoryProduct
      categoryId - the context ID of the parent Category
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      the category product that has the given ID and parent category ID
    • readByCategoryIdIn

      @NonNull public org.springframework.data.domain.Page<P> readByCategoryIdIn(@NonNull @NonNull @NonNull Collection<String> categoryIds, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Reads a page of CategoryProducts by ID.
      Specified by:
      readByCategoryIdIn in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      categoryIds - Category IDs to match against
      page - Pagination info
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      A page of CategoryProducts by ID.
    • readAllByCategoryIdIn

      @NonNull public List<P> readAllByCategoryIdIn(@NonNull @NonNull Collection<String> categoryIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Reads a list of CategoryProducts by ID.
      Specified by:
      readAllByCategoryIdIn in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      categoryIds - Category IDs to match against
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      A list of CategoryProducts by ID.
    • readPrimaryByProductIdIn

      @NonNull public Map<String,P> readPrimaryByProductIdIn(@NonNull @NonNull @NonNull Collection<String> productIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Reads all CategoryProducts whose product ID is in one of the given values and whose CategoryProduct.primary is true.

      This essentially finds the relationships between the given products and their primary categories.

      For any given product ID, there should only be one primary category, but in the event more than one result is found, only the first will be used.

      Specified by:
      readPrimaryByProductIdIn in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      productIds - the ids of the products for which to find primary category-product relationships
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      a map from product ID to the category-product found for it. If no category-product was found for a product id, it will not have an entry in the resulting map.
    • readPageForCategory

      public org.springframework.data.domain.Page<P> readPageForCategory(@NonNull @NonNull Category category, @Nullable org.springframework.data.domain.Pageable page, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable Boolean isSorted, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CategoryProductService
      Finds a page of CategoryProducts for the given Category and additional inputs.
      Specified by:
      readPageForCategory in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      category - The parent category
      page - Pagination info
      filters - RSQL filters
      isSorted - Whether to read only CategoryProducts that have a sort value.
      contextInfo - Additional multitenant and sandbox info
      Returns:
      Page of CategoryProducts for the given Category.
    • countNonProductionRecordsByProductIdsInTenant

      public long countNonProductionRecordsByProductIdsInTenant(@NonNull @NonNull Collection<String> productIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CategoryProductService
      Returns the count of non-production records that match the given productContextIds and the given tenant context.
      Specified by:
      countNonProductionRecordsByProductIdsInTenant in interface CategoryProductService<P extends CategoryProduct>
      Parameters:
      productIds - IDs of parent Products to match against
      context - Request context information around sandbox and multitenant state
      Returns:
      the count of non-production records that match the given productContextIds and the given tenant context
    • getMessage

      protected String getMessage(String name, String defaultMessage, Locale locale, @Nullable Object[] args)
      Retrieves a message from a message source.
      Parameters:
      name - Name of the message
      defaultMessage - Default message to display if message not found by name
      locale - The locale for the message
      args - Any arguments to supply.
      Returns:
      The message.
    • choosePrimary

      protected P choosePrimary(P primaryCategoryProduct1, P primaryCategoryProduct2)
      A simple BinaryOperator that takes two category products that were found to be primaries for the same product and chooses one. This allows for graceful handling of an erroneous scenario where a product has more than one primary category.

      The default implementation chooses the one with the "highest" ID value.

      Parameters:
      primaryCategoryProduct1 - a category product that was a primary for the same product
      primaryCategoryProduct2 - a category product that was a primary for the same product
      Returns:
      one of the two category products
    • createCategoryRefFromCategory

      protected CategoryRef createCategoryRefFromCategory(Category category)
    • getRepository

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

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

      @Autowired @Qualifier("catalogCacheByCategoryProduct") public void setCacheByCategoryProductKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByCategoryProductKeyGen)
      See Also:
    • getCacheByCategoryProductKeyGen

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

      @Autowired @Qualifier("catalogCacheByCategoryProductCategory") public void setCacheByCategoryProductCategoryKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByCategoryProductCategoryKeyGen)
      See Also:
    • getCacheByCategoryProductCategoryKeyGen

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

      protected ProductService<Product> getProductService()
    • setProductService

      @Autowired @Lazy public void setProductService(ProductService<Product> productService)
    • getMessageSource

      @Nullable protected org.springframework.context.MessageSource getMessageSource()
    • setMessageSource

      @Autowired(required=false) public void setMessageSource(org.springframework.context.MessageSource messageSource)