Class DefaultItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.cart.service.DefaultItemListService<P>
- 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
ConstructorsConstructorDescriptionDefaultItemListService
(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
Modifier and TypeMethodDescriptioncreateAll
(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 an item list by idvoid
Delete an item listvoid
deleteAll
(Collection<String> listIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Delete multiple item lists by idprotected 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>
protected ItemListItemService<com.broadleafcommerce.cart.client.domain.ItemListItem>
protected ItemListRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected com.broadleafcommerce.common.extension.TypeFactory
protected P
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.readByContextId
(String id, boolean hydrate, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads an item list by its ID, optionally hydrating the entity.readByContextId
(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) 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.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 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
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 Details
-
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 Details
-
readByContextId
public P readByContextId(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
readByContextId
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Overrides:
readByContextId
in classcom.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 interfaceItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Parameters:
id
- the ID of the item list to retrievehydrate
- whether to hydrate the item list or notcontext
- 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 interfaceItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Parameters:
ids
- the IDs of the item lists to retrievepage
- the requested page of results from the databasefilters
- 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 interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Overrides:
create
in classcom.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 interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Overrides:
createAll
in classcom.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 interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Overrides:
replace
in classcom.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 interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Overrides:
update
in classcom.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 interfaceItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Parameters:
itemList
- list to deletecontext
- 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 interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Specified by:
delete
in interfaceItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Overrides:
delete
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Parameters:
id
- list id to deletecontext
- 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 interfaceItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>
- Parameters:
listIds
- list ids to deletecontext
- 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 oldtargetItemList
- the target item list which will have its items replacedcontext
- 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 fromcontext
- 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 hydratecontext
- 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 itemsitems
- the items to set the owning item list ID on
-
getRepository
- Overrides:
getRepository
in classcom.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()
-