Class DefaultPriceListService<P extends PriceList>

  • 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)
    • 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 where PriceList.getUserTargets() intersects with the provided UserTargets.
      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 all PriceListRefs that apply to a given PriceContext.
      List<P> retrievePriceListsForPriceContext​(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)
      Retrieves all PriceListRefs that apply to a given PriceContext.
      protected void setCurrencyForContext​(@NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Ensures that PriceContext.getCurrency() is set and is valid for the ContextInfo.
      • 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 interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

        create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
      • Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

        readAll, readAll, readAll, readAll
    • 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 given PriceContext.

        This method will look first for any customer- or account-specific PriceLists since these will trump any others (see PriceList.getUserTargets(). Then, it will filter by PriceList.getCurrency(). If none, then it will filter first on currency then on PriceList.getPriceContextCriteria(). In all cases, if applicable, it will filter and sort on priority.

        Specified by:
        retrievePriceListRefsForPriceContext in interface PriceListService<P extends PriceList>
      • 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 interface PriceListService<P extends PriceList>
        Returns:
      • convertPriceListRefToIdList

        protected List<String> convertPriceListRefToIdList​(Collection<com.broadleafcommerce.pricing.client.domain.PriceListRef> priceListRefs)
      • 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 interface PriceListService<P extends PriceList>
        Parameters:
        currencies - the list of CurrencyUnits by which to filter
        context - 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:
        readAllByIds in interface PriceListService<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 interface PriceListService<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 interface PriceListService<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 interface PriceListService<P extends PriceList>
      • 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 request
        contextInfo - 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 that PriceContext.getCurrency() is set and is valid for the ContextInfo. If it is not set, then this will check the currency related to request locale, then Application on contextInfo, then finally SystemCurrencyContextHolder.

        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 of Application.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()
        Overrides:
        getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends PriceList>
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()