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
-
Constructor Summary
ConstructorDescriptionDefaultCategoryProductService
(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 TypeMethodDescriptionprotected P
choosePrimary
(P primaryCategoryProduct1, P primaryCategoryProduct2) A simpleBinaryOperator
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 givenproductContextIds
and the given tenant context.protected CategoryRef
createCategoryRefFromCategory
(Category category) 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 ProductService<Product>
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) 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 allCategoryProducts
for the givenCategory.id
,Product.id
, andCategoryProduct.sorted
values.readAllByCategoryIdIn
(@NonNull Collection<String> categoryIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads a list ofCategoryProducts
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 givenproductIds
.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 ofCategoryProducts
by ID.readByIdAndCategoryId
(String id, String categoryId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theCategoryProduct
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 ofCategoryProducts
for the givenCategory
and additional inputs.readPrimaryByProductIdIn
(@NonNull Collection<String> productIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads allCategoryProducts
whose product ID is in one of the given values and whoseCategoryProduct.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
setProductService
(ProductService<Product> productService) 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
-
CACHE_BY_CATEGORY_PRODUCT
- See Also:
-
CACHE_BY_CATEGORY_PRODUCT_CATEGORY
- See Also:
-
-
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 interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
productId
- the product context IDcategoryId
- the category context IDcontextInfo
- 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 interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
categoryContextId
- the category context ID to find the relationships forfilters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.page
- the requested page of results from the databasecontextInfo
- 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 interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
categoryContextId
- the category context ID to find the relationships forproductIds
- the list ofProduct.id
s to retrievefilters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.page
- the requested page of results from the databasecontextInfo
- 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 interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
productContextId
- the product context ID to find the relationships forfilters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.page
- the requested page of results from the databasecontextInfo
- 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 givenproductIds
.- Specified by:
readAllByProductIdIn
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
productIds
- a collection of product IDs which the results must be associated withcontext
- 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
- Specified by:
readAllByCategoryIdAndIsSorted
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
categoryId
- parentCategory.id
isSorted
- Whether to returnCategoryProducts
whereCategoryProduct.sorted
is true, else false.filters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.page
- the requested page of results from the databasecontextInfo
- the context to query within- Returns:
- the
CategoryProducts
with the givencategoryId
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 allCategoryProducts
for the givenCategory.id
,Product.id
, andCategoryProduct.sorted
values.- Specified by:
readAllByCategoryIdAndProductIdsAndIsSorted
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
categoryId
- parentCategory.id
productIds
- the list ofProduct.id
s to retrieveisSorted
- Whether to returnCategoryProducts
whereCategoryProduct.sorted
is true, else false.filters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.page
- the requested page of results from the databasecontextInfo
- the context to query within- Returns:
- the
CategoryProducts
with the givencategoryId
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 interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
productId
- the product context IDcategoryId
- the category context IDcontextInfo
- 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 theCategoryProduct
which has the given ID and parent category ID.- Specified by:
readByIdAndCategoryId
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
id
- the context ID of theCategoryProduct
categoryId
- the context ID of the parentCategory
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 ofCategoryProducts
by ID.- Specified by:
readByCategoryIdIn
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
categoryIds
-Category
IDs to match againstpage
- Pagination infocontextInfo
- 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 ofCategoryProducts
by ID.- Specified by:
readAllByCategoryIdIn
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
categoryIds
-Category
IDs to match againstcontextInfo
- 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 allCategoryProducts
whose product ID is in one of the given values and whoseCategoryProduct.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 interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
productIds
- the ids of the products for which to find primary category-product relationshipscontextInfo
- 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 ofCategoryProducts
for the givenCategory
and additional inputs.- Specified by:
readPageForCategory
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
category
- The parent categorypage
- Pagination infofilters
- RSQL filtersisSorted
- Whether to read onlyCategoryProducts
that have a sort value.contextInfo
- Additional multitenant and sandbox info- Returns:
- Page of
CategoryProducts
for the givenCategory
.
-
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 givenproductContextIds
and the given tenant context.- Specified by:
countNonProductionRecordsByProductIdsInTenant
in interfaceCategoryProductService<P extends CategoryProduct>
- Parameters:
productIds
- IDs of parent Products to match againstcontext
- 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 messagedefaultMessage
- Default message to display if message not found by namelocale
- The locale for the messageargs
- Any arguments to supply.- Returns:
- The message.
-
choosePrimary
A simpleBinaryOperator
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 productprimaryCategoryProduct2
- a category product that was a primary for the same product- Returns:
- one of the two category products
-
createCategoryRefFromCategory
-
getRepository
@NonNull protected CategoryProductRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()- Overrides:
getRepository
in classcom.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
-
setProductService
-
getMessageSource
@Nullable protected org.springframework.context.MessageSource getMessageSource() -
setMessageSource
@Autowired(required=false) public void setMessageSource(org.springframework.context.MessageSource messageSource)
-