Class ResourcePurgeServiceImpl
java.lang.Object
org.broadleafcommerce.core.util.service.ResourcePurgeServiceImpl
- All Implemented Interfaces:
ResourcePurgeService
@Service("blResourcePurgeService")
public class ResourcePurgeServiceImpl
extends Object
implements ResourcePurgeService
Service capable of deleting old or defunct entities from the persistence layer (e.g. Carts and anonymous Customers).
ResourcePurgeService for additional API documentation.
A basic Quartz scheduled job configuration for calling this service can be configured as follows:
<bean id="purgeCartConfig" class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="SECONDS_OLD" value="2592000"/>
<entry key="STATUS" value="IN_PROCESS"/>
</map>
</property>
</bean>
<p/>
<bean id="purgeCartJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="blResourcePurgeService" />
<property name="targetMethod" value="purgeCarts" />
<property name="arguments">
<list>
<ref bean="purgeCartConfig"/>
</list>
</property>
</bean>
<p/>
<bean id="purgeCartTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="purgeCartJobDetail" />
<property name="startDelay" value="30000" />
<property name="repeatInterval" value="86400000" />
</bean>
- Author:
- Jeff Fischer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected classclass -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Longprotected ResourcePurgeServiceImpl.PurgeErrorCacheprotected ResourcePurgeServiceImpl.PurgeErrorCacheprotected CustomerServiceprotected DeleteStatementGeneratorprotected jakarta.persistence.EntityManagerprotected org.springframework.core.env.Environmentprotected ResourcePurgeExtensionManagerprotected NotificationDispatcherprotected OrderServiceprotected static final Longprotected ResourcePurgeDaoprotected org.springframework.transaction.PlatformTransactionManager -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddeleteCart(Order cart) Remove the cart from the persistence layer.protected voiddeleteCustomer(Customer customer) Remove the cart from the persistence layer.Get the Carts Ids from cache that should be ignored due to errors in previous purge attempts.getCartsToPurge(ResourcePurgeServiceImpl.CartPurgeParams purgeParams, int startPos, int length, List<Long> cartsInError) Get the list of carts to delete from the database.protected LonggetCartsToPurgeLength(ResourcePurgeServiceImpl.CartPurgeParams purgeParams, List<Long> cartsInError) Get the count of carts to delete from the database.Get the Customer Ids from cache that should be ignored due to errors in previous purge attemptsgetCustomersToPurge(ResourcePurgeServiceImpl.CustomerPurgeParams purgeParams, int startPos, int length, List<Long> customersInError) Get the list of carts to delete from the database.protected LonggetCustomersToPurgeLength(ResourcePurgeServiceImpl.CustomerPurgeParams purgeParams, List<Long> customersInError) Get the count of customers to delete from the database.protected StringgetEmailForCart(Order cart) protected voidnotifyCart(Order cart) Notify the cart's owner of a pending purge of their cart.voidnotifyCarts(Map<String, String> config) voidpurgeCarts(Map<String, String> config) Execute a purge of carts from the persistence layer based on the configuration parameters.voidpurgeCustomers(Map<String, String> config) voidpurgeOrderHistory(Class<?> rootType, String rootTypeIdValue, Map<String, List<DeleteStatementGeneratorImpl.PathElement>> depends, Map<String, Integer> config) Generates delete statement and executes them Originally was designed to purge orders and its dependencies
-
Field Details
-
BATCH_SIZE
-
PURGE_ERROR_CACHE_RETRY_SECONDS
-
customerPurgeErrors
-
cartPurgeErrors
-
transactionManager
protected org.springframework.transaction.PlatformTransactionManager transactionManager -
resourcePurgeDao
-
orderService
-
customerService
-
notificationDispatcher
@Autowired @Qualifier("blNotificationDispatcher") protected NotificationDispatcher notificationDispatcher -
deleteStatementGenerator
-
env
@Autowired protected org.springframework.core.env.Environment env -
em
protected jakarta.persistence.EntityManager em -
extensionManager
-
-
Constructor Details
-
ResourcePurgeServiceImpl
public ResourcePurgeServiceImpl()
-
-
Method Details
-
purgeCarts
Description copied from interface:ResourcePurgeServiceExecute a purge of carts from the persistence layer based on the configuration parameters. The default implementation is capable of looking at any combination of name, status and creation date. Take a look atorg.broadleafcommerce.core.order.service.OrderService#findCarts(String[], org.broadleafcommerce.core.order.service.type.OrderStatus[], java.util.Date, Boolean, int, int)for more info on the default behavior.- Specified by:
purgeCartsin interfaceResourcePurgeService- Parameters:
config- Map of params used to drive the selection of carts to purge
-
notifyCarts
- Specified by:
notifyCartsin interfaceResourcePurgeService
-
purgeOrderHistory
public void purgeOrderHistory(Class<?> rootType, String rootTypeIdValue, Map<String, List<DeleteStatementGeneratorImpl.PathElement>> depends, Map<String, Integer> config) Description copied from interface:ResourcePurgeServiceGenerates delete statement and executes them Originally was designed to purge orders and its dependencies- Specified by:
purgeOrderHistoryin interfaceResourcePurgeService- Parameters:
rootType- - entity type to start from to find all dependent entitiesrootTypeIdValue- - id value to use, can be any string like '?' that you will want to replace with concrete id, or id itselfdepends- - a map representing dependent tables that can't be navigated from a root type, where key is a table name to depend on, value is structure representing a depending table name, join column name(FK column that is in depending table) and id field name in table to depend on.
-
purgeCustomers
- Specified by:
purgeCustomersin interfaceResourcePurgeService
-
getCartsInErrorToIgnore
Get the Carts Ids from cache that should be ignored due to errors in previous purge attempts. Expired cached errors removed.- Parameters:
purgeParams- configured parameters for the cart purge process- Returns:
- set of cart ids to ignore/exclude from the next purge run
-
getCartsToPurge
protected List<Order> getCartsToPurge(ResourcePurgeServiceImpl.CartPurgeParams purgeParams, int startPos, int length, List<Long> cartsInError) Get the list of carts to delete from the database. Subclasses may override for custom cart retrieval logic.- Parameters:
purgeParams- configured parameters for the Cart purge processcartsInError- list of cart ids to be ignored/excluded from the query- Returns:
- list of carts to delete
-
getCartsToPurgeLength
protected Long getCartsToPurgeLength(ResourcePurgeServiceImpl.CartPurgeParams purgeParams, List<Long> cartsInError) Get the count of carts to delete from the database. Subclasses may override for custom cart retrieval logic.- Parameters:
purgeParams- configured parameters for the Customer purge process used in the querycartsInError- list of cart ids to ignore/exclude from the next purge run- Returns:
- count of carts to delete
-
notifyCart
Notify the cart's owner of a pending purge of their cart.- Parameters:
cart- the cart
-
getEmailForCart
-
deleteCart
Remove the cart from the persistence layer. Subclasses may override for custom cart retrieval logic.- Parameters:
cart- the cart to remove
-
getCustomersInErrorToIgnore
protected Set<Long> getCustomersInErrorToIgnore(ResourcePurgeServiceImpl.CustomerPurgeParams purgeParams) Get the Customer Ids from cache that should be ignored due to errors in previous purge attempts- Parameters:
purgeParams- configured parameters for the Customer purge process- Returns:
- set of customer ids to ignore/exclude from the next purge run
-
getCustomersToPurge
protected List<Customer> getCustomersToPurge(ResourcePurgeServiceImpl.CustomerPurgeParams purgeParams, int startPos, int length, List<Long> customersInError) Get the list of carts to delete from the database. Subclasses may override for custom cart retrieval logic.- Parameters:
purgeParams- configured parameters for the Customer purge processcustomersInError- list of customer ids to be ignored/excluded from the query- Returns:
- list of customers to delete
-
getCustomersToPurgeLength
protected Long getCustomersToPurgeLength(ResourcePurgeServiceImpl.CustomerPurgeParams purgeParams, List<Long> customersInError) Get the count of customers to delete from the database. Subclasses may override for custom customer retrieval logic.- Parameters:
purgeParams- configured parameters for the Customer purge processcustomersInError- list of customer ids to be ignored/excluded from the query- Returns:
-
deleteCustomer
Remove the cart from the persistence layer. Subclasses may override for custom cart retrieval logic.- Parameters:
customer- the customer to remove
-