Class DefaultPriceDataService<P extends PriceData>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.pricing.service.DefaultPriceDataService<P>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>,PriceDataService<P>,EventListener,org.springframework.context.ApplicationListener<PricingCacheInvalidationEvent>
public class DefaultPriceDataService<P extends PriceData>
extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
implements PriceDataService<P>, org.springframework.context.ApplicationListener<PricingCacheInvalidationEvent>
- Author:
- Chad Harchar (charchar)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringA key intoContextInfo.getAdditionalProperties()that is used in some flows to hold a map fromPriceList.getId()to theCurrencyUnitof itsPriceList.getCurrency().static final StringA key intoContextInfo.getAdditionalProperties()that is used in some flows to holdCurrency.getCurrencyCode()of a singlePriceList.getCurrency()that is in play. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultPriceDataService(PriceDataRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable> priceListRepository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory pricingFactory, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager) -
Method Summary
Modifier and TypeMethodDescriptionconvertFromDomain(List<com.broadleafcommerce.data.tracking.core.Trackable> trackables, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected org.springframework.data.domain.Page<P>convertFromDomain(org.springframework.data.domain.Page<com.broadleafcommerce.data.tracking.core.Trackable> trackables, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) com.broadleafcommerce.pricing.client.domain.PriceableTargetRefconvertTargetToRef(com.broadleafcommerce.pricing.client.domain.PriceableTarget target) create(PriceList priceList, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P>createAllAllowingPartialSuccess(List<P> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) intdecrementAvailableQuantity(String priceDataId, String priceListId, Instant usageDate, int quantityToDecrement, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Decrements thePriceData.getAvailableQuantity().voiddelete(PriceList priceList, String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected javax.money.CurrencyUnitdetermineCorrectCurrencyToSetOnPriceData(com.broadleafcommerce.data.tracking.core.context.ContextInfo context, P priceData) findByPriceableTargetRefAndPriceListId(com.broadleafcommerce.pricing.client.domain.PriceableTargetRef target, String priceListId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds thePriceDatathat has the givenPriceData.targetandorg.springframework.data.domain.Page<P>findByPriceList(String priceListId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) org.springframework.data.domain.Page<P>findByPriceListAndTarget(String priceListId, String targetType, Collection<String> targetIds, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) findByTargetKeyInAndPriceListIn(Collection<TargetKeyDto> targets, Collection<String> priceListIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) findByTargetRefInAndPriceListIn(Collection<com.broadleafcommerce.pricing.client.domain.PriceableTargetRef> targets, Collection<String> priceListIds, boolean filterByVendor, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Uses the repository to find a list of price data by the givenPriceableTargetRefsand price list ids.protected PfixCurrency(com.broadleafcommerce.data.tracking.core.context.ContextInfo context, P priceData) protected com.broadleafcommerce.common.extension.cache.CacheStateManagerprotected PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable>protected com.broadleafcommerce.common.extension.TypeFactoryprotected PriceDataRepository<com.broadleafcommerce.data.tracking.core.Trackable>intincrementAvailableQuantity(String priceDataId, int quantityToIncrement, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Increments thePriceData.getAvailableQuantity(), typically used as part of the rollback.protected voidinitializeCurrency(com.broadleafcommerce.data.tracking.core.context.ContextInfo context, String priceListId) voidprotected voidpopulatePriceListCurrencyMap(com.broadleafcommerce.data.tracking.core.context.ContextInfo context, List<com.broadleafcommerce.data.tracking.core.Trackable> priceData) protected voidpopulatePriceListCurrencyMap(com.broadleafcommerce.data.tracking.core.context.ContextInfo context, org.springframework.data.domain.Page<com.broadleafcommerce.data.tracking.core.Trackable> priceData) readAllByPriceListId(String priceListId, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) readByContextId(PriceList priceList, String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) readByContextId(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) replace(PriceList priceList, String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) replace(String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidsetDefaultValuesForCreate(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Sets the appropriate default values for a create operation.protected voidsetDefaultValuesForUpdate(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Sets the appropriate default values for an update/replace operation.protected voidsetupPlaceholderCurrency(com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Useful when reading priceData as we don't yet know the correct currency which is needed by the model mapper when reading by id.protected org.springframework.data.domain.PageabletransformSort(org.springframework.data.domain.Pageable pageable) update(PriceList priceList, String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) update(String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<P>updateAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<P>> updates, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) 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, createAll, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, updateAll, updateSortMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecutionMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
createAll, delete, readAll, readAll, readAll, readAllByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateSortMethods inherited from interface com.broadleafcommerce.pricing.service.PriceDataService
findByTargetRefInAndPriceListInMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService
readAll, readAll, readAll, readAll
-
Field Details
-
CACHE_BY_TARGET_DTOS_AND_PRICE_LIST
- See Also:
-
PRICE_LIST_CURRENCY
A key intoContextInfo.getAdditionalProperties()that is used in some flows to holdCurrency.getCurrencyCode()of a singlePriceList.getCurrency()that is in play.- See Also:
-
CURRENCY_BY_PRICE_LIST_ID_MAP
A key intoContextInfo.getAdditionalProperties()that is used in some flows to hold a map fromPriceList.getId()to theCurrencyUnitof itsPriceList.getCurrency().- See Also:
-
-
Constructor Details
-
DefaultPriceDataService
public DefaultPriceDataService(PriceDataRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable> priceListRepository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory pricingFactory, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager)
-
-
Method Details
-
onApplicationEvent
-
findByPriceList
@NonNull public org.springframework.data.domain.Page<P> findByPriceList(@NonNull String priceListId, @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:
findByPriceListin interfacePriceDataService<P extends PriceData>
-
transformSort
protected org.springframework.data.domain.Pageable transformSort(org.springframework.data.domain.Pageable pageable) -
findByPriceListAndTarget
@NonNull public org.springframework.data.domain.Page<P> findByPriceListAndTarget(@Nullable String priceListId, @Nullable String targetType, @Nullable Collection<String> targetIds, @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:
findByPriceListAndTargetin interfacePriceDataService<P extends PriceData>
-
readAllByPriceListId
public Stream<P> readAllByPriceListId(String priceListId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
readAllByPriceListIdin interfacePriceDataService<P extends PriceData>
-
findByPriceableTargetRefAndPriceListId
@NonNull public Optional<P> findByPriceableTargetRefAndPriceListId(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTargetRef target, @NonNull String priceListId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PriceDataServiceFinds thePriceDatathat has the givenPriceData.targetand- Specified by:
findByPriceableTargetRefAndPriceListIdin interfacePriceDataService<P extends PriceData>- Returns:
-
findByTargetRefInAndPriceListIn
@NonNull public List<P> findByTargetRefInAndPriceListIn(@NonNull Collection<com.broadleafcommerce.pricing.client.domain.PriceableTargetRef> targets, @NonNull Collection<String> priceListIds, boolean filterByVendor, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PriceDataServiceUses the repository to find a list of price data by the givenPriceableTargetRefsand price list ids.- Specified by:
findByTargetRefInAndPriceListInin interfacePriceDataService<P extends PriceData>- Parameters:
targets- a list ofPriceableTargetRefsto matchpriceListIds- a list of price list ids to look forfilterByVendor- whether to also filter the price data based on the {@link {@link PriceableTargetRef#getVendorRef()}. When this isfalse, vendor-discriminated targets will also get non-vendor price data.- Returns:
- a list of price data by the given
PriceableTargetRefsand price list ids from the repository
-
findByTargetKeyInAndPriceListIn
@NonNull public List<P> findByTargetKeyInAndPriceListIn(@NonNull Collection<TargetKeyDto> targets, @NonNull Collection<String> priceListIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
findByTargetKeyInAndPriceListInin interfacePriceDataService<P extends PriceData>
-
readByContextId
@NonNull public P readByContextId(@NonNull PriceList priceList, @NonNull String id, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
readByContextIdin interfacePriceDataService<P extends PriceData>
-
update
@NonNull public P update(@NonNull PriceList priceList, @NonNull String id, @NonNull P businessInstance, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
updatein interfacePriceDataService<P extends PriceData>
-
delete
public void delete(@NonNull PriceList priceList, @NonNull String id, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
deletein interfacePriceDataService<P extends PriceData>
-
replace
@NonNull public P replace(@NonNull PriceList priceList, @NonNull String id, @NonNull P businessInstance, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
replacein interfacePriceDataService<P extends PriceData>
-
create
@NonNull public P create(@NonNull PriceList priceList, @NonNull P businessInstance, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
createin interfacePriceDataService<P extends PriceData>
-
createAllAllowingPartialSuccess
-
updateAllAllowingPartialSuccess
-
incrementAvailableQuantity
public int incrementAvailableQuantity(String priceDataId, int quantityToIncrement, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PriceDataServiceIncrements thePriceData.getAvailableQuantity(), typically used as part of the rollback.This method updates the quantity based on the current
PriceData.getAvailableQuantity()to prevent causing stale data (e.g., read entity and then update the entity separately could cause the data to be stale).This method should be used to increment the
PriceData.getAvailableQuantity()to prevent race condition and cause the quantity to be stale.- Specified by:
incrementAvailableQuantityin interfacePriceDataService<P extends PriceData>- Parameters:
priceDataId- thePriceData.getId()to incrementquantityToIncrement- the quantity to incrementcontextInfo- the context info- Returns:
- the count of records updated
-
decrementAvailableQuantity
public int decrementAvailableQuantity(@NonNull String priceDataId, @NonNull String priceListId, @NonNull Instant usageDate, int quantityToDecrement, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PriceDataServiceDecrements thePriceData.getAvailableQuantity().This method only updates the quantity if the
PriceData.getAvailableQuantity()is enough to cover thequantityToDecrement.This method should be used to decrement the
PriceData.getAvailableQuantity()to prevent race condition and decrement more quantity than actually available.- Specified by:
decrementAvailableQuantityin interfacePriceDataService<P extends PriceData>- Parameters:
priceDataId- thePriceData.getId()to decrementpriceListId- thePriceList.getId()that it belongs tousageDate- theInstantused to check against the active start and end datesquantityToDecrement- the quantity to decrementcontextInfo- the context info- Returns:
- the count of records updated
-
convertTargetToRef
@Nullable public com.broadleafcommerce.pricing.client.domain.PriceableTargetRef convertTargetToRef(@Nullable com.broadleafcommerce.pricing.client.domain.PriceableTarget target) - Specified by:
convertTargetToRefin interfacePriceDataService<P extends PriceData>
-
convertFromDomain
-
convertFromDomain
protected org.springframework.data.domain.Page<P> convertFromDomain(org.springframework.data.domain.Page<com.broadleafcommerce.data.tracking.core.Trackable> trackables, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
readByContextId
-
update
-
replace
-
create
-
setupPlaceholderCurrency
protected void setupPlaceholderCurrency(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Useful when reading priceData as we don't yet know the correct currency which is needed by the model mapper when reading by id. The "fixCurrency" method will be called to adjust the PriceData before returning to the caller. Sets the Context to the default currency. -
setDefaultValuesForCreate
protected void setDefaultValuesForCreate(@NonNull P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Sets the appropriate default values for a create operation.- Parameters:
businessInstance- thePriceDatabeing createdcontext- theContextInfofor the operation
-
setDefaultValuesForUpdate
protected void setDefaultValuesForUpdate(@NonNull P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Sets the appropriate default values for an update/replace operation.- Parameters:
businessInstance- thePriceDatabeing updatedcontext- theContextInfofor the operation
-
fixCurrency
-
determineCorrectCurrencyToSetOnPriceData
protected javax.money.CurrencyUnit determineCorrectCurrencyToSetOnPriceData(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context, P priceData) -
populatePriceListCurrencyMap
protected void populatePriceListCurrencyMap(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context, org.springframework.data.domain.Page<com.broadleafcommerce.data.tracking.core.Trackable> priceData) -
populatePriceListCurrencyMap
protected void populatePriceListCurrencyMap(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context, List<com.broadleafcommerce.data.tracking.core.Trackable> priceData) -
initializeCurrency
protected void initializeCurrency(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context, String priceListId) -
getRepository
@NonNull protected PriceDataRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository() -
getPriceListRepository
@NonNull protected PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable> getPriceListRepository() -
getPricingFactory
@NonNull protected com.broadleafcommerce.common.extension.TypeFactory getPricingFactory() -
getCacheStateManager
@Nullable protected com.broadleafcommerce.common.extension.cache.CacheStateManager getCacheStateManager()
-