Class DefaultProductService<P extends Product>

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

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

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

    Constructors
    Constructor
    Description
    DefaultProductService(ProductRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, VariantService<Variant> variantService, CategoryProductService<CategoryProduct> categoryProductService, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected CategoryProduct
    buildPrimaryCategoryProduct(@NonNull String productId, @NonNull String categoryId)
    Builds a new CategoryProduct POJO for productId and categoryId with CategoryProduct.isPrimary() set to true.
    protected boolean
    changeContainerIdAlreadySet(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
    protected com.broadleafcommerce.data.tracking.core.filtering.domain.ChangeContainer
    copyChangeContainer(com.broadleafcommerce.data.tracking.core.filtering.domain.ChangeContainer changeContainer)
     
    create(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Performs the same behavior as BaseCrudEntityService.create(Object, ContextInfo) with the addition of Product.getPrimaryCategory() management.
    void
    delete(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Deletes a product by ID.
    boolean
    existsById(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Returns whether there is a product 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
     
     
    getCurrentPrimaryCategoryProduct(@NonNull String productId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds the current primary category product for the given productId.
    protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>
     
    protected ProductRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
     
    protected void
    managePrimaryCategory(@NonNull String productId, Category requestedPrimary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Enables direct management of the primary category product relationship for a product.
    protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
    overrideChangeContainerId(String changeContainerId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
    org.springframework.data.domain.Page<P>
    readAllByCategoryContextId(String categoryId, Boolean isSorted, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Finds all products in a given category.
    readAllByContextIds(@NonNull Collection<String> productIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Return all of the products with IDs in the supplied collection.
    org.springframework.data.domain.Page<P>
    readAllByContextIds(Collection<String> productIds, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Return all of the products with IDs in the supplied list.
    readAllByExternalIds(Collection<String> externalIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Fetches products based on the provided external IDs.
    readAllByFiltersExcluding(cz.jirutka.rsql.parser.ast.Node filters, List<String> exclusions, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Returns all of the products matching the given filters, excluding any products whose IDs match any of the values in exclusions.
    org.springframework.data.domain.Page<P>
    readAllByName(String name, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
     
    readAllByUris(@NonNull Iterable<String> uris, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds the product matching the uris.
    readAllSkusByProduct(P product, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads all the SKUs for the the specified product.
    readAllSkusByProductId(@NonNull String productId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads all the SKUs for the the specified product ID.
    readAllSkusByProductIdAndQuery(@NonNull String productId, @NonNull String sku, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Reads all the SKUs for the the specified product ID and SKU identifier.
    readAllUniqueIds(int page, cz.jirutka.rsql.parser.ast.Node filters)
    Return all of the unique product IDs.
    readAllUniqueIdsPerContext(int page, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Retrieves a narrowed list of unique product context IDs narrowed on a ContextInfo
    readByUri(String uri, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Read a product by a given URI
    replace(@NonNull String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Performs the same behavior as BaseCrudEntityService.replace(String, Object, ContextInfo) with the addition of Product.getPrimaryCategory() management.
    void
    setCacheByActiveProductKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveProductKeyGen)
     
    void
    setCacheByActiveProductUriKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveProductUriKeyGen)
     
    protected void
    unsetCurrentPrimaryCategoryProduct(@NonNull String productId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds the current primary category product for the given productId and unmarks it as primary if it exists.

    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, createAll, createAllAllowingPartialSuccess, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, 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

    createAll, createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, readByContextId, 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

    • DefaultProductService

      public DefaultProductService(ProductRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, VariantService<Variant> variantService, CategoryProductService<CategoryProduct> categoryProductService, @Nullable com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • existsById

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

      public org.springframework.data.domain.Page<P> readAllByName(@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)
      Specified by:
      readAllByName in interface ProductService<P extends Product>
    • readAllByContextIds

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

      public org.springframework.data.domain.Page<P> readAllByCategoryContextId(String categoryId, @Nullable Boolean isSorted, @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: ProductService
      Finds all products in a given category.
      Specified by:
      readAllByCategoryContextId in interface ProductService<P extends Product>
      Parameters:
      categoryId - the context id of the category.
      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 amount of results from the database. -1 indicates no limit.
      context - Request context information around sandbox and multitenant state
      Returns:
      All the products in the given category
    • readAllByFiltersExcluding

      public Stream<P> readAllByFiltersExcluding(@Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable List<String> exclusions, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductService
      Returns all of the products matching the given filters, excluding any products whose IDs match any of the values in exclusions.
      Specified by:
      readAllByFiltersExcluding in interface ProductService<P extends Product>
      Parameters:
      filters - the RSQL Node used to restrict results, must not be null
      exclusions - a list of product IDs that should be excluded from the results
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      all of the products matching the given filters, excluding any products whose IDs match any of the values in exclusions
    • readAllByContextIds

      public List<P> readAllByContextIds(@NonNull @NonNull @NonNull Collection<String> productIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductService
      Return all of the products with IDs in the supplied collection.
      Specified by:
      readAllByContextIds in interface ProductService<P extends Product>
      Parameters:
      productIds - the product context IDs to search for
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the products that matched with the IDs in the given collection
    • readByUri

      public Optional<P> readByUri(String uri, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ProductService
      Read a product by a given URI
      Specified by:
      readByUri in interface ProductService<P extends Product>
      Parameters:
      uri - the URI to search for
      Returns:
      an Optional representing a found Product or an empty optional if none found
    • readAllUniqueIds

      public List<String> readAllUniqueIds(int page, @Nullable cz.jirutka.rsql.parser.ast.Node filters)
      Description copied from interface: ProductService
      Return all of the unique product IDs.
      Specified by:
      readAllUniqueIds in interface ProductService<P extends Product>
      Parameters:
      page - the requested amount of results from the database. -1 indicates no limit.
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      Returns:
      unique product IDs
    • readAllUniqueIdsPerContext

      public List<String> readAllUniqueIdsPerContext(int page, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ProductService
      Retrieves a narrowed list of unique product context IDs narrowed on a ContextInfo
      Specified by:
      readAllUniqueIdsPerContext in interface ProductService<P extends Product>
      Parameters:
      page - the requested amount of results from the database. -1 indicates no limit.
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      context - The context used to help narrowing. For example, narrowing results to a particular catalog.
      Returns:
      The narrowed list of unique product context IDs
    • readAllSkusByProductId

      public List<SKUContainer> readAllSkusByProductId(@NonNull @NonNull @NonNull String productId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ProductService
      Reads all the SKUs for the the specified product ID.
      Specified by:
      readAllSkusByProductId in interface ProductService<P extends Product>
      Parameters:
      productId - the product ID
      context - the information surrounding sandboxing and multitenant state
      Returns:
      the list of SKUContainer for the specified product ID
      See Also:
    • readAllSkusByProduct

      public List<SKUContainer> readAllSkusByProduct(@NonNull @NonNull P product, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ProductService
      Reads all the SKUs for the the specified product. This method is the same as ProductService.readAllSkusByProductId(String, ContextInfo) except it does not perform any query for Product and directly uses the POJO's id and sku for producing the result.
      Specified by:
      readAllSkusByProduct in interface ProductService<P extends Product>
      Parameters:
      product - the Product
      context - the information surrounding sandboxing and multitenant state
      Returns:
      the list of SKUContainer for the specified product ID
    • readAllSkusByProductIdAndQuery

      public List<SKUContainer> readAllSkusByProductIdAndQuery(@NonNull @NonNull @NonNull String productId, @NonNull @NonNull @NonNull String sku, @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: ProductService
      Reads all the SKUs for the the specified product ID and SKU identifier.
      Specified by:
      readAllSkusByProductIdAndQuery in interface ProductService<P extends Product>
      Parameters:
      productId - the product ID
      sku - the SKU identifier to search
      filters - the RSQL Node used to restrict result
      page - the requested page of results from the database
      context - the information surrounding sandboxing and multitenant state
      Returns:
      the list of SKUContainer for the specified Product id
    • getRepositoryDomain

      public String getRepositoryDomain()
      Specified by:
      getRepositoryDomain in interface ProductService<P extends Product>
    • readAllByUris

      public List<P> readAllByUris(@NonNull @NonNull Iterable<String> uris, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductService
      Finds the product matching the uris.
      Specified by:
      readAllByUris in interface ProductService<P extends Product>
      Parameters:
      uris - URIs to match
      contextInfo - the information surrounding sandboxing and multitenant state
      Returns:
      The product matching the uris
    • readAllByExternalIds

      public List<P> readAllByExternalIds(Collection<String> externalIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductService
      Fetches products based on the provided external IDs.
      Specified by:
      readAllByExternalIds in interface ProductService<P extends Product>
      Parameters:
      externalIds - a collection of external IDs
      contextInfo - the information surrounding sandboxing and multitenant state
      Returns:
      Products matching the provided external IDs
    • create

      public P create(@NonNull P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Performs the same behavior as BaseCrudEntityService.create(Object, ContextInfo) with the addition of Product.getPrimaryCategory() management.
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Product>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Product>
      Parameters:
      businessInstance - The business domain instance. In general, the DomainMapperManager is responsible for converting to a repository platform type for persistence.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      the created product
    • replace

      public P replace(@NonNull @NonNull String id, @NonNull P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Performs the same behavior as BaseCrudEntityService.replace(String, Object, ContextInfo) with the addition of Product.getPrimaryCategory() management.
      Specified by:
      replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Product>
      Overrides:
      replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Product>
      Parameters:
      id - The context id for the entity. This is the id by which the business recognizes the item.
      businessInstance - The payload type that domain class should be converted to. In general, the payload is what the rest API responds with.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      the replaced product
    • delete

      public void delete(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Deletes a product by ID. In addition, any CategoryProduct references are also deleted.
      Specified by:
      delete in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Product>
      Overrides:
      delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Product>
      Parameters:
      id - The context id for the entity. This is the id by which the business recognizes the item.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
    • managePrimaryCategory

      protected void managePrimaryCategory(@NonNull @NonNull String productId, @Nullable Category requestedPrimary, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Enables direct management of the primary category product relationship for a product.

      • If requestedPrimary is null or doesn't have an ID, the current primary category-product relationship will be unmarked as primary if it exists
      • If requestedPrimary is already the primary category for the product, nothing will be changed
      • If the product currently has a different primary category, it will be unmarked as primary before the new primary is set
      • If there is already a category-product relationship between the product and the requested primary, it will simply be updated to be set as primary
      • If there is not already a category-product relationship between the product and the requested primary, a new one will be created
      Parameters:
      productId - the id of the product for which the primary category needs to be managed
      requestedPrimary - the requested primary category (typically supplied by an API caller in Product.getPrimaryCategory())
      contextInfo - context information surrounding sandboxing and multitenant state
    • changeContainerIdAlreadySet

      protected boolean changeContainerIdAlreadySet(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • overrideChangeContainerId

      @Nullable protected com.broadleafcommerce.data.tracking.core.context.ContextInfo overrideChangeContainerId(String changeContainerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • copyChangeContainer

      protected com.broadleafcommerce.data.tracking.core.filtering.domain.ChangeContainer copyChangeContainer(com.broadleafcommerce.data.tracking.core.filtering.domain.ChangeContainer changeContainer)
    • unsetCurrentPrimaryCategoryProduct

      protected void unsetCurrentPrimaryCategoryProduct(@NonNull @NonNull String productId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Finds the current primary category product for the given productId and unmarks it as primary if it exists.
      Parameters:
      productId - the ID of the product whose primary category product should be unmarked
      contextInfo - context information surrounding sandboxing and multitenant state
    • getCurrentPrimaryCategoryProduct

      protected Optional<CategoryProduct> getCurrentPrimaryCategoryProduct(@NonNull @NonNull String productId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Finds the current primary category product for the given productId.
      Parameters:
      productId - the ID of the product whose primary category product should be found
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      an Optional containing the primary category product if found, else Optional.empty()
    • buildPrimaryCategoryProduct

      protected CategoryProduct buildPrimaryCategoryProduct(@NonNull @NonNull String productId, @NonNull @NonNull String categoryId)
      Builds a new CategoryProduct POJO for productId and categoryId with CategoryProduct.isPrimary() set to true.
      Parameters:
      productId - the ID of the product to set on the new category-product
      categoryId - the ID of the category to set on the new category-product
      Returns:
      a new primary CategoryProduct POJO for the given entities
    • getRepository

      protected ProductRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Product>
    • getVariantService

      protected VariantService<Variant> getVariantService()
    • getCategoryProductService

      protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • setCacheByActiveProductKeyGen

      @Autowired @Qualifier("catalogCacheByActiveProduct") public void setCacheByActiveProductKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveProductKeyGen)
      See Also:
    • getCacheByActiveProductKeyGen

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

      @Autowired @Qualifier("catalogCacheByActiveProductUri") public void setCacheByActiveProductUriKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByActiveProductUriKeyGen)
      See Also:
    • getCacheByActiveProductUriKeyGen

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

      protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> getParser()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()