Class DefaultItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>

  • All Implemented Interfaces:
    ItemListService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

    public class DefaultItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
    extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
    implements ItemListService<P>
    The default implementation of an item list service.
    Author:
    Jacob Mitash
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultItemListService​(ItemListRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, ItemListItemService<com.broadleafcommerce.cart.client.domain.ItemListItem> itemService, ItemListAccessRuleService<com.broadleafcommerce.cart.client.domain.ItemListAccessRule> accessRuleService, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      P create​(P requestInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      List<P> createAll​(List<P> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      protected P createItems​(P requestInstance, P targetInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Creates items from a requested item list on a different item list.
      void delete​(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Delete an item list by id
      void delete​(P itemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Delete an item list
      void deleteAll​(Collection<String> listIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Delete multiple item lists by id
      protected P deleteItems​(P targetItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Deletes any items belonging to the target list.
      protected ItemListAccessRuleService<com.broadleafcommerce.cart.client.domain.ItemListAccessRule> getAccessRuleService()  
      protected ItemListItemService<com.broadleafcommerce.cart.client.domain.ItemListItem> getItemService()  
      protected ItemListRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()  
      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()  
      protected P hydrate​(P itemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Hydrates the given list, loading its items and populating them on the instance.
      org.springframework.data.domain.Page<P> readAllByContextIdAndAttachItemCount​(@NonNull Iterable<String> ids, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Reads a collection of item lists by a list of IDs, and attaches an item count per list.
      P readByContextId​(String id, boolean hydrate, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Reads an item list by its ID, optionally hydrating the entity.
      P readByContextId​(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      P replace​(String id, P requestInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      protected P replaceItems​(P newItemList, P targetItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Replaces items of the target list with items from a new item list.
      protected void setListIds​(String id, Collection<com.broadleafcommerce.cart.client.domain.ItemListItem> items)
      Sets the owning item list ID for each item.
      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo toCreate​(com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Converts a context info to a create operation type, if present.
      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo toDelete​(com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Converts a context info to a delete operation type, if present.
      P update​(String id, P requestInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)  
      • 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, createAllAllowingPartialSuccess, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, updateAll, updateAllAllowingPartialSuccess, updateSort
      • Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

        createAllAllowingPartialSuccess, readAll, readAll, readAll, readAllByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateAllAllowingPartialSuccess, updateSort
      • Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

        readAll, readAll, readAll, readAll
    • Constructor Detail

      • DefaultItemListService

        public DefaultItemListService​(ItemListRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository,
                                      ItemListItemService<com.broadleafcommerce.cart.client.domain.ItemListItem> itemService,
                                      ItemListAccessRuleService<com.broadleafcommerce.cart.client.domain.ItemListAccessRule> accessRuleService,
                                      com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper,
                                      com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • Method Detail

      • readByContextId

        public P readByContextId​(String id,
                                 @Nullable
                                 com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        readByContextId in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Overrides:
        readByContextId in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
      • readByContextId

        public P readByContextId​(String id,
                                 boolean hydrate,
                                 @Nullable
                                 com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: ItemListService
        Reads an item list by its ID, optionally hydrating the entity.
        Specified by:
        readByContextId in interface ItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Parameters:
        id - the ID of the item list to retrieve
        hydrate - whether to hydrate the item list or not
        context - the context of the request
        Returns:
        the item list with the given ID
      • readAllByContextIdAndAttachItemCount

        public org.springframework.data.domain.Page<P> readAllByContextIdAndAttachItemCount​(@NonNull
                                                                                            @NonNull Iterable<String> ids,
                                                                                            @Nullable
                                                                                            org.springframework.data.domain.Pageable page,
                                                                                            @Nullable
                                                                                            cz.jirutka.rsql.parser.ast.Node filters,
                                                                                            @Nullable
                                                                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: ItemListService
        Reads a collection of item lists by a list of IDs, and attaches an item count per list.
        Specified by:
        readAllByContextIdAndAttachItemCount in interface ItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Parameters:
        ids - the IDs of the item lists to retrieve
        page - the requested page of results from the database
        filters - additional filters to apply in the query.
        context - the context of the request
        Returns:
        items lists each with its item count as an attribute
      • create

        public P create​(P requestInstance,
                        @Nullable
                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Overrides:
        create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
      • createAll

        public List<P> createAll​(List<P> businessInstances,
                                 @Nullable
                                 com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        createAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Overrides:
        createAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
      • replace

        public P replace​(String id,
                         @NonNull
                         P requestInstance,
                         @Nullable
                         com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Overrides:
        replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
      • update

        public P update​(String id,
                        @NonNull
                        P requestInstance,
                        @Nullable
                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Overrides:
        update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
      • delete

        @Transactional("cartTransactionManager")
        public void delete​(P itemList,
                           @Nullable
                           com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: ItemListService
        Delete an item list
        Specified by:
        delete in interface ItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Parameters:
        itemList - list to delete
        context - the context of the request
      • delete

        @Transactional("cartTransactionManager")
        public void delete​(String id,
                           @Nullable
                           com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: ItemListService
        Delete an item list by id
        Specified by:
        delete in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Specified by:
        delete in interface ItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Overrides:
        delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Parameters:
        id - list id to delete
        context - the context of the request
      • deleteAll

        @Transactional("cartTransactionManager")
        public void deleteAll​(Collection<String> listIds,
                              @Nullable
                              com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: ItemListService
        Delete multiple item lists by id
        Specified by:
        deleteAll in interface ItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
        Parameters:
        listIds - list ids to delete
        context - the context of the request
      • createItems

        protected P createItems​(P requestInstance,
                                P targetInstance,
                                @Nullable
                                com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Creates items from a requested item list on a different item list. Does nothing when there are no items to create. If items were created, the target instance is hydrated.
        Parameters:
        requestInstance - the requested instance that contains the items to create (the request body)
        targetInstance - the target instance that the items will be added to (the newly saved instance)
        context - the request context information
        Returns:
        the target instance, hydrated if any items were created
      • replaceItems

        protected P replaceItems​(P newItemList,
                                 P targetItemList,
                                 @Nullable
                                 com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Replaces items of the target list with items from a new item list. Does nothing if the new item list has null for its items.
        Parameters:
        newItemList - the new item list containing the items that will replace the old
        targetItemList - the target item list which will have its items replaced
        context - the request context information
        Returns:
        the target item list, hydrated if any items were replaced
      • deleteItems

        protected P deleteItems​(P targetItemList,
                                @Nullable
                                com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Deletes any items belonging to the target list.
        Parameters:
        targetItemList - the list to delete items from
        context - the request context information
        Returns:
        the target item list with its items deleted
      • hydrate

        protected P hydrate​(P itemList,
                            @Nullable
                            com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Hydrates the given list, loading its items and populating them on the instance.
        Parameters:
        itemList - the item list to hydrate
        context - the request context information
        Returns:
        the same instance passed in, now with its items populated
      • toDelete

        @Nullable
        protected com.broadleafcommerce.data.tracking.core.context.ContextInfo toDelete​(@Nullable
                                                                                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Converts a context info to a delete operation type, if present.
        Parameters:
        context - the request context information
        Returns:
        the request context information as a delete operation, or null if null was provided
      • toCreate

        @Nullable
        protected com.broadleafcommerce.data.tracking.core.context.ContextInfo toCreate​(@Nullable
                                                                                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Converts a context info to a create operation type, if present.
        Parameters:
        context - the request context information
        Returns:
        the request context information as a create operation, or null if null was provided
      • setListIds

        protected void setListIds​(String id,
                                  Collection<com.broadleafcommerce.cart.client.domain.ItemListItem> items)
        Sets the owning item list ID for each item.
        Parameters:
        id - the owning item list ID to set for the items
        items - the items to set the owning item list ID on
      • getRepository

        protected ItemListRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
        Overrides:
        getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
      • getItemService

        protected ItemListItemService<com.broadleafcommerce.cart.client.domain.ItemListItem> getItemService()
      • getAccessRuleService

        protected ItemListAccessRuleService<com.broadleafcommerce.cart.client.domain.ItemListAccessRule> getAccessRuleService()
      • getTypeFactory

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