Class DefaultProductCharacteristicService<P extends ProductCharacteristic>
- All Implemented Interfaces:
ProductCharacteristicService<P>,com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
ProductCharacteristicService.- Since:
- Catalog Service 2.3.0, Release Train 2.3.0
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultProductCharacteristicService(ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, 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 TypeMethodDescriptionlongcountNonProductionRecordsByProductIdsInTenant(@NonNull Collection<String> productIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the count of non-production records that match the givenproductContextIdsand the given tenant context.Resolves a scenario where the query for product characteristics of a product/products actually produced multiple results for the sameProductCharacteristic.getFieldName()on the same product.protected LonggetCatalogLevel(P pc) protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>protected ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable>protected com.broadleafcommerce.common.extension.TypeFactoryreadAllByProductContextIdAndCatalogContextId(@NonNull String productContextId, String catalogContextId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all product characteristics for a givenproductContextId, restricting results to only the items directly resident in the providedcatalogContextIdreadAllByProductContextIdAndInheritanceLine(Collection<String> contextIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds all product characteristics by product context id for a given catalog inheritance line.readAllByProductContextIdIn(@NonNull Collection<String> productContextIds, boolean deduplicateByFieldName, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all product characteristics for givenproductContextIds.readAllByProductContextIdIn(@NonNull Collection<String> productContextIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all product characteristics for givenproductContextIds.Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAllMethods 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, updateSortMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, updateSortMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService
readAll, readAll, readAll, readAll
-
Constructor Details
-
DefaultProductCharacteristicService
public DefaultProductCharacteristicService(ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
readAllByProductContextIdAndCatalogContextId
public List<P> readAllByProductContextIdAndCatalogContextId(@NonNull @NonNull String productContextId, @Nullable String catalogContextId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductCharacteristicServiceReads all product characteristics for a givenproductContextId, restricting results to only the items directly resident in the providedcatalogContextId- Specified by:
readAllByProductContextIdAndCatalogContextIdin interfaceProductCharacteristicService<P extends ProductCharacteristic>- Parameters:
productContextId- the product context ID to find characteristics forcatalogContextId- the catalog context ID to restrict the results tocontextInfo- Request context information around sandbox and multitenant state- Returns:
- a list of characteristics associated with the product in the specified catalog
-
readAllByProductContextIdIn
public List<P> readAllByProductContextIdIn(@NonNull @NonNull Collection<String> productContextIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductCharacteristicServiceReads all product characteristics for givenproductContextIds. This is the same asProductCharacteristicService.readAllByProductContextIdIn(Collection, boolean, ContextInfo)withdeduplicateByFieldNameset to 'true'.- Specified by:
readAllByProductContextIdInin interfaceProductCharacteristicService<P extends ProductCharacteristic>- Parameters:
productContextIds- The product context idscontextInfo- Request context information around sandbox and multitenant state- Returns:
- All product characteristics for given
productContextIds.
-
readAllByProductContextIdIn
public List<P> readAllByProductContextIdIn(@NonNull @NonNull Collection<String> productContextIds, boolean deduplicateByFieldName, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductCharacteristicServiceReads all product characteristics for given
productContextIds.The
deduplicateByFieldNameparameter, when set to true, resolves a scenario where the query for product characteristics of a product/products actually produced multiple results for the sameProductCharacteristic.getFieldName()on the same product. See the Javadocs ofProductCharacteristicService.deduplicateProductCharacteristicsByFieldName(List)for an explanation of the edge cases this is handling.- Specified by:
readAllByProductContextIdInin interfaceProductCharacteristicService<P extends ProductCharacteristic>- Parameters:
productContextIds- The product context idsdeduplicateByFieldName- whether to deduplicate results for the same product by field namecontextInfo- Request context information around sandbox and multitenant state- Returns:
- All product characteristics for given
productContextIds.
-
deduplicateProductCharacteristicsByFieldName
Description copied from interface:ProductCharacteristicServiceResolves a scenario where the query for product characteristics of a product/products actually produced multiple results for the same
ProductCharacteristic.getFieldName()on the same product.In most cases, this scenario should not arise. We're expecting the results to have gone through our standard catalog narrowing process to filter down
ProductCharacteristicsto just 1 instance perProductCharacteristic context ID. This should ensure only the most derived catalog representation is in play for eachProductCharacteristic context ID, and in most cases for everyProductCharacteristic.getFieldName()on a product, theProductCharacteristic.getId()will be unique.With that being said, consider a scenario where we started out with a product in TopTenantCatalog that didn't have any actual persisted ProductCharacteristic records and simply relied on the inherited defaults from its parent business type to be hydrated at read time. If, after that, an API caller went into ChildTenantCatalog (or application catalog) and specified a different value for any of those characteristics, that change would be interpreted as a new ProductCharacteristic creation in that catalog. It would not technically be considered an override from a DataTracking perspective, because there was no base ProductCharacteristic record in the parent catalog to override. It's a net new insert, and as a result will have a net new context ID. Then, imagine later, someone goes and modifies the value of the characteristic with the same fieldName at the top catalog level. There too, it would be seen as a new ProductCharacteristic creation and have its own new context ID. If you then come back to the child catalog context and read the persisted ProductCharacteristic records, narrowing won't help us because it only narrows by context ID. The results will end up including both the different ProductCharacteristic records for the same field name.
As a result, we must manually filter out duplicate field names and use this hook point to find the 'most derived' characteristic - usually just by finding the item with the deepest catalog level.
- Specified by:
deduplicateProductCharacteristicsByFieldNamein interfaceProductCharacteristicService<P extends ProductCharacteristic>- Parameters:
input- a list of product characteristics, potentially for multiple different products. Generally speaking this input should already only be a list of 'most derived' entities narrowed by context ID. We are only expecting to handle duplicates based onProductCharacteristic.getProductId()+ProductCharacteristic.getFieldName()- Returns:
- a new list with duplicate field name results for the same product filtered out
-
getCatalogLevel
-
readAllByProductContextIdAndInheritanceLine
public List<P> readAllByProductContextIdAndInheritanceLine(Collection<String> contextIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductCharacteristicServiceFinds all product characteristics by product context id for a given catalog inheritance line. For more details on the filtration semantics and what can be expected in the result, please see the Javadocs ofCustomizedProductCharacteristicRepository.findAllByProductContextIdAndInheritanceLine(Collection, ContextInfo), which backs this method.- Specified by:
readAllByProductContextIdAndInheritanceLinein interfaceProductCharacteristicService<P extends ProductCharacteristic>- Parameters:
contextIds- the product context ids to findcontextInfo- the information surrounding sandboxing and multitenant state, used to determine the catalog inheritance line- Returns:
- All product characteristics by product context id for a given catalog inheritance line
-
countNonProductionRecordsByProductIdsInTenant
public long countNonProductionRecordsByProductIdsInTenant(@NonNull @NonNull Collection<String> productIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:ProductCharacteristicServiceReturns the count of non-production records that match the givenproductContextIdsand the given tenant context.- Specified by:
countNonProductionRecordsByProductIdsInTenantin interfaceProductCharacteristicService<P extends ProductCharacteristic>- 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
productContextIdsand the given tenant context
-
getRepository
protected ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()- Overrides:
getRepositoryin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends ProductCharacteristic>
-
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()
-