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 String
CACHE_BY_CURRENCY
static String
CACHE_BY_PRICE_LIST
static String
CACHE_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.PriceListRef
convertPriceListToPriceListRef(PriceList priceList)
Create a lightweight PriceListRef from a PriceList object.protected CurrencyUtils
getCurrencyUtils()
protected PriceListFilterService
getPriceListFilterService()
protected PriceListRepository<com.broadleafcommerce.data.tracking.core.Trackable>
getRepository()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected void
modifyPriceContext(@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 providedUserTarget
s.Set<String>
readAllModifiableFieldsForType(String type)
Returns the fields that the PriceModifier components can use for calculations.ModifiableFields
readModifiableFieldsForType(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 allPriceListRefs
that apply to a givenPriceContext
.List<P>
retrievePriceListsForPriceContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)
Retrieves allPriceListRefs
that apply to a givenPriceContext
.protected void
setCurrencyForContext(@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:PriceListService
Retrieves all
PriceListRefs
that apply to a givenPriceContext
.This method will look first for any customer- or account-specific
PriceLists
since 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:
retrievePriceListRefsForPriceContext
in 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:PriceListService
Retrieves all
PriceListRefs
that apply to a givenPriceContext
.This method will look first for any customer- or account-specific
PriceLists
since 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:
retrievePriceListsForPriceContext
in interfacePriceListService<P extends PriceList>
-
convertPriceListToPriceListRef
public com.broadleafcommerce.pricing.client.domain.PriceListRef convertPriceListToPriceListRef(PriceList priceList)
Description copied from interface:PriceListService
Create a lightweight PriceListRef from a PriceList object.- Specified by:
convertPriceListToPriceListRef
in 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:PriceListService
Returns list of PriceLists for the provided priceListRefs.- Specified by:
readAllByPriceRefs
in 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:PriceListService
Reads all price lists wherePriceList.getUserTargets()
intersects with the providedUserTarget
s.- Specified by:
readAllByUserTargetsIn
in interfacePriceListService<P extends PriceList>
- Parameters:
userTargets
- users the returnedPriceList
should targetcurrencies
- the list ofCurrencyUnit
s by which to filtercontext
- Context information regarding the current API request- Returns:
- all
PriceList
s targeting the providedUserTarget
s.
-
readAllByCurrencyIn
@NonNull public List<P> readAllByCurrencyIn(@NonNull List<javax.money.CurrencyUnit> currencies, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Description copied from interface:PriceListService
Reads all price lists targeting the given currency.- Specified by:
readAllByCurrencyIn
in interfacePriceListService<P extends PriceList>
- Parameters:
currencies
- the list ofCurrencyUnit
s by which to filtercontext
- Context information regarding the current API request- Returns:
- all
PriceList
s 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:
readAllByIds
in 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:
readAllByType
in 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:
readAllByName
in 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:
readAllByTypeAndName
in interfacePriceListService<P extends PriceList>
-
readModifiableFieldsForType
public ModifiableFields readModifiableFieldsForType(String type)
- Specified by:
readModifiableFieldsForType
in interfacePriceListService<P extends PriceList>
-
readAllModifiableFieldsForType
public Set<String> readAllModifiableFieldsForType(String type)
Description copied from interface:PriceListService
Returns the fields that the PriceModifier components can use for calculations.- Specified by:
readAllModifiableFieldsForType
in 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
, thenApplication
oncontextInfo
, 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()
-
-