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
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 Pcreate(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 PcreateItems(P requestInstance, P targetInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Creates items from a requested item list on a different item list.voiddelete(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Delete an item list by idvoiddelete(P itemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Delete an item listvoiddeleteAll(Collection<String> listIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Delete multiple item lists by idprotected PdeleteItems(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.TypeFactorygetTypeFactory()protected Phydrate(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.PreadByContextId(String id, boolean hydrate, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Reads an item list by its ID, optionally hydrating the entity.PreadByContextId(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Preplace(String id, P requestInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected PreplaceItems(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 voidsetListIds(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.ContextInfotoCreate(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.ContextInfotoDelete(com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Converts a context info to a delete operation type, if present.Pupdate(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
-
-
-
-
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:
readByContextIdin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>- Overrides:
readByContextIdin 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:ItemListServiceReads an item list by its ID, optionally hydrating the entity.- Specified by:
readByContextIdin 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:ItemListServiceReads a collection of item lists by a list of IDs, and attaches an item count per list.- Specified by:
readAllByContextIdAndAttachItemCountin 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:
createin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>- Overrides:
createin 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:
createAllin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>- Overrides:
createAllin 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:
replacein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>- Overrides:
replacein 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:
updatein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>- Overrides:
updatein 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:ItemListServiceDelete an item list- Specified by:
deletein 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:ItemListServiceDelete an item list by id- Specified by:
deletein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends com.broadleafcommerce.cart.client.domain.ItemList>- Specified by:
deletein interfaceItemListService<P extends com.broadleafcommerce.cart.client.domain.ItemList>- Overrides:
deletein 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:ItemListServiceDelete multiple item lists by id- Specified by:
deleteAllin 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
protected ItemListRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
- Overrides:
getRepositoryin 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()
-
-