Class DefaultPriceListService<P extends PriceList>
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
-
- com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
-
- com.broadleafcommerce.pricing.service.DefaultPriceListService<P>
-
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>,PriceListService<P>
public class DefaultPriceListService<P extends PriceList> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements PriceListService<P>
- Author:
- Chad Harchar (charchar)
-
-
Field Summary
Fields Modifier and Type Field Description static StringCACHE_BY_CURRENCYstatic StringCACHE_BY_PRICE_LISTstatic StringCACHE_BY_USER
-
Constructor Summary
Constructors Constructor Description DefaultPriceListService(PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PriceListFilterService priceListFilterService, CurrencyUtils currencyUtils, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<String>convertPriceListRefToIdList(Collection<com.broadleafcommerce.pricing.client.domain.PriceListRef> priceListRefs)com.broadleafcommerce.pricing.client.domain.PriceListRefconvertPriceListToPriceListRef(PriceList priceList)Create a lightweight PriceListRef from a PriceList object.protected CurrencyUtilsgetCurrencyUtils()protected PriceListFilterServicegetPriceListFilterService()protected PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable>getRepository()protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected voidmodifyPriceContext(@NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Extend this if you want to modify the provided price context, for example removing certain attributes for security reasons.List<P>readAllByCurrencyIn(List<javax.money.CurrencyUnit> currencies, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Reads all price lists targeting the given currency.org.springframework.data.domain.Page<P>readAllByIds(Iterable<String> ids, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)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)List<P>readAllByPriceRefs(Collection<com.broadleafcommerce.pricing.client.domain.PriceListRef> priceListRefs, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Returns list of PriceLists for the provided priceListRefs.org.springframework.data.domain.Page<P>readAllByType(String type, 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>readAllByTypeAndName(String type, String name, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)List<P>readAllByUserTargetsIn(Iterable<UserTarget> userTargets, List<javax.money.CurrencyUnit> currencies, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Reads all price lists wherePriceList.getUserTargets()intersects with the providedUserTargets.Set<String>readAllModifiableFieldsForType(String type)Returns the fields that the PriceModifier components can use for calculations.ModifiableFieldsreadModifiableFieldsForType(String type)List<com.broadleafcommerce.pricing.client.domain.PriceListRef>retrievePriceListRefsForPriceContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)Retrieves allPriceListRefsthat apply to a givenPriceContext.List<P>retrievePriceListsForPriceContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)Retrieves allPriceListRefsthat apply to a givenPriceContext.protected voidsetCurrencyForContext(@NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Ensures thatPriceContext.getCurrency()is set and is valid for theContextInfo.-
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
-
-
-
-
Field Detail
-
CACHE_BY_PRICE_LIST
public static final String CACHE_BY_PRICE_LIST
- See Also:
- Constant Field Values
-
CACHE_BY_CURRENCY
public static final String CACHE_BY_CURRENCY
- See Also:
- Constant Field Values
-
CACHE_BY_USER
public static final String CACHE_BY_USER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultPriceListService
public DefaultPriceListService(PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PriceListFilterService priceListFilterService, CurrencyUtils currencyUtils, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
-
-
Method Detail
-
retrievePriceListRefsForPriceContext
@NonNull public List<com.broadleafcommerce.pricing.client.domain.PriceListRef> retrievePriceListRefsForPriceContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)
Description copied from interface:PriceListServiceRetrieves all
PriceListRefsthat apply to a givenPriceContext.This method will look first for any customer- or account-specific
PriceListssince these will trump any others (seePriceList.getUserTargets(). Then, it will filter byPriceList.getCurrency(). If none, then it will filter first on currency then onPriceList.getPriceContextCriteria(). In all cases, if applicable, it will filter and sort on priority.- Specified by:
retrievePriceListRefsForPriceContextin interfacePriceListService<P extends PriceList>
-
retrievePriceListsForPriceContext
@NonNull public List<P> retrievePriceListsForPriceContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)
Description copied from interface:PriceListServiceRetrieves all
PriceListRefsthat apply to a givenPriceContext.This method will look first for any customer- or account-specific
PriceListssince these will trump any others (seePriceList.getUserTargets(). Then, it will filter byPriceList.getCurrency(). If none, then it will filter first on currency then onPriceList.getPriceContextCriteria(). In all cases, if applicable, it will filter and sort on priority.- Specified by:
retrievePriceListsForPriceContextin interfacePriceListService<P extends PriceList>
-
convertPriceListToPriceListRef
public com.broadleafcommerce.pricing.client.domain.PriceListRef convertPriceListToPriceListRef(PriceList priceList)
Description copied from interface:PriceListServiceCreate a lightweight PriceListRef from a PriceList object.- Specified by:
convertPriceListToPriceListRefin interfacePriceListService<P extends PriceList>- Returns:
-
readAllByPriceRefs
@NonNull public List<P> readAllByPriceRefs(Collection<com.broadleafcommerce.pricing.client.domain.PriceListRef> priceListRefs, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Description copied from interface:PriceListServiceReturns list of PriceLists for the provided priceListRefs.- Specified by:
readAllByPriceRefsin interfacePriceListService<P extends PriceList>- Returns:
-
convertPriceListRefToIdList
protected List<String> convertPriceListRefToIdList(Collection<com.broadleafcommerce.pricing.client.domain.PriceListRef> priceListRefs)
-
readAllByUserTargetsIn
@NonNull public List<P> readAllByUserTargetsIn(@NonNull Iterable<UserTarget> userTargets, @NonNull List<javax.money.CurrencyUnit> currencies, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Description copied from interface:PriceListServiceReads all price lists wherePriceList.getUserTargets()intersects with the providedUserTargets.- Specified by:
readAllByUserTargetsInin interfacePriceListService<P extends PriceList>- Parameters:
userTargets- users the returnedPriceListshould targetcurrencies- the list ofCurrencyUnits by which to filtercontext- Context information regarding the current API request- Returns:
- all
PriceLists targeting the providedUserTargets.
-
readAllByCurrencyIn
@NonNull public List<P> readAllByCurrencyIn(@NonNull List<javax.money.CurrencyUnit> currencies, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Description copied from interface:PriceListServiceReads all price lists targeting the given currency.- Specified by:
readAllByCurrencyInin interfacePriceListService<P extends PriceList>- Parameters:
currencies- the list ofCurrencyUnits by which to filtercontext- Context information regarding the current API request- Returns:
- all
PriceLists targeting the provided currency
-
readAllByIds
@NonNull public org.springframework.data.domain.Page<P> readAllByIds(@NonNull Iterable<String> ids, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
- Specified by:
readAllByIdsin interfacePriceListService<P extends PriceList>
-
readAllByType
@NonNull public org.springframework.data.domain.Page<P> readAllByType(@NonNull String type, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
- Specified by:
readAllByTypein interfacePriceListService<P extends PriceList>
-
readAllByName
@NonNull public org.springframework.data.domain.Page<P> readAllByName(@NonNull String name, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
- Specified by:
readAllByNamein interfacePriceListService<P extends PriceList>
-
readAllByTypeAndName
@NonNull public org.springframework.data.domain.Page<P> readAllByTypeAndName(@NonNull String type, @NonNull String name, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
- Specified by:
readAllByTypeAndNamein interfacePriceListService<P extends PriceList>
-
readModifiableFieldsForType
public ModifiableFields readModifiableFieldsForType(String type)
- Specified by:
readModifiableFieldsForTypein interfacePriceListService<P extends PriceList>
-
readAllModifiableFieldsForType
public Set<String> readAllModifiableFieldsForType(String type)
Description copied from interface:PriceListServiceReturns the fields that the PriceModifier components can use for calculations.- Specified by:
readAllModifiableFieldsForTypein interfacePriceListService<P extends PriceList>- Returns:
-
modifyPriceContext
protected void modifyPriceContext(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Extend this if you want to modify the provided price context, for example removing certain attributes for security reasons. Left blank by default.- Parameters:
priceContext- data relevant for determining which pricing entities apply to an API requestcontextInfo- Optional sandbox and multitenant info
-
setCurrencyForContext
protected void setCurrencyForContext(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Ensures thatPriceContext.getCurrency()is set and is valid for theContextInfo. If it is not set, then this will check the currency related torequest locale, thenApplicationoncontextInfo, then finallySystemCurrencyContextHolder.Moreover, currency may be requested on
priceContext, but, if it is not valid for the current application, it will not be honored and the result ofApplication.computeDefaultCurrency()will be used instead.- Parameters:
priceContext- Data relevant for determining which pricing entities apply to an API request.contextInfo- Additional context for multitenancy and sandbox
-
getRepository
@NonNull protected PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
-
getCurrencyUtils
protected CurrencyUtils getCurrencyUtils()
-
getPriceListFilterService
protected PriceListFilterService getPriceListFilterService()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
-