Class DefaultCharacteristicHydrationService
java.lang.Object
com.broadleafcommerce.catalog.service.product.hydration.DefaultCharacteristicHydrationService
- All Implemented Interfaces:
CharacteristicHydrationService
public class DefaultCharacteristicHydrationService
extends Object
implements CharacteristicHydrationService
Default implementation of the
CharacteristicHydrationService that applies characteristic
value narrowing to products based on the context information.- Since:
- Catalog Services 2.3.0, Release Train 2.3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<P extends ProductCharacteristic>
voidapplyCharacteristicValueNarrowing(Product product, List<P> allProdCharsFromInheritanceLine, P productCharacteristic, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Applies characteristic value narrowing for the given product characteristic on the given product.protected LonggetCatalogLevel(com.broadleafcommerce.data.tracking.core.ContextStateAware ctxAware) protected Optional<ProductCharacteristicValue>getMatchingValue(ProductCharacteristicValue pcValue, List<ProductCharacteristicValue> activeValues) Gets the matching product characteristic value from the list of active values.protected booleanisCurrentCatalogLevel(ProductCharacteristic currentProdChar, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the current product characteristic's catalog level is the same as the context info's catalog level meaning that it is the current version of the product characteristic.
-
Constructor Details
-
DefaultCharacteristicHydrationService
public DefaultCharacteristicHydrationService()
-
-
Method Details
-
applyCharacteristicValueNarrowing
public <P extends ProductCharacteristic> void applyCharacteristicValueNarrowing(Product product, List<P> allProdCharsFromInheritanceLine, P productCharacteristic, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CharacteristicHydrationServiceApplies characteristic value narrowing for the given product characteristic on the given product.
This method narrows characteristic values based on their active status and the catalog level from context information. Narrowing occurs to guarantee that only values active in all higher catalog levels (if there are any) are included.
- Specified by:
applyCharacteristicValueNarrowingin interfaceCharacteristicHydrationService- Parameters:
product- the product containing the characteristic that needs narrowingallProdCharsFromInheritanceLine- a list of all product characteristics for the given product context id. This input is expected to contain results from the entire catalog ancestry rather than only the 'most-derived' results. Thus, this should contain multiple catalog representations (e.g., parent vs. child catalog) of each logical characteristic. At the same time, for each catalog representation, this should only contain the 'most derived' sandbox result - this method does not account for multiple sandbox representations.productCharacteristic- the product characteristic that needs narrowing. This is the 'most derived' instance of the product characteristic loaded for the current context info. Its value will be directly mutated by this method.contextInfo- the context information containing the catalog level
-
getCatalogLevel
-
isCurrentCatalogLevel
protected boolean isCurrentCatalogLevel(ProductCharacteristic currentProdChar, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the current product characteristic's catalog level is the same as the context info's catalog level meaning that it is the current version of the product characteristic.- Parameters:
currentProdChar- The product characteristic to check.contextInfo- The context info containing the catalog level to compare against.- Returns:
- true if the current product characteristic's catalog level is the same as the context info's catalog level, false otherwise.
-
getMatchingValue
protected Optional<ProductCharacteristicValue> getMatchingValue(ProductCharacteristicValue pcValue, List<ProductCharacteristicValue> activeValues) Gets the matching product characteristic value from the list of active values.- Parameters:
pcValue- the product characteristic value to match.activeValues- the list of active product characteristic values to search.- Returns:
- an optional containing the matching product characteristic value if found, otherwise an empty optional.
-