Class DefaultAuditPruneService

java.lang.Object
com.broadleafcommerce.audit.service.DefaultAuditPruneService
All Implemented Interfaces:
org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class DefaultAuditPruneService extends Object implements org.springframework.context.SmartLifecycle
ClusterService responsible for interval polling workflows whose retention period have expired and deleting them.
  • Field Details

    • started

      protected boolean started
  • Constructor Details

    • DefaultAuditPruneService

      public DefaultAuditPruneService(AuditPruneProperties properties, AuditHeaderRepository<com.broadleafcommerce.data.tracking.core.Trackable> headerRepository, AuditDetailRepository<com.broadleafcommerce.data.tracking.core.Trackable> detailRepository, org.springframework.scheduling.TaskScheduler scheduler, org.springframework.context.ApplicationEventPublisher eventPublisher)
  • Method Details

    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • cleanup

      protected void cleanup()
      On interval, remove expired records from hot storage. See preProcess(List).
    • processPageOfResults

      protected long processPageOfResults(Function<org.springframework.data.domain.Pageable,org.springframework.data.domain.Page<HeaderIdProjection>> fetch, org.springframework.data.domain.Pageable first)
      Find and attempt to clean up JpaAuditHeader and JpaAuditDetail records where JpaAuditHeader.getExpiryDate() or AuditPruneProperties.getRetentionPeriod() is surpassed.
    • preProcess

      protected List<String> preProcess(List<String> headerPruneIds)
      Perform pre-processing on JpaAuditHeader records before deletion as a result of exceeding the retention period. Several actions may be taken:
      1. Do nothing and simply return the ids in the response collection so that the record may be cleared from hot storage.
      2. Strip ids out and don't return them in the collection so that the items are spared. In this case, you may want to update the JpaAuditHeader.setExpiryDate(Instant) to a future timestamp to avoid unwanted repeat attempts for deletion.
      3. Archive one or more of the records (headers and details) to a cold storage. Still return the ids in the response collection so that the records may be cleared from hot storage.
      Parameters:
      headerPruneIds - The primary key values of the deletion candidate JpaAuditHeader entities
      Returns:
      The possibly filtered list of ids that actually result in deletion (possibly a subset of the incoming list). The default is to return all the passed in ids.
    • isStarted

      public boolean isStarted()